检验voucher异常

#检查voucher transfer之前voucher有无异常
SELECT *
FROM voucher a
LEFT JOIN voucher_action b ON(a.voucher_id = b.voucher_id)
LEFT JOIN voucher_campaign_issue c ON(a.voucher_id = c.voucher_id)
LEFT JOIN voucher_submission_error d ON(a.voucher_id = d.voucher_id)
WHERE a.status_id < 5
AND (
     a.issue_time IS NOT NULL
     OR a.expiry_time IS NOT NULL
     OR a.submission_id IS NOT NULL
     OR a.transfer_time IS NOT NULL
     OR a.transfer_channel IS NOT NULL
     OR b.id is not null
     OR c.id is not null
     OR d.error_id is not null
)

#检查voucher transfer之后voucher有无异常
SELECT *
FROM voucher a
LEFT JOIN voucher_action b ON(a.voucher_id = b.voucher_id)
LEFT JOIN voucher_campaign_issue c ON(a.voucher_id = c.voucher_id)
LEFT JOIN voucher_submission_error d ON(a.voucher_id = d.voucher_id)
WHERE a.status_id = 5
AND (
     a.issue_time IS NOT NULL
     OR a.expiry_time IS NOT NULL
     OR a.submission_id IS NOT NULL
     OR a.transfer_time IS NULL
     #OR a.transfer_channel IS NULL
     OR b.id is not null
     OR c.id is not null
     OR d.error_id is not null
)

#检查voucher issue之前是否有异常
SELECT a.voucher_id, CONCAT(a.prefix, a.voucher_no) AS voucher, b.id, c.campaign_id, d.error_id
FROM voucher a
LEFT JOIN voucher_action b ON (a.voucher_id = b.voucher_id)
LEFT JOIN voucher_campaign_issue c ON(a.voucher_id = c.voucher_id)
LEFT JOIN voucher_submission_error d ON(a.voucher_id = d.voucher_id)
WHERE a.status_id < 6 AND (b.id IS NOT NULL OR c.id IS NOT NULL OR d.error_id IS NOT NULL)

#检查voucher issue之后是否有异常
SELECT a.voucher_id, CONCAT(a.prefix, a.voucher_no) AS voucher, b.id, c.campaign_id, d.error_id
FROM voucher a
LEFT JOIN voucher_action b ON (a.voucher_id = b.voucher_id AND b.action_id = 6)
LEFT JOIN voucher_campaign_issue c ON(a.voucher_id = c.voucher_id)
LEFT JOIN voucher_submission_error d ON(a.voucher_id = d.voucher_id)
WHERE a.status_id = 6 AND (b.id IS NULL OR a.transfer_time IS NULL OR a.issue_time IS NULL OR a.expiry_time IS NULL OR a.transfer_channel IS NULL)


#检查tenant submit之后时候有异常
SELECT a.voucher_id, CONCAT(a.prefix, a.voucher_no) AS voucher, b.id, c.campaign_id, e.submission_id
FROM voucher a
LEFT JOIN voucher_action b ON (a.voucher_id = b.voucher_id and b.action_id = 8)
LEFT JOIN voucher_campaign_issue c ON(a.voucher_id = c.voucher_id)
LEFT JOIN voucher_store_submission e ON(a.submission_id = e.submission_id)
WHERE a.status_id = 7 AND (b.id IS NULL OR c.id IS NULL OR e.submission_id is NULL)


#检查reimburse之后voucher是否有异常
SELECT *
FROM voucher
WHERE status_id = 9
AND (
     transfer_time IS NULL
     OR issue_time IS null
     OR submission_time IS NULL
     OR expiry_time IS NULL
     OR transfer_channel IS NULL
     OR submission_id IS NULL
     OR reimburse_time IS NULL
     )