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

+ 32 - 0
app-ghs/controllers/StatItemController.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace ghs\controllers;
+
+use biz\stat\classes\StatItemClass;
+use common\components\dateUtil;
+use Yii;
+use common\components\util;
+
+class StatItemController extends BaseController
+{
+
+    //花材销量 shish 20211021
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (isset($get['shopId']) && !empty($get['shopId'])) {
+            $where['shopId'] = $get['shopId'];
+        }
+        $selectTime = $get['selectTime'] ?? '';
+        if (!empty($selectTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($selectTime, $startTime, $endTime, true);
+            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+        $list = StatItemClass::getAllByCondition($where, null, '*', null, true);
+    }
+
+}

+ 56 - 0
biz-ghs/order/classes/OrderClass.php

@@ -7,6 +7,7 @@ use biz\shop\classes\ShopClass;
 use biz\shop\classes\ShopExtClass;
 use biz\shop\models\Shop;
 use biz\sj\classes\SjClass;
+use biz\stat\classes\StatItemClass;
 use biz\stat\classes\StatOrderCountClass;
 use bizGhs\custom\models\Custom;
 use bizGhs\express\services\DadaExpressServices;
@@ -1001,4 +1002,59 @@ class OrderClass extends BaseClass
         return $order;
     }
 
+    //新订单入队列 shish 20211012
+    public static function newOrderAddQueue($order)
+    {
+        $shopId = $order->shopId ?? 0;
+        if (empty($shopId)) {
+            return false;
+        }
+        $id = $order->id ?? 0;
+        if (empty($id)) {
+            return false;
+        }
+        $newOrderKey = 'ghsNewOrder_' . $shopId;
+        Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]);
+    }
+
+    //处理队列里的新订单 shish 20211012
+    public static function newOrderFromQueueDone()
+    {
+        $ghs = dict::getDict('ptStyle', 'ghs');
+        $shopList = ShopClass::getAllByCondition(['ptStyle' => $ghs], null, '*', null, true);
+        if (!empty($shopList)) {
+            foreach ($shopList as $key => $shop) {
+                $ids = [];
+                $shopId = $shop->id ?? 0;
+                $newOrderKey = 'ghsNewOrder_' . $shopId;
+                while ($count = Yii::$app->redis->executeCommand('LLEN', [$newOrderKey])) {
+                    $id = Yii::$app->redis->executeCommand('RPOP', [$newOrderKey]);
+                    if (is_numeric($id)) {
+                        $ids[] = $id;
+                    }
+                }
+                if (empty($ids)) {
+                    continue;
+                }
+                $list = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+                if (empty($list)) {
+                    return false;
+                }
+                foreach ($list as $key => $order) {
+                    $orderSn = $order->orderSn ?? '';
+                    if (empty($orderSn)) {
+                        continue;
+                    }
+                    $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                    if (empty($itemList)) {
+                        continue;
+                    }
+                    foreach ($itemList as $itemKey => $itemVal) {
+                        StatItemClass::replace($itemVal);
+                    }
+                }
+            }
+        }
+    }
+
 }

+ 3 - 0
biz-ghs/order/services/OrderService.php

@@ -611,6 +611,9 @@ class OrderService extends BaseService
         $order->payTime = date("Y-m-d H:i:s");
         $order->save();
 
+        //入队列,花材统计
+        OrderClass::newOrderAddQueue($order);
+
         //员工业绩、总业绩增加
         $shopAdminId = $order->shopAdminId ?? 0;
         if (!empty($shopAdminId)) {

+ 0 - 1
biz-ghs/product/classes/ProductClass.php

@@ -1259,7 +1259,6 @@ class ProductClass extends BaseClass
                 $ids = [];
                 $shopId = $shop->id ?? 0;
                 $stockWarningListKey = 'stockWarningList_' . $shopId;
-                echo $stockWarningListKey . "\n";
                 while ($count = Yii::$app->redis->executeCommand('LLEN', [$stockWarningListKey])) {
                     $productId = Yii::$app->redis->executeCommand('RPOP', [$stockWarningListKey]);
                     if (is_numeric($productId)) {

+ 42 - 0
biz/stat/classes/StatItemClass.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use biz\stat\models\StatCg;
+use common\components\util;
+
+class StatItemClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatItem';
+
+    //每日花材统计 shish 2021012
+    public static function replace($item, $date = null)
+    {
+        $sjId = $item->sjId ?? 0;
+        $shopId = $item->id ?? 0;
+        $productId = $item->productId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+
+        $amount = $item->price ?? 0;
+        $num = $item->num ?? 0;
+
+        $currentNum = bcadd($unique->num, $num, 2);
+        $unique->num = $currentNum;
+
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+        StatItemMonthClass::replace($amount, $time);
+    }
+
+}

+ 49 - 0
biz/stat/classes/StatItemMonthClass.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use biz\stat\models\StatCg;
+use common\components\util;
+
+class StatItemMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatItemMonth';
+
+    //每月花材统计 shish 20211012
+    public static function replace($item, $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 = $item->sjId ?? 0;
+        $shopId = $item->id ?? 0;
+        $productId = $item->productId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        $amount = $item->price ?? 0;
+        $num = $item->num ?? 0;
+
+        $currentNum = bcadd($unique->num, $num, 2);
+        $unique->num = $currentNum;
+
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+    }
+
+}

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

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

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

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

+ 6 - 0
console/controllers/GlobalController.php

@@ -2,6 +2,7 @@
 
 namespace console\controllers;
 
+use bizGhs\order\classes\OrderClass;
 use bizGhs\product\classes\ProductClass;
 use Yii;
 use yii\console\Controller;
@@ -22,6 +23,11 @@ class GlobalController extends Controller
             ProductClass::allShopStockWarningFromQueue();
         }
 
+        //每三分钟进行一次完成订单的花材统计
+        if ((int)date('i') % 3 == 0) {
+            OrderClass::newOrderFromQueueDone();
+        }
+
     }
 
 }