shish 2 년 전
부모
커밋
bde0e06ef9
1개의 변경된 파일32개의 추가작업 그리고 8개의 파일을 삭제
  1. 32 8
      biz-ghs/stat/classes/StatCgClass.php

+ 32 - 8
biz-ghs/stat/classes/StatCgClass.php

@@ -3,6 +3,8 @@
 namespace bizGhs\stat\classes;
 
 use bizGhs\order\classes\PurchaseOrderClass;
+use bizGhs\order\classes\PurchaseOrderItemClass;
+use bizGhs\product\classes\ProductClass;
 use common\components\dateUtil;
 use Yii;
 use bizGhs\base\classes\BaseClass;
@@ -29,20 +31,42 @@ class StatCgClass extends BaseClass
         $currentStartTime = $currentStartDate . ' 00:00:00';
         $currentEndTime = $currentEndDate . ' 23:59:59';
 
-        //采购入库
+        $productInfo = ProductClass::getAllByCondition(['mainId' => $mainId], null, 'id,name,py', 'id');
+
         $cgWhere = ['mainId' => $mainId, 'status' => 4];
         $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
         $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
-        $cg = 0;
+        $arr = [];
         if (!empty($cgList)) {
-            foreach ($cgList as $cgKey => $cgItem) {
-                $actPrice = $cgItem['actPrice'] ?? 0;
-                $paidPrice = $cgItem['paidPrice'] ?? 0;
-                $total = bcadd($actPrice, $paidPrice, 2);
-                $cg = bcadd($cg, $total, 2);
+            foreach ($cgList as $cgKey => $cgInfo) {
+                $orderSn = $cgInfo['orderSn'] ?? '';
+                $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($itemList)) {
+                    foreach ($itemList as $key => $val) {
+                        $productId = $val->productId ?? 0;
+                        $num = $val->num ?? 0;
+                        $refundNum = $val->refundNum ?? 0;
+                        $remainNum = bcsub($num, $refundNum);
+                        $unitPrice = $val->bigPrice ?? 0;
+                        $name = $productInfo[$productId]['name'] ?? '';
+                        $py = $productInfo[$productId]['py'] ?? '';
+
+                        if (isset($arr[$productId])) {
+                            $totalPrice = bcmul($remainNum, $unitPrice, 2);
+                            $arr[$productId]['num'] = bcadd($arr[$productId]['num'], $remainNum);
+                            $arr[$productId]['amount'] = bcadd($arr[$productId]['amount'], $totalPrice, 2);
+                        } else {
+                            $arr[$productId]['num'] = 0;
+                            $arr[$productId]['amount'] = 0;
+                            $arr[$productId]['py'] = $py;
+                            $arr[$productId]['name'] = $name;
+                        }
+                    }
+                }
             }
         }
-        $cg = floatval($cg);
+        print_r($arr);
+        
     }
 
 }