shish 3 år sedan
förälder
incheckning
99fea7f518
1 ändrade filer med 89 tillägg och 1 borttagningar
  1. 89 1
      app-hd/controllers/StatKindController.php

+ 89 - 1
app-hd/controllers/StatKindController.php

@@ -3,6 +3,8 @@
 namespace hd\controllers;
 
 use bizHd\goods\classes\KindClass;
+use bizHd\goods\classes\PlantCgClass;
+use bizHd\goods\classes\PlantCgItemClass;
 use bizHd\item\classes\ItemClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderGoodsClass;
@@ -16,7 +18,7 @@ use common\components\util;
 class StatKindController extends BaseController
 {
 
-    //各渠道收入 ssh 20220711
+    //花束相关统计 ssh 20230320
     public function actionProfile()
     {
         $get = Yii::$app->request->get();
@@ -140,4 +142,90 @@ class StatKindController extends BaseController
         util::success(['kindStat' => $kindStat, 'partStat' => $partStat, 'workTotalUseSmallNum' => $workTotalUseSmallNum, 'partTotalSmallNum' => $partTotalSmallNum, 'partTotalNum' => $partTotalNum]);
     }
 
+    //绿植相关的统计 ssh 20230320
+    public function actionLzProfile()
+    {
+        $get = Yii::$app->request->get();
+
+        $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
+        $startTime = $get['startTime'] ?? '';
+        $endTime = $get['endTime'] ?? '';
+        $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
+        $start = $period['startTime'];
+        $end = $period['endTime'];
+        $currentStartDate = date('Y-m-d', strtotime($start));
+        $currentEndDate = date('Y-m-d', strtotime($end));
+        $currentStartTime = $currentStartDate . ' 00:00:00';
+        $currentEndTime = $currentEndDate . ' 23:59:59';
+
+        $mainId = $this->mainId;
+
+        $kindList = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => 1, 'delStatus' => 0, 'status' => 1], null, '*', 'id');
+
+        $kindStat = [];
+
+        $where = ['mainId' => $mainId, 'status' => 1];
+        $where['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $lzList = PlantCgClass::getAllByCondition([$where], null, '*', null, true);
+        if (!empty($lzList)) {
+            foreach ($lzList as $lz) {
+                $orderSn = $lz->orderSn ?? '';
+                $lzItemList = PlantCgItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($lzItemList)) {
+                    foreach ($lzItemList as $lzItem) {
+                        $kindId = $lzItem->kindId ?? 0;
+                        if (empty($kindId)) {
+                            continue;
+                        }
+                        $num = $lzItem->num ?? 0;
+                        $kindName = $kindList[$kindId]['name'] ?? '';
+                        if (isset($kindStat[$kindId]['cgNum'])) {
+                            $kindStat[$kindId]['cgNum'] = bcadd($kindStat[$kindId]['cgNum'], $num);
+                        } else {
+                            $kindStat[$kindId]['cgNum'] = $num;
+                            $kindStat[$kindId]['name'] = $kindName;
+                            if (isset($kindStat[$kindId]['saleNum']) == false) {
+                                $kindStat[$kindId]['saleNum'] = 0;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        $where = ['mainId' => $mainId, 'payStatus' => 1, 'payTime' => ['between', [$currentStartTime, $currentEndTime]]];
+        $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
+        if (!empty($orderList)) {
+            foreach ($orderList as $order) {
+                $orderSn = $order->orderSn ?? '';
+                $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($sonList)) {
+                    foreach ($sonList as $son) {
+                        $flower = $son->flower ?? 0;
+                        if ($flower == 1) {
+                            continue;
+                        }
+                        $kindId = $son->kindId ?? 0;
+                        if (empty($kindId)) {
+                            continue;
+                        }
+                        $num = $son->num ?? 0;
+                        $kindName = $kindList[$kindId]['name'] ?? '';
+                        if (isset($kindStat[$kindId]['saleNum'])) {
+                            $kindStat[$kindId]['saleNum'] = bcadd($kindStat[$kindId]['saleNum'], $num);
+                        } else {
+                            $kindStat[$kindId]['saleNum'] = $num;
+                            $kindStat[$kindId]['kindName'] = $kindName;
+                            if (isset($kindStat[$kindId]['cgNum']) == false) {
+                                $kindStat[$kindId]['cgNum'] = 0;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        util::success(['kindStat' => $kindStat]);
+    }
+
 }