Răsfoiți Sursa

跨天售后影响

shish 12 ore în urmă
părinte
comite
c0f6065885

+ 26 - 0
app-ghs/controllers/StatKdController.php

@@ -2,8 +2,10 @@
 
 namespace ghs\controllers;
 
+use bizGhs\order\classes\NextDayRefundClass;
 use bizGhs\shop\classes\ShopAdminClass;
 use bizGhs\stat\classes\StatKdClass;
+use common\components\dateUtil;
 use common\components\util;
 use Yii;
 
@@ -49,4 +51,28 @@ class StatKdController extends BaseController
         util::success(['list' => $incomeList, 'totalIncome' => $totalIncome, 'staffAmountList' => $staffAmountList, 'payCodeIncome' => $payCodeIncome]);
     }
 
+    /**
+     * 跨天售后影响:筛售后创建时间,按原单账单日汇总日/月金额。
+     * PC /assets/nextDayAffect 使用;只计挂上 xhGhsOrder 的已通过跨天售后。
+     */
+    public function actionNextDayAffect()
+    {
+        $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
+        if ($lookMoney == 0) {
+            util::fail('无法查看');
+        }
+        $get = Yii::$app->request->get();
+        $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
+        $startTime = $get['startTime'] ?? '';
+        $endTime = $get['endTime'] ?? '';
+        // 售后 addTime 用完整时分秒,不能走统计页的 Ymd
+        $period = dateUtil::formatTime($searchTime, $startTime, $endTime, false);
+        $data = NextDayRefundClass::affectByOrderPayTime(
+            $this->mainId,
+            $period['startTime'],
+            $period['endTime']
+        );
+        util::success($data);
+    }
+
 }

+ 67 - 0
biz-ghs/order/classes/NextDayRefundClass.php

@@ -905,6 +905,73 @@ class NextDayRefundClass
         return $map;
     }
 
+    /**
+     * 跨天售后对原单账单日的影响:筛售后创建时间,按 xhGhsOrder.payTime 汇总日/月金额。
+     * 只 INNER JOIN 批发单,零售/采购不算;只统计已通过,避免未审核当成已冲回。
+     *
+     * @param int $mainId
+     * @param string $startTime 售后 addTime 起(含时分秒)
+     * @param string $endTime 售后 addTime 止
+     * @return array{dayList:array,monthList:array,totalAmount:float}
+     */
+    public static function affectByOrderPayTime($mainId, $startTime, $endTime)
+    {
+        $sql = "SELECT DATE(o.payTime) AS billDay,
+                DATE_FORMAT(o.payTime, '%Y-%m') AS billMonth,
+                COALESCE(SUM(r.refundPrice), 0) AS amount
+            FROM xhRefund r
+            INNER JOIN xhGhsOrder o ON o.orderSn = r.relateOrderSn AND o.mainId = r.mainId
+            WHERE r.mainId = :mainId
+              AND r.status = :status
+              AND r.sameDay = :sameDay
+              AND r.addTime BETWEEN :start AND :end
+              AND o.payTime > '1970-01-01'
+            GROUP BY billDay, billMonth
+            ORDER BY billDay DESC";
+        $rows = Yii::$app->db->createCommand($sql, [
+            ':mainId' => $mainId,
+            ':status' => RefundOrderClass::STATUS_COMPLETE,
+            ':sameDay' => self::SAME_DAY_NO,
+            ':start' => $startTime,
+            ':end' => $endTime,
+        ])->queryAll();
+
+        $dayList = [];
+        $monthMap = [];
+        $totalAmount = '0.00';
+        foreach ($rows ?: [] as $row) {
+            $amount = bcadd((string)($row['amount'] ?? '0'), '0', 2);
+            if (bccomp($amount, '0', 2) == 0) {
+                continue;
+            }
+            $dayList[] = [
+                'day' => $row['billDay'] ?? '',
+                'amount' => floatval($amount),
+            ];
+            $month = $row['billMonth'] ?? '';
+            if ($month !== '') {
+                if (!isset($monthMap[$month])) {
+                    $monthMap[$month] = '0.00';
+                }
+                $monthMap[$month] = bcadd($monthMap[$month], $amount, 2);
+            }
+            $totalAmount = bcadd($totalAmount, $amount, 2);
+        }
+        krsort($monthMap);
+        $monthList = [];
+        foreach ($monthMap as $month => $amt) {
+            $monthList[] = [
+                'month' => $month,
+                'amount' => floatval($amt),
+            ];
+        }
+        return [
+            'dayList' => $dayList,
+            'monthList' => $monthList,
+            'totalAmount' => floatval($totalAmount),
+        ];
+    }
+
     /**
      * @param array $rows
      * @return array