Ver Fonte

按分类统计

shish há 2 anos atrás
pai
commit
a615fed9a6

+ 20 - 6
app-ghs/controllers/StatController.php

@@ -63,7 +63,8 @@ class StatController extends BaseController
         util::success(['list' => $cgList, 'total' => $total]);
     }
 
-    public function actionProfit()
+    //按分类统计收入 ssh 20231111
+    public function actionClassProfit()
     {
 
         ini_set('memory_limit', '2045M');
@@ -75,11 +76,24 @@ class StatController extends BaseController
             util::fail('无法查看');
         }
 
-        //惠雅鲜花员工不能看利润表
-        $shopAdmin = $this->shopAdmin;
-        $adminId = $shopAdmin->adminId ?? 0;
-        if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
-            util::fail('暂无权限');
+        $mainId = $this->mainId;
+        $respond = StatSaleClass::classProfile($mainId);
+        $income = $respond['income'] ?? 0;
+        $expend = $respond['expend'] ?? 0;
+        $balance = $respond['balance'] ?? 0;
+        util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]);
+    }
+
+    public function actionProfit()
+    {
+
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        //查看财务的权限
+        $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
+        if ($lookMoney == 0) {
+            util::fail('无法查看');
         }
 
         $mainId = $this->mainId;

+ 105 - 0
biz-ghs/stat/classes/StatSaleClass.php

@@ -5,9 +5,12 @@ namespace bizGhs\stat\classes;
 use biz\stat\classes\StatCgClass;
 use biz\stat\classes\StatStockInClass;
 use biz\stat\classes\StatStockOutClass;
+use bizGhs\cg\classes\CgRefundClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\expend\classes\ExpendClass;
+use bizGhs\item\classes\ItemClassClass;
 use bizGhs\order\classes\PurchaseOrderClass;
+use bizGhs\order\classes\PurchaseOrderItemClass;
 use bizGhs\order\classes\StockWastageOrderClass;
 use bizGhs\staff\classes\SalaryClass;
 use bizHd\goods\classes\PlantCgClass;
@@ -17,6 +20,7 @@ use bizHd\purchase\classes\PurchaseClass;
 use common\components\arrayUtil;
 use common\components\dateUtil;
 use common\components\dict;
+use common\components\util;
 use Yii;
 use bizGhs\base\classes\BaseClass;
 
@@ -326,4 +330,105 @@ class StatSaleClass extends BaseClass
         return ['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'totalOrderNum' => $totalOrderNum];
     }
 
+    //按分类统计收入 ssh 20231111
+    public static function classProfile($mainId)
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $mainId;
+        $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
+
+        $startTime = $get['startTime'] ?? '';
+        $endTime = $get['endTime'] ?? '';
+        $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
+        $start = $period['startTime'];
+        $end = $period['endTime'];
+        $where['time'] = ['between', [$start, $end]];
+
+        $currentStartDate = date('Y-m-d', strtotime($start));
+        $currentEndDate = date('Y-m-d', strtotime($end));
+        $currentStartTime = $currentStartDate . ' 00:00:00';
+        $currentEndTime = $currentEndDate . ' 23:59:59';
+
+        $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, 'id,name', 'id');
+        if (empty($classList)) {
+            util::fail('没有找到花材');
+        }
+
+        $arr = [];
+        //采购入库
+        $cgWhere = ['mainId' => $mainId, 'status' => 4];
+        $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
+        $cg = 0;
+        if (!empty($cgList)) {
+            foreach ($cgList as $cgKey => $cgItem) {
+                $actPrice = $cgItem['actPrice'] ?? 0;
+                $paidPrice = $cgItem['paidPrice'] ?? 0;
+                $tkPrice = $cgItem['tkPrice'] ?? 0;
+                $orderSn = $cgItem['orderSn'] ?? '';
+                $total = bcadd($actPrice, $paidPrice, 2);
+                $cg = bcadd($cg, $total, 2);
+                $cgItemInfoList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($cgItemInfoList)) {
+                    foreach ($cgItemInfoList as $cgData) {
+                        $itemNum = $cgData->itemNum ?? 0;
+                        $refundNum = $cgData->refundNum ?? 0;
+                        $remainNum = bcsub($itemNum, $refundNum);
+                        $bigPrice = $cgData->bigPrice ?? 0;
+                        $amount = bcmul($remainNum, $bigPrice, 2);
+                        $classId = $cgData->classId;
+                        $className = $classList[$classId]['name'] ?? '未知';
+                        $arr[$classId]['className'] = $className;
+                        if (isset($arr[$classId]['expend'])) {
+                            $arr[$classId]['expend'] = bcadd($amount, $arr[$classId]['expend'], 2);
+                        } else {
+                            $arr[$classId]['expend'] = $amount;
+                        }
+                    }
+                    if ($tkPrice > 0) {
+                        $cgRefundOrderList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
+                        if (!empty($cgRefundOrderList)) {
+                            foreach ($cgRefundOrderList as $cgRefundOrder) {
+                                if ($cgRefundOrder->refundType == 2) {
+                                    //仅退款,这里没有处理,需要进行处理!!!!!!!!!! todo
+                                } else {
+                                    //退货退款前面已经考虑,这里不再处理 OK
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        $cg = floatval($cg);
+        print_r($arr);
+        die;
+
+        //批发开单
+        $pfIncome = 0;
+        $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
+        $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
+        if (!empty($ghsOrderList)) {
+            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+                $actPrice = $ghsOrder['actPrice'] ?? 0;
+                $pfIncome = bcadd($pfIncome, $actPrice, 2);
+            }
+        }
+
+        //零售开单
+        $lsIncome = 0;
+        $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
+        $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
+        foreach ($hdOrderList as $hdKey => $hdOrder) {
+            $actPrice = $hdOrder['mainPay'] ?? 0;
+            $cash = $hdOrder['cash'] ?? 0;
+            $lsIncome = bcadd($actPrice, $lsIncome, 2);
+            $lsIncome = bcadd($lsIncome, $cash, 2);
+        }
+
+    }
+
 }