StatKdController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatKdClass;
  4. use biz\stat\classes\StatRefundClass;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\order\classes\SettleClass;
  7. use common\components\dateUtil;
  8. use Yii;
  9. use common\components\util;
  10. use bizHd\order\classes\OrderClass as HdOrderClass;
  11. use bizGhs\clear\classes\ClearClass;
  12. class StatKdController extends BaseController
  13. {
  14. //各渠道收入 ssh 20220711
  15. public function actionChannel()
  16. {
  17. //批发开单 零售开单 批发结账 零售结账
  18. $todayDate = date('Y-m-d');
  19. $todayStartTime = $todayDate . ' 00:00:00';
  20. $todayEndTime = $todayDate . ' 23:59:59';
  21. //批发开单
  22. $where = ['shopId' => $this->shopId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  23. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  24. $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
  25. if (!empty($ghsOrderList)) {
  26. foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
  27. $payWay = $ghsOrder['payWay'] ?? 0;
  28. $actPrice = $ghsOrder['actPrice'] ?? 0;
  29. }
  30. }
  31. //零售开单
  32. $hdWhere = ['shopId' => $this->shop['lsShopId'], 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  33. $hdWhere['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  34. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  35. foreach ($hdOrderList as $hdKey => $hdOrder) {
  36. $payWay = $hdOrder['payWay'] ?? 0;
  37. $mainPay = $hdOrder['mainPay'] ?? 0;
  38. $cash = $hdOrder['cash'] ?? 0;
  39. }
  40. //批发结帐收入
  41. $clearWhere = ['ghsShopId' => $this->shopId, 'status' => 2];
  42. $clearWhere['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  43. $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
  44. if (!empty($clearList)) {
  45. foreach ($clearList as $cKey => $clear) {
  46. $payWay = $clear['payWay'] ?? 0;
  47. $actPrice = $clear['actPrice'] ?? 0;
  48. }
  49. }
  50. //零售结账收入
  51. $settleWhere = ['shopId' => $this->shopId, 'status' => 2];
  52. $settleWhere['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  53. $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
  54. if (!empty($settleList)) {
  55. foreach ($settleList as $sKey => $settle) {
  56. $payWay = $settle['payWay'] ?? 0;
  57. $actPrice = $settle['actPrice'] ?? 0;
  58. }
  59. }
  60. }
  61. //开单收入统计 ssh 20211017
  62. public function actionProfile()
  63. {
  64. $get = Yii::$app->request->get();
  65. $where = [];
  66. $where['mainId'] = $this->mainId;
  67. $searchTime = $get['searchTime'] ?? 'today';
  68. if (!empty($searchTime)) {
  69. $startTime = $get['startTime'] ?? '';
  70. $endTime = $get['endTime'] ?? '';
  71. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  72. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  73. }
  74. $kdList = StatKdClass::getAllByCondition($where, null, '*');
  75. $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  76. if (!empty($kdList)) {
  77. foreach ($kdList as $key => $item) {
  78. $kd['wx'] = bcadd($kd['wx'], $item['wx'], 2);
  79. $kd['alipay'] = bcadd($kd['alipay'], $item['alipay'], 2);
  80. $kd['balance'] = bcadd($kd['balance'], $item['balance'], 2);
  81. $kd['cash'] = bcadd($kd['cash'], $item['cash'], 2);
  82. $kd['bank'] = bcadd($kd['bank'], $item['bank'], 2);
  83. $kd['debt'] = bcadd($kd['debt'], $item['debt'], 2);
  84. $kd['amount'] = bcadd($kd['amount'], $item['amount'], 2);
  85. }
  86. }
  87. $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  88. $refundList = StatRefundClass::getAllByCondition($where, null, '*');
  89. if (!empty($refundList)) {
  90. foreach ($refundList as $key => $item) {
  91. $refund['wx'] = bcadd($refund['wx'], $item['wx'], 2);
  92. $refund['alipay'] = bcadd($refund['alipay'], $item['alipay'], 2);
  93. $refund['balance'] = bcadd($refund['balance'], $item['balance'], 2);
  94. $refund['cash'] = bcadd($refund['cash'], $item['cash'], 2);
  95. $refund['bank'] = bcadd($refund['bank'], $item['bank'], 2);
  96. $refund['debt'] = bcadd($refund['debt'], $item['debt'], 2);
  97. $refund['amount'] = bcadd($refund['amount'], $item['amount'], 2);
  98. }
  99. }
  100. $arr = [
  101. ['name' => '微信支付', 'kd' => floatval($kd['wx']), 'refund' => floatval($refund['wx'])],
  102. ['name' => '支付宝', 'kd' => floatval($kd['alipay']), 'refund' => floatval($refund['alipay'])],
  103. ['name' => '欠账', 'kd' => floatval($kd['debt']), 'refund' => floatval($refund['debt'])],
  104. ['name' => '余额', 'kd' => floatval($kd['balance']), 'refund' => floatval($refund['balance'])],
  105. ['name' => '现金', 'kd' => floatval($kd['cash']), 'refund' => floatval($refund['cash'])],
  106. ['name' => '银行卡', 'kd' => floatval($kd['bank']), 'refund' => floatval($refund['bank'])],
  107. ['name' => '总计', 'kd' => floatval($kd['amount']), 'refund' => floatval($refund['amount'])],
  108. ];
  109. $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
  110. util::success(['list' => $arr, 'income' => $income]);
  111. }
  112. }