Bladeren bron

花材数量统计

shish 3 jaren geleden
bovenliggende
commit
8b889ab3f1
1 gewijzigde bestanden met toevoegingen van 52 en 2 verwijderingen
  1. 52 2
      app-ghs/controllers/StatItemController.php

+ 52 - 2
app-ghs/controllers/StatItemController.php

@@ -14,8 +14,8 @@ use common\components\util;
 class StatItemController extends BaseController
 {
 
-    //花材销量 ssh 20211021
-    public function actionProfile()
+    //花材销量 ssh 20230223
+    public function actionShow()
     {
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
@@ -92,4 +92,54 @@ class StatItemController extends BaseController
         util::success(['list' => $stat]);
     }
 
+
+    //花材销量 ssh 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'];
+        }
+        $searchTime = $get['searchTime'] ?? 'today';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
+            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+        $list = StatItemClass::getAllByCondition($where, null, '*');
+        if (empty($list)) {
+            util::success(['list' => $list]);
+        }
+        $ids = array_column($list, 'itemId');
+        $ids = array_unique(array_filter($ids));
+        $productInfo = ProductClass::getByIds($ids, null, 'id');
+        $stat = [];
+        foreach ($list as $key => $val) {
+            $itemId = $val['itemId'] ?? 0;
+            $idsData[$itemId] = 0;
+            $num = bcsub($val['num'], $val['refundNum'], 2);
+            $amount = bcsub($val['amount'], $val['refundAmount'], 2);
+            $name = $productInfo[$itemId]['name'] ?? '';
+            $py = $productInfo[$itemId]['py'] ?? '';
+            $stat[$itemId]['productId'] = $itemId;
+            $stat[$itemId]['name'] = $name;
+            $stat[$itemId]['py'] = $py;
+            if (isset($stat[$itemId]['num'])) {
+                $stat[$itemId]['num'] = bcadd($stat[$itemId]['num'], $num, 2);
+            } else {
+                $stat[$itemId]['num'] = $num;
+            }
+            if (isset($stat[$itemId]['amount'])) {
+                $stat[$itemId]['amount'] = bcadd($stat[$itemId]['amount'], $amount, 2);
+            } else {
+                $stat[$itemId]['amount'] = $amount;
+            }
+        }
+        $stat = arrayUtil::arraySort($stat, 'num');
+        util::success(['list' => $stat]);
+    }
+
 }