shish преди 3 години
родител
ревизия
17bc1456b5
променени са 2 файла, в които са добавени 100 реда и са изтрити 0 реда
  1. 98 0
      app-hd/controllers/StatCgController.php
  2. 2 0
      biz-ghs/order/classes/PurchaseOrderClass.php

+ 98 - 0
app-hd/controllers/StatCgController.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace hd\controllers;
+
+use biz\ghs\classes\GhsClass;
+use biz\stat\classes\StatCgGhsClass;
+use common\components\arrayUtil;
+use common\components\dateUtil;
+use Yii;
+use common\components\util;
+
+class StatCgController extends BaseController
+{
+
+    //一整年采购了哪些花材
+
+    //还可以选择供货商
+
+    //做一个需求反馈的入口
+
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $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 = StatCgGhsClass::getAllByCondition($where, null, '*');
+        $ghsIds = [];
+        $arr = [];
+        if (!empty($list)) {
+            foreach ($list as $ke => $item) {
+                $ghsId = $item['ghsId'] ?? 0;
+                $num = $item['num'] ?? 0;
+                $refundNum = $item['refundNum'] ?? 0;
+                $amount = $item['amount'] ?? 0;
+                $refundAmount = $item['refundAmount'] ?? 0;
+                $ghsIds[$ghsId] = 1;
+
+                if (isset($arr[$ghsId]['num'])) {
+                    $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
+                } else {
+                    $arr[$ghsId]['num'] = $num;
+                }
+
+                if (isset($arr[$ghsId]['refundNum'])) {
+                    $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
+                } else {
+                    $arr[$ghsId]['refundNum'] = $refundNum;
+                }
+
+                if (isset($arr[$ghsId]['amount'])) {
+                    $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
+                } else {
+                    $arr[$ghsId]['amount'] = $amount;
+                }
+
+                if (isset($arr[$ghsId]['refundAmount'])) {
+                    $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
+                } else {
+                    $arr[$ghsId]['refundAmount'] = $refundAmount;
+                }
+
+            }
+        }
+        $ghsIds = array_keys($ghsIds);
+        $ghsData = GhsClass::getByIds($ghsIds);
+        $cg = [];
+        foreach ($ghsData as $ghs) {
+            $ghsId = $ghs['id'] ?? 0;
+            $ghsName = $ghs['name'] ?? '';
+            $ghsPy = $ghs['py'] ?? '';
+            $num = $arr[$ghsId]['num'] ?? 0;
+            $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
+            $amount = $arr[$ghsId]['amount'] ?? 0;
+            $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
+            $lastAmount = bcsub($amount, $refundAmount, 2);
+            $lastNum = bcsub($num, $refundNum, 2);
+            $cg[] = [
+                'ghsId' => $ghsId,
+                'ghsName' => $ghsName,
+                'py' => $ghsPy,
+                'num' => $lastNum,
+                'amount' => $lastAmount,
+            ];
+        }
+        $cg = arrayUtil::arraySort($cg, 'num');
+        util::success(['list' => $cg]);
+    }
+
+
+
+}

+ 2 - 0
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -458,9 +458,11 @@ class PurchaseOrderClass extends BaseClass
                 $currentBigUnit = $productList[$productId]['bigUnit'] ?? '';
                 $currentSmallUnit = $productList[$productId]['smallUnit'] ?? '';
                 $currentRatio = $productList[$productId]['ratio'] ?? 0;
+                $presell = $productList[$productId]['presell'] ?? 0;
                 $batchData[$currentKey]['bigUnit'] = $currentBigUnit;
                 $batchData[$currentKey]['smallUnit'] = $currentSmallUnit;
                 $batchData[$currentKey]['ratio'] = $currentRatio;
+                $batchData[$currentKey]['presell'] = $presell;
 
                 if ($inType == self::IN_TYPE_NOW) {
                     $product = ProductClass::getLockById($productId);