| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace ghs\controllers;
- use biz\stat\classes\StatKdClass;
- use biz\stat\classes\StatRefundClass;
- use bizGhs\order\classes\OrderClass;
- use bizHd\order\classes\SettleClass;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- use bizHd\order\classes\OrderClass as HdOrderClass;
- use bizGhs\clear\classes\ClearClass;
- class StatKdController extends BaseController
- {
- //各渠道收入 ssh 20220711
- public function actionChannel()
- {
- //批发开单 零售开单 批发结账 零售结账
- $todayDate = date('Y-m-d');
- $todayStartTime = $todayDate . ' 00:00:00';
- $todayEndTime = $todayDate . ' 23:59:59';
- //批发开单
- $where = ['shopId' => $this->shopId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $payWay = $ghsOrder['payWay'] ?? 0;
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- }
- }
- //零售开单
- $hdWhere = ['shopId' => $this->shop['lsShopId'], 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
- $hdWhere['addTime'] = ['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;
- }
- //批发结帐收入
- $clearWhere = ['ghsShopId' => $this->shopId, 'status' => 2];
- $clearWhere['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
- $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
- if (!empty($clearList)) {
- foreach ($clearList as $cKey => $clear) {
- $payWay = $clear['payWay'] ?? 0;
- $actPrice = $clear['actPrice'] ?? 0;
- }
- }
- //零售结账收入
- $settleWhere = ['shopId' => $this->shopId, 'status' => 2];
- $settleWhere['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
- $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
- if (!empty($settleList)) {
- foreach ($settleList as $sKey => $settle) {
- $payWay = $settle['payWay'] ?? 0;
- $actPrice = $settle['actPrice'] ?? 0;
- }
- }
- }
- //开单收入统计 ssh 20211017
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $searchTime = $get['searchTime'] ?? 'today';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $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'], 2);
- $kd['alipay'] = bcadd($kd['alipay'], $item['alipay'], 2);
- $kd['balance'] = bcadd($kd['balance'], $item['balance'], 2);
- $kd['cash'] = bcadd($kd['cash'], $item['cash'], 2);
- $kd['bank'] = bcadd($kd['bank'], $item['bank'], 2);
- $kd['debt'] = bcadd($kd['debt'], $item['debt'], 2);
- $kd['amount'] = bcadd($kd['amount'], $item['amount'], 2);
- }
- }
- $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'], 2);
- $refund['alipay'] = bcadd($refund['alipay'], $item['alipay'], 2);
- $refund['balance'] = bcadd($refund['balance'], $item['balance'], 2);
- $refund['cash'] = bcadd($refund['cash'], $item['cash'], 2);
- $refund['bank'] = bcadd($refund['bank'], $item['bank'], 2);
- $refund['debt'] = bcadd($refund['debt'], $item['debt'], 2);
- $refund['amount'] = bcadd($refund['amount'], $item['amount'], 2);
- }
- }
- $arr = [
- ['name' => '微信支付', 'kd' => floatval($kd['wx']), 'refund' => floatval($refund['wx'])],
- ['name' => '支付宝', 'kd' => floatval($kd['alipay']), 'refund' => floatval($refund['alipay'])],
- ['name' => '欠账', 'kd' => floatval($kd['debt']), 'refund' => floatval($refund['debt'])],
- ['name' => '余额', 'kd' => floatval($kd['balance']), 'refund' => floatval($refund['balance'])],
- ['name' => '现金', 'kd' => floatval($kd['cash']), 'refund' => floatval($refund['cash'])],
- ['name' => '银行卡', 'kd' => floatval($kd['bank']), 'refund' => floatval($refund['bank'])],
- ['name' => '总计', 'kd' => floatval($kd['amount']), 'refund' => floatval($refund['amount'])],
- ];
- $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
- util::success(['list' => $arr, 'income' => $income]);
- }
- }
|