StatKdController.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. //惠雅鲜花员工不能看利润表
  20. $shopAdmin = $this->shopAdmin;
  21. $adminId = $shopAdmin->adminId ?? 0;
  22. if (in_array($adminId, [3405, 2812, 4004,2812])) {
  23. util::fail('暂无权限');
  24. }
  25. $searchTime = $get['searchTime'] ?? 'today';
  26. if (!empty($searchTime)) {
  27. $startTime = $get['startTime'] ?? '';
  28. $endTime = $get['endTime'] ?? '';
  29. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  30. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  31. }
  32. $kdList = StatKdClass::getAllByCondition($where, null, '*');
  33. $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  34. if (!empty($kdList)) {
  35. foreach ($kdList as $key => $item) {
  36. $kd['wx'] = bcadd($kd['wx'], $item['wx']);
  37. $kd['alipay'] = bcadd($kd['alipay'], $item['alipay']);
  38. $kd['balance'] = bcadd($kd['balance'], $item['balance']);
  39. $kd['cash'] = bcadd($kd['cash'], $item['cash']);
  40. $kd['bank'] = bcadd($kd['bank'], $item['bank']);
  41. $kd['debt'] = bcadd($kd['debt'], $item['debt']);
  42. $kd['amount'] = bcadd($kd['amount'], $item['amount']);
  43. }
  44. }
  45. $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
  46. $refundList = StatRefundClass::getAllByCondition($where, null, '*');
  47. if (!empty($refundList)) {
  48. foreach ($refundList as $key => $item) {
  49. $refund['wx'] = bcadd($refund['wx'], $item['wx']);
  50. $refund['alipay'] = bcadd($refund['alipay'], $item['alipay']);
  51. $refund['balance'] = bcadd($refund['balance'], $item['balance']);
  52. $refund['cash'] = bcadd($refund['cash'], $item['cash']);
  53. $refund['bank'] = bcadd($refund['bank'], $item['bank']);
  54. $refund['debt'] = bcadd($refund['debt'], $item['debt']);
  55. $refund['amount'] = bcadd($refund['amount'], $item['amount']);
  56. }
  57. }
  58. $arr = [
  59. ['name' => '微信支付', 'kd' => $kd['wx'], 'refund' => $refund['wx']],
  60. ['name' => '支付宝', 'kd' => $kd['alipay'], 'refund' => $refund['alipay']],
  61. ['name' => '欠账', 'kd' => $kd['debt'], 'refund' => $refund['debt']],
  62. ['name' => '余额', 'kd' => $kd['balance'], 'refund' => $refund['balance']],
  63. ['name' => '现金', 'kd' => $kd['cash'], 'refund' => $refund['cash']],
  64. ['name' => '银行卡', 'kd' => $kd['bank'], 'refund' => $refund['bank']],
  65. ['name' => '总计', 'kd' => $kd['amount'], 'refund' => $refund['amount']],
  66. ];
  67. $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
  68. util::success(['list' => $arr, 'income' => $income]);
  69. }
  70. }