shish пре 5 година
родитељ
комит
f274a2a4de

+ 5 - 0
biz-ghs/order/services/RefundOrderService.php

@@ -5,6 +5,7 @@ namespace bizGhs\order\services;
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
 use biz\stat\classes\StatOutClass;
+use biz\stat\classes\StatRefundClass;
 use bizGhs\base\services\BaseService;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\OrderClass;
@@ -86,6 +87,8 @@ class RefundOrderService extends BaseService
         //总支出增加
         $currentTotalExpend = bcadd($shop->totalExpend, $refundPrice, 2);
         $shop->totalExpend = $currentTotalExpend;
+        $totalRefund = bcadd($shop->totalRefund, $refundPrice, 2);
+        $shop->totalRefund = $totalRefund;
         $shop->save();
 
         //支出流水
@@ -106,6 +109,8 @@ class RefundOrderService extends BaseService
         //当天和当月支出统计
         StatOutClass::updateOrInsert($shop, $refundPrice);
 
+        StatRefundClass::replace($shop, $refundPrice);
+
         //记录总的退款金额
         $currentTkPrice = bcadd($order->tkPrice, $refundPrice, 2);
         $order->tkPrice = $currentTkPrice;

+ 32 - 0
biz/stat/classes/StatRefundClass.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatRefundClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatRefund';
+
+    //退款统计 shish 20210827
+    public static function replace($shop, $amount, $date = null)
+    {
+        $sjId = $shop->sjId ?? 0;
+        $shopId = $shop->id ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalRefund;
+        $unique->num += 1;
+        $unique->save();
+        StatRefundMonthClass::replace($shop, $amount, $time);
+    }
+
+}

+ 41 - 0
biz/stat/classes/StatRefundMonthClass.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+
+class StatRefundMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatRefundMonth';
+
+    //退款统计 shish 20210827
+    public static function replace($shop, $amount, $date = null)
+    {
+        if ($date == null) {
+            $time = date('Ym');
+            $year = date('Y');
+            $month = date('m');
+        } else {
+            $timestamp = strtotime($date);
+            $time = date('Ym', $timestamp);
+            $year = date('Y', $timestamp);
+            $month = date('m', $timestamp);
+        }
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalRefund;
+        $unique->num += 1;
+        $unique->save();
+    }
+
+}

+ 13 - 0
biz/stat/models/StatRefund.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatRefund extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatRefund';
+    }
+}

+ 15 - 0
biz/stat/models/StatRefundMonth.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatRefundMonth extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhStatRefundMonth';
+    }
+
+}