shish 4 лет назад
Родитель
Сommit
a86e13113e

+ 1 - 5
app-ghs/controllers/StatCgGhsController.php

@@ -17,10 +17,7 @@ class StatCgGhsController extends BaseController
     {
         $get = Yii::$app->request->get();
         $where = [];
-        $where['shopId'] = $this->shopId;
-        if (isset($get['shopId']) && !empty($get['shopId'])) {
-            $where['shopId'] = $get['shopId'];
-        }
+        $where['mainId'] = $this->mainId;
         $searchTime = $get['searchTime'] ?? 'today';
         if (!empty($searchTime)) {
             $startTime = $get['startTime'] ?? '';
@@ -28,7 +25,6 @@ class StatCgGhsController extends BaseController
             $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
             $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
         }
-
         $list = StatCgGhsClass::getAllByCondition($where, null, '*');
         $ghsIds = [];
         $arr = [];

+ 1 - 5
app-hd/controllers/StatCgGhsController.php

@@ -17,10 +17,7 @@ class StatCgGhsController extends BaseController
     {
         $get = Yii::$app->request->get();
         $where = [];
-        $where['shopId'] = $this->shopId;
-        if (isset($get['shopId']) && !empty($get['shopId'])) {
-            $where['shopId'] = $get['shopId'];
-        }
+        $where['mainId'] = $this->mainId;
         $searchTime = $get['searchTime'] ?? 'today';
         if (!empty($searchTime)) {
             $startTime = $get['startTime'] ?? '';
@@ -28,7 +25,6 @@ class StatCgGhsController extends BaseController
             $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
             $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
         }
-
         $list = StatCgGhsClass::getAllByCondition($where, null, '*');
         $ghsIds = [];
         $arr = [];

+ 5 - 2
biz-hd/purchase/services/PurchaseService.php

@@ -9,6 +9,7 @@ use biz\shop\classes\ShopClass;
 use biz\shop\classes\ShopCouponClass;
 use biz\shop\models\Shop;
 use biz\stat\classes\StatCgClass;
+use biz\stat\classes\StatCgGhsClass;
 use biz\stat\classes\StatOutClass;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\custom\classes\CustomClass;
@@ -399,9 +400,11 @@ class PurchaseService extends BaseService
         ShopCapitalClass::addCapital($capitalData);
 
         //采购统计
-        StatCgClass::replace($shop, $info->actPrice);
+        StatCgClass::replace($shop, $info->orderPrice);
+        //采购按供货商统计
+        StatCgGhsClass::hdCgGhsReplace($info);
         //支出统计
-        StatOutClass::updateOrInsert($shop, $info->actPrice);
+        StatOutClass::updateOrInsert($shop, $info->orderPrice);
 
         //使用优惠券
         $hbId = $info->hbId;

+ 3 - 2
biz/stat/classes/StatCgClass.php

@@ -22,10 +22,11 @@ class StatCgClass extends BaseClass
     public static function replace($shop, $amount)
     {
         $mainId = $shop->mainId ?? 0;
+        $sjId = $shop->sjId ?? 0;
         $time = date('Ymd');
-        $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
+        $stat = self::getByCondition(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
         if (empty($stat)) {
-            $stat = self::add(['mainId' => $mainId, 'time' => $time, 'num' => 0], true);
+            $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true);
         }
         $id = $stat->id;
         $unique = self::getLockById($id);

+ 21 - 1
biz/stat/classes/StatCgGhsClass.php

@@ -9,7 +9,27 @@ class StatCgGhsClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatCgGhs';
 
-    //采购统计 shish 2021012
+    //花店采购统计 ssh 20220402
+    public static function hdCgGhsReplace($cgInfo, $date = null)
+    {
+        $sjId = $cgInfo->sjId ?? 0;
+        $mainId = $cgInfo->mainId ?? 0;
+        $ghsId = $cgInfo->ghsId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $amount = $cgInfo->orderPrice ?? 0;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->save();
+        StatCgGhsMonthClass::hdCgGhsReplace($cgInfo, $time);
+    }
+
+    //城市批发商采购统计 shish 2021012
     public static function ghsReplace($cgInfo, $date = null)
     {
         $sjId = $cgInfo->sjId ?? 0;

+ 27 - 0
biz/stat/classes/StatCgGhsMonthClass.php

@@ -9,6 +9,33 @@ class StatCgGhsMonthClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatCgGhsMonth';
 
+    public static function hdCgGhsReplace($order, $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 = $order->sjId ?? 0;
+        $mainId = $order->mainId ?? 0;
+        $ghsId = $order->ghsId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $amount = $cgInfo->orderPrice ?? 0;
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->save();
+    }
+
     //每月采购统计 shish 20211012
     public static function ghsReplace($order, $date = null)
     {

+ 3 - 2
biz/stat/classes/StatCgMonthClass.php

@@ -17,9 +17,10 @@ class StatCgMonthClass extends BaseClass
         $year = date('Y');
         $month = date('m');
         $mainId = $shop->mainId ?? 0;
-        $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
+        $sjId = $shop->sjId ?? 0;
+        $stat = self::getByCondition(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
         if (empty($stat)) {
-            $stat = self::add(['mainId' => $mainId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
+            $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
         }
         $id = $stat->id;
         $unique = self::getLockById($id);

+ 4 - 0
console/controllers/InitController.php

@@ -25,6 +25,7 @@ use biz\stat\classes\StatStockInClass;
 use biz\stat\classes\StatStockInMonthClass;
 use biz\stat\classes\StatStockOutClass;
 use biz\stat\classes\StatStockOutMonthClass;
+use bizGhs\cg\classes\CgClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\classes\ItemClassClass;
@@ -126,6 +127,9 @@ class InitController extends Controller
             StatRefundClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
             StatRefundMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
+            //ghs专有的
+            CgClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
             /********琦海 start ************/
 
             //报损中央化

+ 3 - 1
sql.txt

@@ -715,4 +715,6 @@ ALTER TABLE xhStatStockIn ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' A
 ALTER TABLE xhStatStockInMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
 
 ALTER TABLE xhStatRefund ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
-ALTER TABLE xhStatRefundMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+ALTER TABLE xhStatRefundMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+
+ALTER TABLE xhGhsCgOrder ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;