新增撞车订单人工退款
This commit is contained in:
@@ -63,20 +63,20 @@ func (r *Repository) summary(ctx context.Context, query DashboardQuery) (*Financ
|
||||
db := r.db.WithContext(ctx)
|
||||
var payment paymentSummaryRow
|
||||
if err := db.Table("payment_orders AS po").
|
||||
Select(`COALESCE(SUM(CASE WHEN po.biz_type IN ('order_pay') AND po.status = 'paid' THEN po.amount_cent ELSE 0 END), 0) AS total_flow_amount_cent,
|
||||
Select(`COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'paid' THEN po.amount_cent ELSE 0 END), 0) AS total_flow_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' THEN po.amount_cent ELSE 0 END), 0) AS total_refund_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunding' THEN po.amount_cent ELSE 0 END), 0) AS pending_refund_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ('order_pay') AND po.status = 'paid' THEN 1 ELSE 0 END), 0) AS successful_pay_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'paid' THEN 1 ELSE 0 END), 0) AS successful_pay_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' AND po.amount_cent >= COALESCE(orig.amount_cent, 0) THEN 1 ELSE 0 END), 0) AS full_refund_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' AND po.amount_cent < COALESCE(orig.amount_cent, 0) THEN 1 ELSE 0 END), 0) AS partial_refund_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunding' THEN 1 ELSE 0 END), 0) AS pending_refund_count`,
|
||||
refundBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes()).
|
||||
payBizTypes(), refundBizTypes(), refundBizTypes(), payBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes()).
|
||||
Joins(`LEFT JOIN (
|
||||
SELECT order_id, MAX(amount_cent) AS amount_cent
|
||||
FROM payment_orders
|
||||
WHERE biz_type = 'order_pay' AND status = 'paid'
|
||||
WHERE biz_type IN ? AND status = 'paid'
|
||||
GROUP BY order_id
|
||||
) AS orig ON orig.order_id = po.order_id`).
|
||||
) AS orig ON orig.order_id = po.order_id`, payBizTypes()).
|
||||
Where("po.created_at >= ? AND po.created_at <= ?", query.StartDate, query.EndDate).
|
||||
Scan(&payment).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -168,20 +168,20 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) ([]Fi
|
||||
payments := make([]dailyPaymentRow, 0)
|
||||
if err := db.Table("payment_orders AS po").
|
||||
Select(`DATE(po.created_at) AS date,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ('order_pay') AND po.status = 'paid' THEN po.amount_cent ELSE 0 END), 0) AS total_flow_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'paid' THEN po.amount_cent ELSE 0 END), 0) AS total_flow_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' THEN po.amount_cent ELSE 0 END), 0) AS total_refund_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunding' THEN po.amount_cent ELSE 0 END), 0) AS pending_refund_amount_cent,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ('order_pay') AND po.status = 'paid' THEN 1 ELSE 0 END), 0) AS successful_pay_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'paid' THEN 1 ELSE 0 END), 0) AS successful_pay_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' AND po.amount_cent >= COALESCE(orig.amount_cent, 0) THEN 1 ELSE 0 END), 0) AS full_refund_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunded' AND po.amount_cent < COALESCE(orig.amount_cent, 0) THEN 1 ELSE 0 END), 0) AS partial_refund_count,
|
||||
COALESCE(SUM(CASE WHEN po.biz_type IN ? AND po.status = 'refunding' THEN 1 ELSE 0 END), 0) AS pending_refund_count`,
|
||||
refundBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes()).
|
||||
payBizTypes(), refundBizTypes(), refundBizTypes(), payBizTypes(), refundBizTypes(), refundBizTypes(), refundBizTypes()).
|
||||
Joins(`LEFT JOIN (
|
||||
SELECT order_id, MAX(amount_cent) AS amount_cent
|
||||
FROM payment_orders
|
||||
WHERE biz_type = 'order_pay' AND status = 'paid'
|
||||
WHERE biz_type IN ? AND status = 'paid'
|
||||
GROUP BY order_id
|
||||
) AS orig ON orig.order_id = po.order_id`).
|
||||
) AS orig ON orig.order_id = po.order_id`, payBizTypes()).
|
||||
Where("po.created_at >= ? AND po.created_at <= ?", query.StartDate, query.EndDate).
|
||||
Group("DATE(po.created_at)").
|
||||
Scan(&payments).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user