浏览代码

损耗总览

shish 3 年之前
父节点
当前提交
8353da9299
共有 1 个文件被更改,包括 40 次插入0 次删除
  1. 40 0
      app-hd/controllers/StatController.php

+ 40 - 0
app-hd/controllers/StatController.php

@@ -14,6 +14,46 @@ use common\components\util;
 class StatController extends BaseController
 {
 
+    //按月统计损耗情况
+    public function actionWaste()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+        $mainId = $this->mainId;
+        $list = \bizGhs\order\classes\StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*');
+        $arr = [];
+        $totalNum = 0;
+        $totalCost = 0;
+        $totalPrice = 0;
+        if (!empty($list)) {
+            foreach ($list as $order) {
+                $addTime = $order['addTime'];
+                $time = date("Ym", strtotime($addTime));
+                $date = date("Y年n月", strtotime($addTime));
+                $bigNum = $order['bigNum'] ?? 0;
+                $cost = $order['cost'] ?? 0;
+                $price = $order['price'] ?? 0;
+                if (isset($arr[$time])) {
+                    $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
+                    $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
+                    $arr[$time]['price'] = bcadd($arr[$time]['price'], $price, 2);
+                    $arr[$time]['time'] = $date;
+                } else {
+                    $arr[$time]['num'] = $bigNum;
+                    $arr[$time]['cost'] = $cost;
+                    $arr[$time]['price'] = $price;
+                    $arr[$time]['time'] = $date;
+                }
+                $totalNum = bcadd($totalNum, $bigNum);
+                $totalCost = bcadd($totalCost, $cost, 2);
+                $totalPrice = bcadd($totalPrice, $price, 2);
+            }
+        }
+        $totalCost = floatval($totalCost);
+        $totalPrice = floatval($totalPrice);
+        util::success(['list' => $arr, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalPrice' => $totalPrice]);
+    }
+
     //利润表 ssh 20230303
     public function actionProfit()
     {