Răsfoiți Sursa

盘点优化

shish 5 ani în urmă
părinte
comite
5eb5334c1f

+ 5 - 5
biz/stat/classes/StatPdAddClass.php

@@ -10,11 +10,11 @@ class StatPdAddClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatPdAdd';
 
     //盘盈统计 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');
+        $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);
@@ -26,7 +26,7 @@ class StatPdAddClass extends BaseClass
         $unique->totalAmount = $shop->totalPdAdd;
         $unique->num += 1;
         $unique->save();
-        StatPdAddMonthClass::replace($shop, $amount);
+        StatPdAddMonthClass::replace($shop, $amount, $time);
     }
 
 }

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

@@ -11,11 +11,18 @@ class StatPdAddMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatPdAddMonth';
 
     //每月盘盈统计 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);

+ 9 - 5
biz/stat/classes/StatPdSubClass.php

@@ -10,11 +10,15 @@ class StatPdSubClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatPdSub';
 
     //盘亏统计 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');
+        $sjId = $shop->sjId ?? 0;
+        $shopId = $shop->id ?? 0;
+        if ($date == null) {
+            $time = date('Ymd');
+        } else {
+            $time = $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 +30,7 @@ class StatPdSubClass extends BaseClass
         $unique->totalAmount = $shop->totalPdSub;
         $unique->num += 1;
         $unique->save();
-        StatPdSubMonthClass::replace($shop, $amount);
+        StatPdSubMonthClass::replace($shop, $amount, $time);
     }
 
 }

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

@@ -11,11 +11,18 @@ class StatPdSubMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatPdSubMonth';
 
     //每月盘亏统计 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);

+ 57 - 0
console/controllers/PdController.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace console\controllers;
+
+use biz\shop\classes\ShopClass;
+use biz\stat\classes\StatPdAddClass;
+use biz\stat\classes\StatPdSubClass;
+use bizGhs\order\classes\CheckOrderClass;
+use bizGhs\order\classes\CheckOrderItemClass;
+use common\components\util;
+use yii\console\Controller;
+use Yii;
+
+class PdController extends Controller
+{
+
+    //盘点数据 ./yii pd/update
+    public function actionUpdate()
+    {
+        $list = CheckOrderClass::getAllByCondition(['status' => 2], 'id asc', '*', null, true);
+        if (!empty($list)) {
+            foreach ($list as $item) {
+                $orderSn = $item->orderSn ?? '';
+                $shopId = $item->shopId ?? 0;
+                $addTime = $item->addTime ?? '';
+                $shop = ShopClass::getById($shopId, true);
+                if (empty($shop)) {
+                    echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
+                    continue;
+                }
+                $productList = CheckOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($productList)) {
+                    $add = 0;
+                    $sub = 0;
+                    foreach ($productList as $product) {
+                        $num = $product->profitLossNum ?? 0;
+                        $cost = $product->itemCost ?? 0;
+                        $res = bcmul($num, $cost, 2);
+                        if ($res > 0) {
+                            $add = bcadd($add, $res, 2);
+                        } else {
+                            $sub = bcadd($add, abs($res), 2);
+                        }
+                    }
+                    $date = date("Ymd", strtotime($addTime));
+                    if ($add > 0) {
+                        StatPdAddClass::replace($shop, $add, $date);
+                    }
+                    if ($sub > 0) {
+                        StatPdSubClass::replace($shop, $sub, $date);
+                    }
+                }
+            }
+        }
+    }
+
+}