shish 4 rokov pred
rodič
commit
66a8e93dcc
1 zmenil súbory, kde vykonal 31 pridanie a 1 odobranie
  1. 31 1
      app-ghs/controllers/StatItemController.php

+ 31 - 1
app-ghs/controllers/StatItemController.php

@@ -3,6 +3,8 @@
 namespace ghs\controllers;
 
 use biz\stat\classes\StatItemClass;
+use bizGhs\product\classes\ProductClass;
+use common\components\arrayUtil;
 use common\components\dateUtil;
 use Yii;
 use common\components\util;
@@ -26,7 +28,35 @@ class StatItemController extends BaseController
             $period = dateUtil::formatTime($selectTime, $startTime, $endTime, true);
             $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
         }
-        $list = StatItemClass::getAllByCondition($where, null, '*', null, true);
+        $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 = $val['num'] ?? 0;
+            $amount = $val['amount'] ?? 0;
+            $name = $productInfo[$itemId]['name'] ?? '';
+            $stat[$itemId]['productId'] = $itemId;
+            $stat[$itemId]['name'] = $name;
+            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]);
     }
 
 }