StatKdController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace ghs\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['mainId'] = $this->mainId;
  16. $searchTime = $get['searchTime'] ?? 'today';
  17. if (!empty($searchTime)) {
  18. $startTime = $get['startTime'] ?? '';
  19. $endTime = $get['endTime'] ?? '';
  20. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  21. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  22. }
  23. $kdList = StatKdClass::getAllByCondition($where, null, '*');
  24. $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  25. if (!empty($kdList)) {
  26. foreach ($kdList as $key => $item) {
  27. $kd['wx'] = bcadd($kd['wx'], $item['wx'], 2);
  28. $kd['alipay'] = bcadd($kd['alipay'], $item['alipay'], 2);
  29. $kd['balance'] = bcadd($kd['balance'], $item['balance'], 2);
  30. $kd['cash'] = bcadd($kd['cash'], $item['cash'], 2);
  31. $kd['bank'] = bcadd($kd['bank'], $item['bank'], 2);
  32. $kd['debt'] = bcadd($kd['debt'], $item['debt'], 2);
  33. $kd['amount'] = bcadd($kd['amount'], $item['amount'], 2);
  34. }
  35. }
  36. $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  37. $refundList = StatRefundClass::getAllByCondition($where, null, '*');
  38. if (!empty($refundList)) {
  39. foreach ($refundList as $key => $item) {
  40. $refund['wx'] = bcadd($refund['wx'], $item['wx'], 2);
  41. $refund['alipay'] = bcadd($refund['alipay'], $item['alipay'], 2);
  42. $refund['balance'] = bcadd($refund['balance'], $item['balance'], 2);
  43. $refund['cash'] = bcadd($refund['cash'], $item['cash'], 2);
  44. $refund['bank'] = bcadd($refund['bank'], $item['bank'], 2);
  45. $refund['debt'] = bcadd($refund['debt'], $item['debt'], 2);
  46. $refund['amount'] = bcadd($refund['amount'], $item['amount'], 2);
  47. }
  48. }
  49. $arr = [
  50. ['name' => '微信支付', 'kd' => floatval($kd['wx']), 'refund' => floatval($refund['wx'])],
  51. ['name' => '支付宝', 'kd' => floatval($kd['alipay']), 'refund' => floatval($refund['alipay'])],
  52. ['name' => '欠账', 'kd' => floatval($kd['debt']), 'refund' => floatval($refund['debt'])],
  53. ['name' => '余额', 'kd' => floatval($kd['balance']), 'refund' => floatval($refund['balance'])],
  54. ['name' => '现金', 'kd' => floatval($kd['cash']), 'refund' => floatval($refund['cash'])],
  55. ['name' => '银行卡', 'kd' => floatval($kd['bank']), 'refund' => floatval($refund['bank'])],
  56. ['name' => '总计', 'kd' => floatval($kd['amount']), 'refund' => floatval($refund['amount'])],
  57. ];
  58. $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
  59. util::success(['list' => $arr, 'income' => $income]);
  60. }
  61. }