shish 4 лет назад
Родитель
Сommit
d0fabd3355

+ 1 - 4
app-ghs/controllers/StatController.php

@@ -22,10 +22,7 @@ class StatController extends BaseController
     {
         $get = Yii::$app->request->get();
         $where = [];
-        $where['shopId'] = $this->shopId;
-        if (isset($get['shopId']) && !empty($get['shopId'])) {
-            $where['shopId'] = $get['shopId'];
-        }
+        $where['mainId'] = $this->mainId;
         $searchTime = $get['searchTime'] ?? 'today';
         if (!empty($searchTime)) {
             $startTime = $get['startTime'] ?? '';

+ 95 - 0
app-hd/controllers/StatCgGhsController.php

@@ -0,0 +1,95 @@
+<?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 StatCgGhsController extends BaseController
+{
+
+    //采购列表 shish 20211017
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (isset($get['shopId']) && !empty($get['shopId'])) {
+            $where['shopId'] = $get['shopId'];
+        }
+        $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]);
+    }
+
+}

+ 150 - 82
app-hd/controllers/StatController.php

@@ -2,92 +2,160 @@
 
 namespace hd\controllers;
 
+use biz\stat\classes\StatCgClass;
+use biz\stat\classes\StatRefundClass;
+use biz\stat\classes\StatSaleClass;
+use biz\stat\classes\StatStockInClass;
+use biz\stat\classes\StatStockOutClass;
 use common\components\dateUtil;
 use Yii;
 use common\components\util;
 
 class StatController extends BaseController
 {
-	
-	//统计列表 ssh 2020.1.5
-	public function actionList()
-	{
-		$type = Yii::$app->request->get('type', 1);
-		$incomeStat = [
-			'total' => (185 + 381 + 662 + 443),
-			'list' => [
-				['name' => '2.6', 'num' => 185],
-				['name' => '2.7', 'num' => 381],
-				['name' => '2.8', 'num' => 662],
-				['name' => '2.9', 'num' => 443],
-			],
-		];
-		$visitStat = [
-			'total' => (115 + 341 + 622 + 423),
-			'list' => [
-				['name' => '2.6', 'num' => 115],
-				['name' => '2.7', 'num' => 341],
-				['name' => '2.8', 'num' => 622],
-				['name' => '2.9', 'num' => 423],
-			],
-		];
-		$userStat = [
-			'total' => (185 + 341 + 622 + 423),
-			'list' => [
-				['name' => '2.6', 'num' => 185],
-				['name' => '2.7', 'num' => 341],
-				['name' => '2.8', 'num' => 622],
-				['name' => '2.9', 'num' => 423],
-			],
-		];
-		$fansStat = [
-			'total' => (185 + 241 + 322 + 553),
-			'list' => [
-				['name' => '2.6', 'num' => 185],
-				['name' => '2.7', 'num' => 241],
-				['name' => '2.8', 'num' => 322],
-				['name' => '2.9', 'num' => 553],
-			],
-		];
-		$incomeSourceStat = [
-			'total' => (299 + 366 + 2995),
-			'list' => [
-				['name' => '门店', 'num' => 299],
-				['name' => '微信朋友圈', 'num' => 366],
-				['name' => '美团', 'num' => 2995],
-			],
-		];
-		$categoryStat = [
-			'total' => (552 + 155 + 295 + 365 + 600 + 504),
-			'list' => [
-				['name' => '花束', 'num' => 552],
-				['name' => '花篮', 'num' => 155],
-				['name' => '蝴蝶兰', 'num' => 295],
-				['name' => '绿植', 'num' => 365],
-				['name' => '永生花', 'num' => 600],
-				['name' => '散花', 'num' => 504],
-			],
-		];
-		$useStat = [
-			'total' => (552 + 155 + 295 + 365 + 600 + 504),
-			'list' => [
-				['name' => '年销花', 'num' => 552],
-				['name' => '送爱人', 'num' => 155],
-				['name' => '婚庆', 'num' => 295],
-				['name' => '开业', 'num' => 365],
-				['name' => '送母亲', 'num' => 600],
-				['name' => '生日', 'num' => 504],
-			]
-		];
-		$data = ['incomeStat' => $incomeStat,
-			'visitStat' => $visitStat,
-			'userStat' => $userStat,
-			'fansStat' => $fansStat,
-			'incomeSourceStat' => $incomeSourceStat,
-			'categoryStat' => $categoryStat,
-			'useStat' => $useStat,
-		];
-		util::success($data);
-	}
-	
+
+    //利润表 shish 20210829
+    public function actionProfit()
+    {
+        $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']]];
+        }
+
+        //开单
+        $sale = StatSaleClass::getSum($where);
+
+        //调拨出库
+        $stockOut = StatStockOutClass::getSum($where);
+        //盘盈
+        //$pdAdd = StatPdAddClass::getSum($where);
+
+        //采购入库
+        $cg = StatCgClass::getSum($where);
+        //报损
+        //$wast = StatWastClass::getSum($where);
+        //调拨入库
+        $stockIn = StatStockInClass::getSum($where);
+        //盘亏
+        //$pdSub = StatPdSubClass::getSum($where);
+        //退款
+        $refund = StatRefundClass::getSum($where);
+
+        $in = $sale;
+        $in = bcadd($in, $stockOut, 2);
+        //$in = bcadd($in, $pdAdd, 2);
+        $out = $cg;
+        //$out = bcadd($out, $wast, 2);
+        $out = bcadd($out, $stockIn, 2);
+        //$out = bcadd($out, $pdSub, 2);
+        $out = bcadd($out, $refund, 2);
+        $balance = bcsub($in, $out, 2);
+
+        $out = [
+            'income' => [
+                ['name' => '销售', 'amount' => $sale],
+                ['name' => '调拨出库', 'amount' => $stockOut],
+                //['name' => '盘盈', 'amount' => $pdAdd],
+            ],
+            'expend' => [
+                ['name' => '采购', 'amount' => $cg],
+                //['name' => '报损', 'amount' => $wast],
+                ['name' => '调拨入库', 'amount' => $stockIn],
+                //['name' => '盘亏', 'amount' => $pdSub],
+                ['name' => '退款', 'amount' => $refund],
+            ],
+            'balance' => $balance,
+        ];
+
+        util::success($out);
+
+    }
+
+    //统计列表 ssh 2020.1.5
+    public function actionList()
+    {
+        $type = Yii::$app->request->get('type', 1);
+        $incomeStat = [
+            'total' => (185 + 381 + 662 + 443),
+            'list' => [
+                ['name' => '2.6', 'num' => 185],
+                ['name' => '2.7', 'num' => 381],
+                ['name' => '2.8', 'num' => 662],
+                ['name' => '2.9', 'num' => 443],
+            ],
+        ];
+        $visitStat = [
+            'total' => (115 + 341 + 622 + 423),
+            'list' => [
+                ['name' => '2.6', 'num' => 115],
+                ['name' => '2.7', 'num' => 341],
+                ['name' => '2.8', 'num' => 622],
+                ['name' => '2.9', 'num' => 423],
+            ],
+        ];
+        $userStat = [
+            'total' => (185 + 341 + 622 + 423),
+            'list' => [
+                ['name' => '2.6', 'num' => 185],
+                ['name' => '2.7', 'num' => 341],
+                ['name' => '2.8', 'num' => 622],
+                ['name' => '2.9', 'num' => 423],
+            ],
+        ];
+        $fansStat = [
+            'total' => (185 + 241 + 322 + 553),
+            'list' => [
+                ['name' => '2.6', 'num' => 185],
+                ['name' => '2.7', 'num' => 241],
+                ['name' => '2.8', 'num' => 322],
+                ['name' => '2.9', 'num' => 553],
+            ],
+        ];
+        $incomeSourceStat = [
+            'total' => (299 + 366 + 2995),
+            'list' => [
+                ['name' => '门店', 'num' => 299],
+                ['name' => '微信朋友圈', 'num' => 366],
+                ['name' => '美团', 'num' => 2995],
+            ],
+        ];
+        $categoryStat = [
+            'total' => (552 + 155 + 295 + 365 + 600 + 504),
+            'list' => [
+                ['name' => '花束', 'num' => 552],
+                ['name' => '花篮', 'num' => 155],
+                ['name' => '蝴蝶兰', 'num' => 295],
+                ['name' => '绿植', 'num' => 365],
+                ['name' => '永生花', 'num' => 600],
+                ['name' => '散花', 'num' => 504],
+            ],
+        ];
+        $useStat = [
+            'total' => (552 + 155 + 295 + 365 + 600 + 504),
+            'list' => [
+                ['name' => '年销花', 'num' => 552],
+                ['name' => '送爱人', 'num' => 155],
+                ['name' => '婚庆', 'num' => 295],
+                ['name' => '开业', 'num' => 365],
+                ['name' => '送母亲', 'num' => 600],
+                ['name' => '生日', 'num' => 504],
+            ]
+        ];
+        $data = ['incomeStat' => $incomeStat,
+            'visitStat' => $visitStat,
+            'userStat' => $userStat,
+            'fansStat' => $fansStat,
+            'incomeSourceStat' => $incomeSourceStat,
+            'categoryStat' => $categoryStat,
+            'useStat' => $useStat,
+        ];
+        util::success($data);
+    }
+
 }

+ 64 - 0
app-hd/controllers/StatItemController.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace hd\controllers;
+
+use biz\stat\classes\StatItemClass;
+use bizGhs\product\classes\ProductClass;
+use common\components\arrayUtil;
+use common\components\dateUtil;
+use Yii;
+use common\components\util;
+
+class StatItemController extends BaseController
+{
+
+    //花材销量 shish 20211021
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (isset($get['shopId']) && !empty($get['shopId'])) {
+            $where['shopId'] = $get['shopId'];
+        }
+        $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 = StatItemClass::getAllByCondition($where, null, '*');
+        if (empty($list)) {
+            util::success(['list' => $list]);
+        }
+        $ids = array_column($list, 'itemId');
+        $ids = array_unique(array_filter($ids));
+        $productInfo = ProductClass::getByIds($ids, null, 'id');
+        $stat = [];
+        foreach ($list as $key => $val) {
+            $itemId = $val['itemId'] ?? 0;
+            $idsData[$itemId] = 0;
+            $num = bcsub($val['num'], $val['refundNum'], 2);
+            $amount = bcsub($val['amount'], $val['refundAmount'], 2);
+            $name = $productInfo[$itemId]['name'] ?? '';
+            $py = $productInfo[$itemId]['py'] ?? '';
+            $stat[$itemId]['productId'] = $itemId;
+            $stat[$itemId]['name'] = $name;
+            $stat[$itemId]['py'] = $py;
+            if (isset($stat[$itemId]['num'])) {
+                $stat[$itemId]['num'] = bcadd($stat[$itemId]['num'], $num, 2);
+            } else {
+                $stat[$itemId]['num'] = $num;
+            }
+            if (isset($stat[$itemId]['amount'])) {
+                $stat[$itemId]['amount'] = bcadd($stat[$itemId]['amount'], $amount, 2);
+            } else {
+                $stat[$itemId]['amount'] = $amount;
+            }
+        }
+        $stat = arrayUtil::arraySort($stat, 'num');
+        util::success(['list' => $stat]);
+    }
+
+}

+ 71 - 0
app-hd/controllers/StatKdController.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace hd\controllers;
+
+use biz\stat\classes\StatKdClass;
+use biz\stat\classes\StatRefundClass;
+use common\components\dateUtil;
+use Yii;
+use common\components\util;
+
+class StatKdController extends BaseController
+{
+
+    //开单收入统计 shish 20211017
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (isset($get['shopId']) && !empty($get['shopId'])) {
+            $where['shopId'] = $get['shopId'];
+        }
+        $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']]];
+        }
+        $kdList = StatKdClass::getAllByCondition($where, null, '*');
+
+        $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
+        if (!empty($kdList)) {
+            foreach ($kdList as $key => $item) {
+                $kd['wx'] = bcadd($kd['wx'], $item['wx']);
+                $kd['alipay'] = bcadd($kd['alipay'], $item['alipay']);
+                $kd['balance'] = bcadd($kd['balance'], $item['balance']);
+                $kd['cash'] = bcadd($kd['cash'], $item['cash']);
+                $kd['bank'] = bcadd($kd['bank'], $item['bank']);
+                $kd['debt'] = bcadd($kd['debt'], $item['debt']);
+                $kd['amount'] = bcadd($kd['amount'], $item['amount']);
+            }
+        }
+
+        $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
+        $refundList = StatRefundClass::getAllByCondition($where, null, '*');
+        if (!empty($refundList)) {
+            foreach ($refundList as $key => $item) {
+                $refund['wx'] = bcadd($refund['wx'], $item['wx']);
+                $refund['alipay'] = bcadd($refund['alipay'], $item['alipay']);
+                $refund['balance'] = bcadd($refund['balance'], $item['balance']);
+                $refund['cash'] = bcadd($refund['cash'], $item['cash']);
+                $refund['bank'] = bcadd($refund['bank'], $item['bank']);
+                $refund['debt'] = bcadd($refund['debt'], $item['debt']);
+                $refund['amount'] = bcadd($refund['amount'], $item['amount']);
+            }
+        }
+        $arr = [
+            ['name' => '微信支付', 'kd' => $kd['wx'], 'refund' => $refund['wx']],
+            ['name' => '支付宝', 'kd' => $kd['alipay'], 'refund' => $refund['alipay']],
+            ['name' => '欠账', 'kd' => $kd['debt'], 'refund' => $refund['debt']],
+            ['name' => '余额', 'kd' => $kd['balance'], 'refund' => $refund['balance']],
+            ['name' => '现金', 'kd' => $kd['cash'], 'refund' => $refund['cash']],
+            ['name' => '银行卡', 'kd' => $kd['bank'], 'refund' => $refund['bank']],
+            ['name' => '总计', 'kd' => $kd['amount'], 'refund' => $refund['amount']],
+        ];
+        $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
+        util::success(['list' => $arr, 'income' => $income]);
+    }
+
+}