shish 4 years ago
parent
commit
db76d93e50

+ 39 - 23
app-ghs/controllers/ConsoleController.php

@@ -2,12 +2,12 @@
 
 namespace ghs\controllers;
 
-use biz\stat\classes\StatSaleClass;
 use biz\stat\services\StatOutService;
 use bizGhs\clear\classes\ClearClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\order\classes\OrderClass;
-use bizHd\order\classes\OrderClass as HdOrderClass;
+use bizGhs\stat\classes\StatKdClass;
+use bizGhs\stat\classes\StatSaleClass;
 use bizHd\stat\classes\StatVisitClass;
 use common\components\dict;
 use common\components\util;
@@ -53,20 +53,30 @@ class ConsoleController extends BaseController
         util::success(['overview' => $overview]);
     }
 
-    //今日笔数和总金额
+    //系统收入、客服收入、欠款
     public function actionStrokeCount()
     {
+        $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
+        $systemIncome = $incomeList['system']['amount'] ?? 0;
+        $systemCount = $incomeList['system']['num'] ?? 0;
+
+        $debtIncome = $incomeList['debt']['amount'] ?? 0;
+        $debtCount = $incomeList['debt']['num'] ?? 0;
+
+        $kfWxIncome = $incomeList['kfWx']['amount'] ?? 0;
+        $kfWxCount = $incomeList['kfWx']['num'] ?? 0;
+
         util::success([
-            'systemIncome' => 0,
-            'systemCount' => 0,
-            'debtCount' => 0,
-            'debtIncome' => 0,
-            'kfWxCount' => 0,
-            'kfWxIncome' => 0,
+            'systemIncome' => $systemIncome,
+            'systemCount' => $systemCount,
+            'debtCount' => $debtCount,
+            'debtIncome' => $debtIncome,
+            'kfWxCount' => $kfWxCount,
+            'kfWxIncome' => $kfWxIncome,
         ]);
     }
 
-    //概况 ssh 2019.12.19
+    //今日概况 ssh 20220723
     public function actionProfile()
     {
         $get = Yii::$app->request->get();
@@ -80,22 +90,27 @@ class ConsoleController extends BaseController
             }
         }
 
-        //今天销售
-        $sale = StatSaleClass::getByCondition(['mainId' => $this->mainId, 'time' => date('Ymd')]);
-        $todaySale = $sale['amount'] ?? 0;
-        $orderNum = $sale['num'] ?? 0;
-
-        //2021.4.14 lqh 今日支出
-        $outData = StatOutService::getTodayNum($this->mainId);
-        $todayOut = $outData['amount'] ?? '0.00';
+        $mainId = $this->mainId;
+        $respond = StatSaleClass::profile($mainId);
+        $incomeList = $respond['income'] ?? [];
+        $todaySale = 0;
+        if (!empty($incomeList)) {
+            foreach ($incomeList as $item) {
+                $todaySale = bcadd($todaySale, $item['amount'], 2);
+            }
+        }
+        $expendList = $respond['expend'] ?? [];
+        $todayOut = 0;
+        if (!empty($expendList)) {
+            foreach ($expendList as $item) {
+                $todayOut = bcadd($todayOut, $item['amount'], 2);
+            }
+        }
+        $orderNum = $respond['totalOrderNum'] ?? 0;
 
         //访客数
         $visitCustom = StatVisitClass::getVisitNum($this->mainId);
 
-        $todayData = ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
-
-        $incomeStat = [];
-
         $menu = [
             ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
             ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
@@ -111,7 +126,8 @@ class ConsoleController extends BaseController
             ["name" => "支出登记", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
         ];
 
-        util::success(['asset' => $this->main, 'notice' => $notice, 'todayData' => $todayData, 'incomeStat' => $incomeStat, 'menu' => $menu,]);
+        util::success(['asset' => $this->main, 'notice' => $notice,
+            'todayData' => ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom], 'menu' => $menu,]);
     }
 
     //常用初始化

+ 1 - 1
app-ghs/controllers/ProductController.php

@@ -75,7 +75,7 @@ class ProductController extends BaseController
             $pyName = strtolower($py);
             $where['py'] = $pyName;
         }
-        if ($requestType == 'changePrice') {
+        if ($requestType == 'hasStock') {
             //改价只显示库存大于0的
             $where['stock>'] = 0;
         }

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

@@ -2,15 +2,7 @@
 
 namespace ghs\controllers;
 
-use biz\stat\classes\StatCgClass;
-use biz\stat\classes\StatStockInClass;
-use biz\stat\classes\StatStockOutClass;
-use bizGhs\expend\classes\ExpendClass;
-use bizGhs\staff\classes\SalaryClass;
-use bizHd\order\classes\OrderClass as HdOrderClass;
-use bizGhs\order\classes\OrderClass;
-use common\components\dateUtil;
-use common\components\dict;
+use bizGhs\stat\classes\StatSaleClass;
 use Yii;
 use common\components\util;
 
@@ -19,117 +11,12 @@ class StatController extends BaseController
 
     public function actionProfit()
     {
-        //收入:批发开单、零售开单(含门店、美团和微信客服)、出库
-        //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
-
-        $get = Yii::$app->request->get();
-        $where = [];
-        $where['mainId'] = $this->mainId;
-        $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']]];
-        }
-        //出库
-        $stockOut = StatStockOutClass::getSum($where);
-        //采购入库
-        $cg = StatCgClass::getSum($where);
-        //调拨入库
-        $stockIn = StatStockInClass::getSum($where);
-
-        $todayDate = date('Y-m-d');
-        $todayStartTime = $todayDate . ' 00:00:00';
-        $todayEndTime = $todayDate . ' 23:59:59';
-
-        //批发开单
-        $pfIncome = 0;
-        $pfSendCost = 0;
-        $where = ['mainId' => $this->mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
-        $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
-        if (!empty($ghsOrderList)) {
-            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
-                $actPrice = $ghsOrder['actPrice'] ?? 0;
-                $sendCost = $ghsOrder['sendCost'] ?? 0;
-                $pfIncome = bcadd($pfIncome, $actPrice, 2);
-                $pfSendCost = bcadd($pfSendCost, $sendCost, 2);
-            }
-        }
-
-        //零售开单
-        $lsIncome = 0;
-        $lsSendCost = 0;
-        $lsServiceFee = 0;
-        $hdWhere = ['mainId' => $this->mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
-        $hdWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
-        foreach ($hdOrderList as $hdKey => $hdOrder) {
-            $actPrice = $hdOrder['actPrice'] ?? 0;
-            $serviceFee = $hdOrder['serviceFee'] ?? 0;
-            $sendCost = $hdOrder['sendCost'] ?? 0;
-            $lsIncome = bcadd($actPrice, $lsIncome, 2);
-            $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
-            $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
-        }
-
-        $condition = ['mainId' => $this->mainId, 'addTime' => ['between', [$todayStartTime, $todayEndTime]],];
-
-        $salary = 0;
-        $salaryList = SalaryClass::getAllByCondition($condition, null, '*', null, true);
-        if (!empty($salaryList)) {
-            foreach ($salaryList as $item) {
-                $salary = bcadd($salary, $item->amount, 2);
-            }
-        }
-
-        $expendList = ExpendClass::getAllByCondition($condition, null, '*', null, true);
-        $expendTypeMap = dict::getDict('expendTypeMap');
-        $expendAmount = [];
-        if (!empty($expendList)) {
-            foreach ($expendList as $item) {
-                $type = $item->type ?? 0;
-                $amount = $item->amount ?? 0;
-                $name = $expendTypeMap[$type] ?? '暂无';
-                if (isset($expendAmount[$type]['amount']) == false) {
-                    $expendAmount[$type]['amount'] = 0;
-                }
-                $expendAmount[$type]['name'] = $name;
-                $expendAmount[$type]['amount'] = floatval(bcadd($expendAmount[$type]['amount'], $amount, 2));
-            }
-        }
-
-        $income = [
-            ['name' => '批发销售', 'amount' => floatval($pfIncome)],
-            ['name' => '零售销售', 'amount' => floatval($lsIncome)],
-            ['name' => '调拨出库', 'amount' => floatval($stockOut)],
-        ];
-        $expend = [
-            ['name' => '批发运费', 'amount' => floatval($pfSendCost)],
-            ['name' => '零售运费', 'amount' => floatval($lsSendCost)],
-            ['name' => '零售服务费', 'amount' => floatval($lsServiceFee)],
-            ['name' => '采购', 'amount' => floatval($cg)],
-            ['name' => '调拨入库', 'amount' => floatval($stockIn)],
-            ['name' => '员工工资', 'amount' => floatval($salary)],
-        ];
-        if (!empty($expendAmount)) {
-            foreach ($expendAmount as $it) {
-                $expend[] = $it;
-            }
-        }
-        $balance = 0;
-        foreach ($income as $it) {
-            $amount = $it['amount'] ?? 0;
-            $balance = bcadd($amount, $balance, 2);
-        }
-        foreach ($expend as $it) {
-            $amount = $it['amount'] ?? 0;
-            $balance = bcsub($balance, $amount, 2);
-        }
-
+        $mainId = $this->mainId;
+        $respond = StatSaleClass::profile($mainId);
+        $income = $respond['income'] ?? 0;
+        $expend = $respond['expend'] ?? 0;
+        $balance = $respond['balance'] ?? 0;
         util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]);
-
     }
 
     //统计列表 ssh 2020.1.5

+ 2 - 369
app-ghs/controllers/StatKdController.php

@@ -2,13 +2,8 @@
 
 namespace ghs\controllers;
 
-use biz\shop\classes\ShopAdminClass;
-use bizGhs\order\classes\OrderClass;
-use bizHd\order\classes\SettleClass;
-use common\components\dict;
+use bizGhs\stat\classes\StatKdClass;
 use common\components\util;
-use bizHd\order\classes\OrderClass as HdOrderClass;
-use bizGhs\clear\classes\ClearClass;
 
 class StatKdController extends BaseController
 {
@@ -16,369 +11,7 @@ class StatKdController extends BaseController
     //各渠道收入 ssh 20220711
     public function actionProfile()
     {
-        //批发开单 pf 零售开单 ls 批发结账 pfJz 零售尾款 lsWk
-
-        $todayDate = date('Y-m-d');
-        $todayStartTime = $todayDate . ' 00:00:00';
-        $todayEndTime = $todayDate . ' 23:59:59';
-        $staffList = ShopAdminClass::getAllByCondition(['mainId' => $this->mainId], null, '*', 'id', true);
-        $kf = [];
-        if (!empty($staffList)) {
-            foreach ($staffList as $staff) {
-                $name = $staff->name ?? '';
-                $staffId = $staff->id ?? 0;
-                $kf[$staffId] = ['name' => $name, 'key' => $staffId, 'num' => 0, 'amount' => 0];
-            }
-        }
-
-        $incomeList = [
-            //系统收入
-            'system' => [
-                'amount' => 0,
-                'num' => 0,
-                'name' => '系统收入',
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-            'kfWx' => [
-                'amount' => 0,
-                'num' => 0,
-                'name' => '客服微信',
-                'class' => $kf,
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                ]
-            ],
-            'debt' => [
-                'amount' => 0,
-                'num' => 0,
-                'name' => '欠款',
-                'category' => [
-                    'pf' => ['name' => '批发欠款', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售欠款', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-            'cash' => [
-                'amount' => 0,
-                'name' => '现金',
-                'num' => 0,
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-            'aliPay' => [
-                'amount' => 0,
-                'num' => 0,
-                'name' => '支付宝',
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-            'bankCard' => [
-                'amount' => 0,
-                'name' => '银行卡',
-                'num' => 0,
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-            'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'],
-            'other' => [
-                'amount' => 0,
-                'num' => 0,
-                'name' => '其它',
-                'category' => [
-                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
-                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
-                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
-                ],
-            ],
-        ];
-
-        //批发开单
-        $where = ['mainId' => $this->mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
-        $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
-        if (!empty($ghsOrderList)) {
-            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
-                $payWay = $ghsOrder['payWay'] ?? 0;
-                $actPrice = $ghsOrder['actPrice'] ?? 0;
-                $shopAdminId = $ghsOrder['shopAdminId'] ?? 0;
-                $debtPrice = $ghsOrder['debtPrice'] ?? 0;
-                $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not');
-                if ($debtPrice > 0) {
-                    //不管是否结清,只要$debtPrice > 0,说明曾经是欠款单
-                    $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $debtPrice, 2);
-                    $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
-                    $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $debtPrice, 2);
-                    $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1);
-                } else {
-                    if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-                        //使用在线支付
-                        $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
-                        $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
-                        $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
-                        $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
-                    } else {
-                        //使用非在线支付
-                        switch ($payWay) {
-                            case dict::getDict('payWay', 'wxPay'):
-                                //客服微信总共收了多少笔多少钱
-                                $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
-                                $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
-                                //批发开单、零售开单、批发结账、零售尾款各收了多少现金
-                                $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2);
-                                $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1);
-                                //客1 客2 客3各收了多少钱
-                                if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
-                                    $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
-                                    $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
-                                }
-                                break;
-                            case dict::getDict('payWay', 'alipay'):
-                                $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                                $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                                $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2);
-                                $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1);
-                                break;
-                            case dict::getDict('payWay', 'cash'):
-                                $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
-                                $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
-                                $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2);
-                                $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1);
-                                break;
-                            case dict::getDict('payWay', 'bankCard'):
-                                $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                                $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                                $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2);
-                                $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1);
-                                break;
-                            case dict::getDict('payWay', 'unknown'):
-                                $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                                $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                                $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2);
-                                $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1);
-                                break;
-                            default:
-                        }
-                    }
-                }
-            }
-        }
-
-        //零售开单
-        $hdWhere = ['mainId' => $this->mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
-        $hdWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
-        foreach ($hdOrderList as $hdKey => $hdOrder) {
-            $payWay = $hdOrder['payWay'] ?? 0;
-            $mainPay = $hdOrder['mainPay'] ?? 0;
-            $cash = $hdOrder['cash'] ?? 0;
-            $actPrice = $hdOrder['actPrice'] ?? 0;
-            $shopAdminId = $hdOrder['shopAdminId'] ?? 0;
-            $debtPrice = $hdOrder['debtPrice'] ?? 0;
-            $onlinePay = $hdOrder['onlinePay'] ?? 0;
-            if ($debtPrice > 0) {
-                //不管是否结清,只要$debtPrice > 0,说明曾经是欠款单
-                $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $debtPrice, 2);
-                $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
-                $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $debtPrice, 2);
-                $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1);
-            } else {
-                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-                    //使用在线支付
-                    $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2);
-                    $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
-                    $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2);
-                    $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1);
-                    if ($cash > 0) {
-                        $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2);
-                        $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
-                        $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2);
-                        $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
-                    }
-                } else {
-                    //使用非在线支付
-                    switch ($payWay) {
-                        case dict::getDict('payWay', 'wxPay'):
-                            //客服微信总共收了多少笔多少钱
-                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
-                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
-                            $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1);
-                            //客1 客2 客3各收了多少钱
-                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
-                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
-                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
-                            }
-                            break;
-                        case dict::getDict('payWay', 'alipay'):
-                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'cash'):
-                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
-                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
-                            $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $actPrice, 2);
-                            $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'bankCard'):
-                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'unknown'):
-                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $actPrice, 2);
-                            $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1);
-                            break;
-                        default:
-                    }
-                }
-            }
-        }
-
-        //批发结帐收入
-        $clearWhere = ['ghsShopId' => $this->shopId, 'status' => 2];
-        $clearWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
-        if (!empty($clearList)) {
-            foreach ($clearList as $cKey => $clear) {
-                $payWay = $clear['payWay'] ?? 0;
-                $actPrice = $clear['actPrice'] ?? 0;
-                $onlinePay = $clear['onlinePay'] ?? 0;
-                $shopAdminId = $clear['ghsShopAdminId'] ?? 0;
-                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-                    $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
-                    $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
-                    $incomeList['system']['category']['pfJz']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
-                    $incomeList['system']['category']['pfJz']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
-                } else {
-                    //使用非在线支付
-                    switch ($payWay) {
-                        case dict::getDict('payWay', 'wxPay'):
-                            //客服微信总共收了多少笔多少钱
-                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
-                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
-                            $incomeList['kfWx']['category']['pfJz']['amount'] = bcadd($incomeList['kfWx']['category']['pfJz']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['category']['pfJz']['num'] = bcadd($incomeList['kfWx']['category']['pfJz']['num'], 1);
-                            //客1 客2 客3各收了多少钱
-                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
-                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
-                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
-                            }
-                            break;
-                        case dict::getDict('payWay', 'alipay'):
-                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['aliPay']['category']['pfJz']['amount'] = bcadd($incomeList['aliPay']['category']['pfJz']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['category']['pfJz']['num'] = bcadd($incomeList['aliPay']['category']['pfJz']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'cash'):
-                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
-                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
-                            $incomeList['cash']['category']['pfJz']['amount'] = bcadd($incomeList['cash']['category']['pfJz']['amount'], $actPrice, 2);
-                            $incomeList['cash']['category']['pfJz']['num'] = bcadd($incomeList['cash']['category']['pfJz']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'bankCard'):
-                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['bankCard']['category']['pfJz']['amount'] = bcadd($incomeList['bankCard']['category']['pfJz']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['category']['pfJz']['num'] = bcadd($incomeList['bankCard']['category']['pfJz']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'unknown'):
-                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['other']['category']['pfJz']['amount'] = bcadd($incomeList['other']['category']['pfJz']['amount'], $actPrice, 2);
-                            $incomeList['other']['category']['pfJz']['num'] = bcadd($incomeList['other']['category']['pfJz']['num'], 1);
-                            break;
-                        default:
-                    }
-                }
-            }
-        }
-
-        //零售尾款收入
-        $settleWhere = ['shopId' => $this->shopId, 'status' => 2];
-        $settleWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
-        $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
-        if (!empty($settleList)) {
-            foreach ($settleList as $sKey => $settle) {
-                $payWay = $settle['payWay'] ?? 0;
-                $actPrice = $settle['actPrice'] ?? 0;
-                $shopAdminId = $settle['hdShopAdminId'] ?? 0;
-                $onlinePay = $settle['onlinePay'] ?? 0;
-                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-
-                } else {
-                    //使用非在线支付
-                    switch ($payWay) {
-                        case dict::getDict('payWay', 'wxPay'):
-                            //客服微信总共收了多少笔多少钱
-                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
-                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
-                            $incomeList['kfWx']['category']['lsWk']['amount'] = bcadd($incomeList['kfWx']['category']['lsWk']['amount'], $actPrice, 2);
-                            $incomeList['kfWx']['category']['lsWk']['num'] = bcadd($incomeList['kfWx']['category']['lsWk']['num'], 1);
-                            //客1 客2 客3各收了多少钱
-                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
-                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
-                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
-                            }
-                            break;
-                        case dict::getDict('payWay', 'alipay'):
-                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['aliPay']['category']['lsWk']['amount'] = bcadd($incomeList['aliPay']['category']['lsWk']['amount'], $actPrice, 2);
-                            $incomeList['aliPay']['category']['lsWk']['num'] = bcadd($incomeList['aliPay']['category']['lsWk']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'cash'):
-                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
-                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
-                            $incomeList['cash']['category']['lsWk']['amount'] = bcadd($incomeList['cash']['category']['lsWk']['amount'], $actPrice, 2);
-                            $incomeList['cash']['category']['lsWk']['num'] = bcadd($incomeList['cash']['category']['lsWk']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'bankCard'):
-                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['bankCard']['category']['lsWk']['amount'] = bcadd($incomeList['bankCard']['category']['lsWk']['amount'], $actPrice, 2);
-                            $incomeList['bankCard']['category']['lsWk']['num'] = bcadd($incomeList['bankCard']['category']['lsWk']['num'], 1);
-                            break;
-                        case dict::getDict('payWay', 'unknown'):
-                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
-                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
-                            $incomeList['other']['category']['lsWk']['amount'] = bcadd($incomeList['other']['category']['lsWk']['amount'], $actPrice, 2);
-                            $incomeList['other']['category']['lsWk']['num'] = bcadd($incomeList['other']['category']['lsWk']['num'], 1);
-                            break;
-                        default:
-                    }
-                }
-
-            }
-        }
+        $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
         util::success(['list' => $incomeList]);
     }
 

+ 393 - 0
biz-ghs/stat/classes/StatKdClass.php

@@ -0,0 +1,393 @@
+<?php
+
+namespace bizGhs\stat\classes;
+
+use biz\shop\classes\ShopAdminClass;
+use bizGhs\order\classes\OrderClass;
+use bizHd\order\classes\SettleClass;
+use common\components\dict;
+use bizHd\order\classes\OrderClass as HdOrderClass;
+use bizGhs\clear\classes\ClearClass;
+use bizGhs\base\classes\BaseClass;
+
+class StatKdClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\stat\models\StatKd';
+
+    //当天各渠道收入 ssh 20220723
+    public static function eachChannelIncome($mainId, $shop)
+    {
+        $ghsShopId = $shop->id ?? 0;
+        $lsShopId = $shop->lsShopId ?? 0;
+
+        //批发开单 pf 零售开单 ls 批发结账 pfJz 零售尾款 lsWk
+
+        $todayDate = date('Y-m-d');
+        $todayStartTime = $todayDate . ' 00:00:00';
+        $todayEndTime = $todayDate . ' 23:59:59';
+        $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id', true);
+        $kf = [];
+        if (!empty($staffList)) {
+            foreach ($staffList as $staff) {
+                $name = $staff->name ?? '';
+                $staffId = $staff->id ?? 0;
+                $kf[$staffId] = ['name' => $name, 'key' => $staffId, 'num' => 0, 'amount' => 0];
+            }
+        }
+
+        $incomeList = [
+            //系统收入
+            'system' => [
+                'amount' => 0,
+                'num' => 0,
+                'name' => '系统收入',
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+            'kfWx' => [
+                'amount' => 0,
+                'num' => 0,
+                'name' => '客服微信',
+                'class' => $kf,
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                ]
+            ],
+            'debt' => [
+                'amount' => 0,
+                'num' => 0,
+                'name' => '欠款',
+                'category' => [
+                    'pf' => ['name' => '批发欠款', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售欠款', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+            'cash' => [
+                'amount' => 0,
+                'name' => '现金',
+                'num' => 0,
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+            'aliPay' => [
+                'amount' => 0,
+                'num' => 0,
+                'name' => '支付宝',
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+            'bankCard' => [
+                'amount' => 0,
+                'name' => '银行卡',
+                'num' => 0,
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+            'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'],
+            'other' => [
+                'amount' => 0,
+                'num' => 0,
+                'name' => '其它',
+                'category' => [
+                    'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
+                    'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
+                    'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                    'lsWk' => ['name' => '零售尾款', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
+                ],
+            ],
+        ];
+
+        //批发开单
+        $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
+        $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
+        if (!empty($ghsOrderList)) {
+            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+                $payWay = $ghsOrder['payWay'] ?? 0;
+                $actPrice = $ghsOrder['actPrice'] ?? 0;
+                $shopAdminId = $ghsOrder['shopAdminId'] ?? 0;
+                $debtPrice = $ghsOrder['debtPrice'] ?? 0;
+                $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not');
+                if ($debtPrice > 0) {
+                    //不管是否结清,只要$debtPrice > 0,说明曾经是欠款单
+                    $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $debtPrice, 2);
+                    $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
+                    $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $debtPrice, 2);
+                    $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1);
+                } else {
+                    if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
+                        //使用在线支付
+                        $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
+                        $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
+                        $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
+                        $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
+                    } else {
+                        //使用非在线支付
+                        switch ($payWay) {
+                            case dict::getDict('payWay', 'wxPay'):
+                                //客服微信总共收了多少笔多少钱
+                                $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
+                                $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
+                                //批发开单、零售开单、批发结账、零售尾款各收了多少现金
+                                $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2);
+                                $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1);
+                                //客1 客2 客3各收了多少钱
+                                if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
+                                    $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
+                                    $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
+                                }
+                                break;
+                            case dict::getDict('payWay', 'alipay'):
+                                $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                                $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                                $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2);
+                                $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1);
+                                break;
+                            case dict::getDict('payWay', 'cash'):
+                                $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
+                                $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
+                                $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2);
+                                $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1);
+                                break;
+                            case dict::getDict('payWay', 'bankCard'):
+                                $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                                $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                                $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2);
+                                $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1);
+                                break;
+                            case dict::getDict('payWay', 'unknown'):
+                                $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                                $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                                $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2);
+                                $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1);
+                                break;
+                            default:
+                        }
+                    }
+                }
+            }
+        }
+
+        //零售开单
+        $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
+        $hdWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
+        foreach ($hdOrderList as $hdKey => $hdOrder) {
+            $payWay = $hdOrder['payWay'] ?? 0;
+            $mainPay = $hdOrder['mainPay'] ?? 0;
+            $cash = $hdOrder['cash'] ?? 0;
+            $actPrice = $hdOrder['actPrice'] ?? 0;
+            $shopAdminId = $hdOrder['shopAdminId'] ?? 0;
+            $debtPrice = $hdOrder['debtPrice'] ?? 0;
+            $onlinePay = $hdOrder['onlinePay'] ?? 0;
+            if ($debtPrice > 0) {
+                //不管是否结清,只要$debtPrice > 0,说明曾经是欠款单
+                $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $debtPrice, 2);
+                $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
+                $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $debtPrice, 2);
+                $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1);
+            } else {
+                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
+                    //使用在线支付
+                    $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2);
+                    $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
+                    $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2);
+                    $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1);
+                    if ($cash > 0) {
+                        $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2);
+                        $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
+                        $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2);
+                        $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
+                    }
+                } else {
+                    //使用非在线支付
+                    switch ($payWay) {
+                        case dict::getDict('payWay', 'wxPay'):
+                            //客服微信总共收了多少笔多少钱
+                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
+                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
+                            $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1);
+                            //客1 客2 客3各收了多少钱
+                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
+                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
+                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
+                            }
+                            break;
+                        case dict::getDict('payWay', 'alipay'):
+                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'cash'):
+                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
+                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
+                            $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $actPrice, 2);
+                            $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'bankCard'):
+                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'unknown'):
+                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $actPrice, 2);
+                            $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1);
+                            break;
+                        default:
+                    }
+                }
+            }
+        }
+
+        //批发结帐收入
+        $clearWhere = ['ghsShopId' => $ghsShopId, 'status' => 2];
+        $clearWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
+        if (!empty($clearList)) {
+            foreach ($clearList as $cKey => $clear) {
+                $payWay = $clear['payWay'] ?? 0;
+                $actPrice = $clear['actPrice'] ?? 0;
+                $onlinePay = $clear['onlinePay'] ?? 0;
+                $shopAdminId = $clear['ghsShopAdminId'] ?? 0;
+                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
+                    $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
+                    $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
+                    $incomeList['system']['category']['pfJz']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
+                    $incomeList['system']['category']['pfJz']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
+                } else {
+                    //使用非在线支付
+                    switch ($payWay) {
+                        case dict::getDict('payWay', 'wxPay'):
+                            //客服微信总共收了多少笔多少钱
+                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
+                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
+                            $incomeList['kfWx']['category']['pfJz']['amount'] = bcadd($incomeList['kfWx']['category']['pfJz']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['category']['pfJz']['num'] = bcadd($incomeList['kfWx']['category']['pfJz']['num'], 1);
+                            //客1 客2 客3各收了多少钱
+                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
+                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
+                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
+                            }
+                            break;
+                        case dict::getDict('payWay', 'alipay'):
+                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['aliPay']['category']['pfJz']['amount'] = bcadd($incomeList['aliPay']['category']['pfJz']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['category']['pfJz']['num'] = bcadd($incomeList['aliPay']['category']['pfJz']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'cash'):
+                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
+                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
+                            $incomeList['cash']['category']['pfJz']['amount'] = bcadd($incomeList['cash']['category']['pfJz']['amount'], $actPrice, 2);
+                            $incomeList['cash']['category']['pfJz']['num'] = bcadd($incomeList['cash']['category']['pfJz']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'bankCard'):
+                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['bankCard']['category']['pfJz']['amount'] = bcadd($incomeList['bankCard']['category']['pfJz']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['category']['pfJz']['num'] = bcadd($incomeList['bankCard']['category']['pfJz']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'unknown'):
+                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['other']['category']['pfJz']['amount'] = bcadd($incomeList['other']['category']['pfJz']['amount'], $actPrice, 2);
+                            $incomeList['other']['category']['pfJz']['num'] = bcadd($incomeList['other']['category']['pfJz']['num'], 1);
+                            break;
+                        default:
+                    }
+                }
+            }
+        }
+
+        //零售尾款收入
+        $settleWhere = ['shopId' => $lsShopId, 'status' => 2];
+        $settleWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
+        if (!empty($settleList)) {
+            foreach ($settleList as $sKey => $settle) {
+                $payWay = $settle['payWay'] ?? 0;
+                $actPrice = $settle['actPrice'] ?? 0;
+                $shopAdminId = $settle['hdShopAdminId'] ?? 0;
+                $onlinePay = $settle['onlinePay'] ?? 0;
+                if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
+
+                } else {
+                    //使用非在线支付
+                    switch ($payWay) {
+                        case dict::getDict('payWay', 'wxPay'):
+                            //客服微信总共收了多少笔多少钱
+                            $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
+                            //批发开单、零售开单、批发结账、零售尾款各收了多少现金
+                            $incomeList['kfWx']['category']['lsWk']['amount'] = bcadd($incomeList['kfWx']['category']['lsWk']['amount'], $actPrice, 2);
+                            $incomeList['kfWx']['category']['lsWk']['num'] = bcadd($incomeList['kfWx']['category']['lsWk']['num'], 1);
+                            //客1 客2 客3各收了多少钱
+                            if (isset($incomeList['kfWx']['num']['class'][$shopAdminId])) {
+                                $incomeList['kfWx']['class'][$shopAdminId]['amount'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['amount'], $actPrice, 2);
+                                $incomeList['kfWx']['class'][$shopAdminId]['num'] = bcadd($incomeList['kfWx']['num']['category'][$shopAdminId]['num'], 1);
+                            }
+                            break;
+                        case dict::getDict('payWay', 'alipay'):
+                            $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['aliPay']['category']['lsWk']['amount'] = bcadd($incomeList['aliPay']['category']['lsWk']['amount'], $actPrice, 2);
+                            $incomeList['aliPay']['category']['lsWk']['num'] = bcadd($incomeList['aliPay']['category']['lsWk']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'cash'):
+                            $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
+                            $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
+                            $incomeList['cash']['category']['lsWk']['amount'] = bcadd($incomeList['cash']['category']['lsWk']['amount'], $actPrice, 2);
+                            $incomeList['cash']['category']['lsWk']['num'] = bcadd($incomeList['cash']['category']['lsWk']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'bankCard'):
+                            $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['bankCard']['category']['lsWk']['amount'] = bcadd($incomeList['bankCard']['category']['lsWk']['amount'], $actPrice, 2);
+                            $incomeList['bankCard']['category']['lsWk']['num'] = bcadd($incomeList['bankCard']['category']['lsWk']['num'], 1);
+                            break;
+                        case dict::getDict('payWay', 'unknown'):
+                            $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
+                            $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
+                            $incomeList['other']['category']['lsWk']['amount'] = bcadd($incomeList['other']['category']['lsWk']['amount'], $actPrice, 2);
+                            $incomeList['other']['category']['lsWk']['num'] = bcadd($incomeList['other']['category']['lsWk']['num'], 1);
+                            break;
+                        default:
+                    }
+                }
+
+            }
+        }
+
+
+        return $incomeList;
+
+    }
+
+}

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

@@ -0,0 +1,140 @@
+<?php
+
+namespace bizGhs\stat\classes;
+
+use biz\stat\classes\StatCgClass;
+use biz\stat\classes\StatStockInClass;
+use biz\stat\classes\StatStockOutClass;
+use bizGhs\expend\classes\ExpendClass;
+use bizGhs\staff\classes\SalaryClass;
+use bizHd\order\classes\OrderClass as HdOrderClass;
+use bizGhs\order\classes\OrderClass;
+use common\components\dateUtil;
+use common\components\dict;
+use Yii;
+use bizGhs\base\classes\BaseClass;
+
+class StatSaleClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\stat\models\StatSale';
+
+    public static function profile($mainId)
+    {
+        //收入:批发开单、零售开单(含门店、美团和微信客服)、出库
+        //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
+
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $mainId;
+        $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']]];
+        }
+        //出库
+        $stockOut = StatStockOutClass::getSum($where);
+        //采购入库
+        $cg = StatCgClass::getSum($where);
+        //调拨入库
+        $stockIn = StatStockInClass::getSum($where);
+
+        $totalOrderNum = 0;
+
+        $todayDate = date('Y-m-d');
+        $todayStartTime = $todayDate . ' 00:00:00';
+        $todayEndTime = $todayDate . ' 23:59:59';
+
+        //批发开单
+        $pfIncome = 0;
+        $pfSendCost = 0;
+        $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
+        $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
+        if (!empty($ghsOrderList)) {
+            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+                $actPrice = $ghsOrder['actPrice'] ?? 0;
+                $sendCost = $ghsOrder['sendCost'] ?? 0;
+                $pfIncome = bcadd($pfIncome, $actPrice, 2);
+                $pfSendCost = bcadd($pfSendCost, $sendCost, 2);
+                $totalOrderNum++;
+            }
+        }
+
+        //零售开单
+        $lsIncome = 0;
+        $lsSendCost = 0;
+        $lsServiceFee = 0;
+        $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
+        $hdWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
+        $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
+        foreach ($hdOrderList as $hdKey => $hdOrder) {
+            $actPrice = $hdOrder['actPrice'] ?? 0;
+            $serviceFee = $hdOrder['serviceFee'] ?? 0;
+            $sendCost = $hdOrder['sendCost'] ?? 0;
+            $lsIncome = bcadd($actPrice, $lsIncome, 2);
+            $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
+            $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
+            $totalOrderNum++;
+        }
+
+        $condition = ['mainId' => $mainId, 'addTime' => ['between', [$todayStartTime, $todayEndTime]],];
+
+        $salary = 0;
+        $salaryList = SalaryClass::getAllByCondition($condition, null, '*', null, true);
+        if (!empty($salaryList)) {
+            foreach ($salaryList as $item) {
+                $salary = bcadd($salary, $item->amount, 2);
+            }
+        }
+
+        $expendList = ExpendClass::getAllByCondition($condition, null, '*', null, true);
+        $expendTypeMap = dict::getDict('expendTypeMap');
+        $expendAmount = [];
+        if (!empty($expendList)) {
+            foreach ($expendList as $item) {
+                $type = $item->type ?? 0;
+                $amount = $item->amount ?? 0;
+                $name = $expendTypeMap[$type] ?? '暂无';
+                if (isset($expendAmount[$type]['amount']) == false) {
+                    $expendAmount[$type]['amount'] = 0;
+                }
+                $expendAmount[$type]['name'] = $name;
+                $expendAmount[$type]['amount'] = floatval(bcadd($expendAmount[$type]['amount'], $amount, 2));
+            }
+        }
+
+        $income = [
+            ['name' => '批发销售', 'amount' => floatval($pfIncome)],
+            ['name' => '零售销售', 'amount' => floatval($lsIncome)],
+            ['name' => '调拨出库', 'amount' => floatval($stockOut)],
+        ];
+        $expend = [
+            ['name' => '批发运费', 'amount' => floatval($pfSendCost)],
+            ['name' => '零售运费', 'amount' => floatval($lsSendCost)],
+            ['name' => '零售服务费', 'amount' => floatval($lsServiceFee)],
+            ['name' => '采购', 'amount' => floatval($cg)],
+            ['name' => '调拨入库', 'amount' => floatval($stockIn)],
+            ['name' => '员工工资', 'amount' => floatval($salary)],
+        ];
+        if (!empty($expendAmount)) {
+            foreach ($expendAmount as $it) {
+                $expend[] = $it;
+            }
+        }
+        $balance = 0;
+        foreach ($income as $it) {
+            $amount = $it['amount'] ?? 0;
+            $balance = bcadd($amount, $balance, 2);
+        }
+        foreach ($expend as $it) {
+            $amount = $it['amount'] ?? 0;
+            $balance = bcsub($balance, $amount, 2);
+        }
+
+        return ['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'totalOrderNum' => $totalOrderNum];
+    }
+
+}

+ 15 - 0
biz-ghs/stat/models/StatKd.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizGhs\stat\models;
+
+use bizGhs\base\models\Base;
+
+class StatKd extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhStatKd';
+    }
+
+}

+ 15 - 0
biz-ghs/stat/models/StatSale.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizGhs\stat\models;
+
+use bizGhs\base\models\Base;
+
+class StatSale extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhStatSale';
+    }
+
+}