新增撞车订单人工退款
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 {
|
||||
|
||||
@@ -20,6 +20,10 @@ const (
|
||||
financeStatusOfflineSettlementPending = "offline_settlement_pending"
|
||||
)
|
||||
|
||||
func payBizTypes() []string {
|
||||
return []string{"order_pay", "mohong_pay"}
|
||||
}
|
||||
|
||||
func refundBizTypes() []string {
|
||||
return []string{
|
||||
"cancel_refund",
|
||||
@@ -29,6 +33,7 @@ func refundBizTypes() []string {
|
||||
"deposit_refund",
|
||||
"rent_refund",
|
||||
"arbitration_refund",
|
||||
"mohong_refund",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,3 +23,25 @@ func TestDailyDateKey(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPayBizTypesIncludeMohongPay(t *testing.T) {
|
||||
values := map[string]bool{}
|
||||
for _, item := range payBizTypes() {
|
||||
values[item] = true
|
||||
}
|
||||
for _, want := range []string{"order_pay", "mohong_pay"} {
|
||||
if !values[want] {
|
||||
t.Fatalf("payBizTypes missing %s", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefundBizTypesIncludeMohongRefund(t *testing.T) {
|
||||
values := map[string]bool{}
|
||||
for _, item := range refundBizTypes() {
|
||||
values[item] = true
|
||||
}
|
||||
if !values["mohong_refund"] {
|
||||
t.Fatal("refundBizTypes missing mohong_refund")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user