shish před 5 roky
rodič
revize
458577648e

+ 1 - 1
app-ghs/controllers/WastageController.php

@@ -61,7 +61,6 @@ class WastageController extends BaseController
     //列表
     public function actionList()
     {
-        $get = Yii::$app->request->get();
         $where = [];
         $where['shopId'] = $this->shopId;
         $list = StockWastageOrderClass::getOrderList($where);
@@ -74,4 +73,5 @@ class WastageController extends BaseController
         $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->shopId);
         util::success($orderData);
     }
+
 }

+ 6 - 1
biz-ghs/order/classes/StockWastageOrderClass.php

@@ -5,6 +5,7 @@ namespace bizGhs\order\classes;
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
 use biz\stat\classes\StatOutClass;
+use biz\stat\classes\StatWastClass;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\classes\StockRecordClass;
@@ -57,7 +58,7 @@ class StockWastageOrderClass extends BaseClass
             //写入订单表
             $order = self::add($data);
             foreach ($ghsItemInfo as $k => $v) {
-                $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'],true);
+                $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'], true);
                 $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
                 $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
             }
@@ -84,11 +85,15 @@ class StockWastageOrderClass extends BaseClass
             }
             $currentTotalExpend = bcadd($shop->totalExpend, $wastage, 2);
             $shop->totalExpend = $currentTotalExpend;
+            $currentWast = bcadd($shop->totalWast, $wastage, 2);
+            $shop->totalWast = $currentWast;
             $shop->save();
 
             //当天和当月支出统计
             StatOutClass::updateOrInsert($shop, $wastage);
 
+            StatWastClass::replace($shop, $wastage);
+
             //报损支出
             $capitalType = dict::getDict('capitalType', 'wastage', 'id');
             $sjId = $post['sjId'] ?? 0;

+ 3 - 3
biz/stat/classes/StatWastClass.php

@@ -10,11 +10,11 @@ class StatWastClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatWast';
 
     //盘盈统计 shish 20210827
-    public static function replace($shop, $amount)
+    public static function replace($shop, $amount, $date = null)
     {
         $sjId = $shop->sjId;
         $shopId = $shop->id;
-        $time = date('Ymd');
+        $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);
@@ -26,7 +26,7 @@ class StatWastClass extends BaseClass
         $unique->totalAmount = $shop->totalWast;
         $unique->num += 1;
         $unique->save();
-        StatWastMonthClass::replace($shop, $amount);
+        StatWastMonthClass::replace($shop, $amount, $time);
     }
 
 }

+ 11 - 4
biz/stat/classes/StatWastMonthClass.php

@@ -11,11 +11,18 @@ class StatWastMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatWastMonth';
 
     //每月盘亏统计 shish 20210827
-    public static function replace($shop, $amount)
+    public static function replace($shop, $amount, $date = null)
     {
-        $time = date('Ym');
-        $year = date('Y');
-        $month = date('m');
+        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);