shish %!s(int64=4) %!d(string=hai) anos
pai
achega
042aeaa8c4

+ 4 - 4
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -179,7 +179,7 @@ class PurchaseOrderClass extends BaseClass
             $data['avgKgWeight'] = $avgKgWeight;
             $data['avgKgWeight'] = $avgKgWeight;
 
 
             $data['cgStyle'] = dict::getDict('cgStyle', 'ghs');
             $data['cgStyle'] = dict::getDict('cgStyle', 'ghs');
-            $order = self::add($data);
+            $order = self::add($data, true);
 
 
             //组装详情表数据
             //组装详情表数据
             $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
             $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
@@ -275,7 +275,7 @@ class PurchaseOrderClass extends BaseClass
             //采购统计
             //采购统计
             StatCgClass::replace($shop, $currentPrice);
             StatCgClass::replace($shop, $currentPrice);
             //采购按供货商统计
             //采购按供货商统计
-            StatCgGhsClass::ghsReplace($order, $currentPrice);
+            StatCgGhsClass::ghsReplace($order);
             //当天和当月支出统计
             //当天和当月支出统计
             StatOutClass::updateOrInsert($shop, $currentPrice);
             StatOutClass::updateOrInsert($shop, $currentPrice);
 
 
@@ -305,8 +305,8 @@ class PurchaseOrderClass extends BaseClass
             //支出流水
             //支出流水
             $payWay = dict::getDict('payWay', 'unknown');
             $payWay = dict::getDict('payWay', 'unknown');
             $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
             $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
-            $sjId = $order['sjId'] ?? 0;
-            $shopId = $order['shopId'] ?? 0;
+            $sjId = $order->sjId ?? 0;
+            $shopId = $order->shopId ?? 0;
             $event = '采购';
             $event = '采购';
             $capitalData = [
             $capitalData = [
                 'capitalType' => $capitalType,
                 'capitalType' => $capitalType,

+ 8 - 2
biz/stat/classes/StatCgGhsClass.php

@@ -10,7 +10,7 @@ class StatCgGhsClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatCgGhs';
     public static $baseFile = '\biz\stat\models\StatCgGhs';
 
 
     //采购统计 shish 2021012
     //采购统计 shish 2021012
-    public static function ghsReplace($cgInfo, $amount, $date = null)
+    public static function ghsReplace($cgInfo, $date = null)
     {
     {
         $sjId = $cgInfo->sjId ?? 0;
         $sjId = $cgInfo->sjId ?? 0;
         $shopId = $cgInfo->shopId ?? 0;
         $shopId = $cgInfo->shopId ?? 0;
@@ -22,6 +22,12 @@ class StatCgGhsClass extends BaseClass
         }
         }
         $id = $stat->id;
         $id = $stat->id;
 
 
+        $amount = $cgInfo->price ?? 0;
+        $totalFreight = $cgInfo->totalFreight ?? 0;
+        if ($totalFreight > 0) {
+            $amount = bcadd($totalFreight, $amount, 2);
+        }
+
         $unique = self::getLockById($id);
         $unique = self::getLockById($id);
 
 
         $num = $cgInfo->itemNum ?? 0;
         $num = $cgInfo->itemNum ?? 0;
@@ -33,7 +39,7 @@ class StatCgGhsClass extends BaseClass
         $unique->amount = $currentAmount;
         $unique->amount = $currentAmount;
 
 
         $unique->save();
         $unique->save();
-        StatCgGhsMonthClass::ghsReplace($cgInfo, $amount, $time);
+        StatCgGhsMonthClass::ghsReplace($cgInfo, $time);
     }
     }
 
 
     //退款统计
     //退款统计

+ 7 - 1
biz/stat/classes/StatCgGhsMonthClass.php

@@ -10,7 +10,7 @@ class StatCgGhsMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatCgGhsMonth';
     public static $baseFile = '\biz\stat\models\StatCgGhsMonth';
 
 
     //每月采购统计 shish 20211012
     //每月采购统计 shish 20211012
-    public static function ghsReplace($order, $amount, $date = null)
+    public static function ghsReplace($order, $date = null)
     {
     {
         if ($date == null) {
         if ($date == null) {
             $time = date('Ym');
             $time = date('Ym');
@@ -32,6 +32,12 @@ class StatCgGhsMonthClass extends BaseClass
         $id = $stat->id;
         $id = $stat->id;
         $unique = self::getLockById($id);
         $unique = self::getLockById($id);
 
 
+        $amount = $cgInfo->price ?? 0;
+        $totalFreight = $cgInfo->totalFreight ?? 0;
+        if ($totalFreight > 0) {
+            $amount = bcadd($totalFreight, $amount, 2);
+        }
+
         $num = $order->itemNum ?? 0;
         $num = $order->itemNum ?? 0;
 
 
         $currentNum = bcadd($unique->num, $num, 2);
         $currentNum = bcadd($unique->num, $num, 2);

+ 41 - 0
console/controllers/StatCgGhsController.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace console\controllers;
+
+use biz\stat\classes\StatCgGhsClass;
+use bizGhs\order\classes\PurchaseOrderClass;
+use bizGhs\order\models\PurchaseOrder;
+use yii\console\Controller;
+use Yii;
+
+class StatCgGhsController extends Controller
+{
+
+    // ./yii stat-cg-ghs/bc
+    public function actionBc()
+    {
+
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $sql = 'TRUNCATE `xhStatCgGhs`;TRUNCATE `xhStatCgGhsMonth`;';
+        Yii::$app->db->createCommand($sql)->execute();
+
+        $query = new \yii\db\Query();
+        $query->from(PurchaseOrder::tableName());
+
+        foreach ($query->batch() as $batch) {
+            foreach ($batch as $cgInfo) {
+                $id = $cgInfo['id'] ?? 0;
+                $date = date('Ymd', strtotime($cgInfo['addTime']));
+                $current = PurchaseOrderClass::getById($id, true);
+                if (empty($current)) {
+                    continue;
+                }
+                StatCgGhsClass::ghsReplace($current, $date);
+            }
+        }
+
+    }
+
+}