StatKdController.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace hd\controllers;
  3. use biz\stat\classes\StatKdClass;
  4. use biz\stat\classes\StatRefundClass;
  5. use common\components\dateUtil;
  6. use Yii;
  7. use common\components\util;
  8. class StatKdController extends BaseController
  9. {
  10. //开单收入统计 ssh 20211017
  11. public function actionProfile()
  12. {
  13. $get = Yii::$app->request->get();
  14. $where = [];
  15. $where['shopId'] = $this->shopId;
  16. if (isset($get['shopId']) && !empty($get['shopId'])) {
  17. $where['shopId'] = $get['shopId'];
  18. }
  19. $searchTime = $get['searchTime'] ?? 'today';
  20. if (!empty($searchTime)) {
  21. $startTime = $get['startTime'] ?? '';
  22. $endTime = $get['endTime'] ?? '';
  23. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  24. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  25. }
  26. $kdList = StatKdClass::getAllByCondition($where, null, '*');
  27. $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  28. if (!empty($kdList)) {
  29. foreach ($kdList as $key => $item) {
  30. $kd['wx'] = bcadd($kd['wx'], $item['wx']);
  31. $kd['alipay'] = bcadd($kd['alipay'], $item['alipay']);
  32. $kd['balance'] = bcadd($kd['balance'], $item['balance']);
  33. $kd['cash'] = bcadd($kd['cash'], $item['cash']);
  34. $kd['bank'] = bcadd($kd['bank'], $item['bank']);
  35. $kd['debt'] = bcadd($kd['debt'], $item['debt']);
  36. $kd['amount'] = bcadd($kd['amount'], $item['amount']);
  37. }
  38. }
  39. $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  40. $refundList = StatRefundClass::getAllByCondition($where, null, '*');
  41. if (!empty($refundList)) {
  42. foreach ($refundList as $key => $item) {
  43. $refund['wx'] = bcadd($refund['wx'], $item['wx']);
  44. $refund['alipay'] = bcadd($refund['alipay'], $item['alipay']);
  45. $refund['balance'] = bcadd($refund['balance'], $item['balance']);
  46. $refund['cash'] = bcadd($refund['cash'], $item['cash']);
  47. $refund['bank'] = bcadd($refund['bank'], $item['bank']);
  48. $refund['debt'] = bcadd($refund['debt'], $item['debt']);
  49. $refund['amount'] = bcadd($refund['amount'], $item['amount']);
  50. }
  51. }
  52. $arr = [
  53. ['name' => '微信支付', 'kd' => $kd['wx'], 'refund' => $refund['wx']],
  54. ['name' => '支付宝', 'kd' => $kd['alipay'], 'refund' => $refund['alipay']],
  55. ['name' => '欠账', 'kd' => $kd['debt'], 'refund' => $refund['debt']],
  56. ['name' => '余额', 'kd' => $kd['balance'], 'refund' => $refund['balance']],
  57. ['name' => '现金', 'kd' => $kd['cash'], 'refund' => $refund['cash']],
  58. ['name' => '银行卡', 'kd' => $kd['bank'], 'refund' => $refund['bank']],
  59. ['name' => '总计', 'kd' => $kd['amount'], 'refund' => $refund['amount']],
  60. ];
  61. $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
  62. util::success(['list' => $arr, 'income' => $income]);
  63. }
  64. }