WithdrawStatisticsController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/10/14 下午10:23
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\backend\modules\finance\controllers;
  10. use app\common\components\BaseController;
  11. use app\common\models\Withdraw;
  12. class WithdrawStatisticsController extends BaseController
  13. {
  14. private $withdrawModel;
  15. public function preAction()
  16. {
  17. parent::preAction();
  18. $this->withdrawModel = new Withdraw();
  19. }
  20. public function index()
  21. {
  22. if (request()->ajax()) {
  23. $search = \YunShop::request()->search;
  24. $has_time = Is_numeric($search['time']['start']) && Is_numeric($search['time']['end']);
  25. if ($has_time) {
  26. $time_data[] = ['start_time' => $search['time']['start'] / 1000, 'end_time' => $search['time']['end'] / 1000];
  27. } else {
  28. $time_data = $this->getDate();
  29. }
  30. $data = [];
  31. $amount = 0;
  32. foreach ($time_data as $key => $item) {
  33. $records = $this->getWithdrawAmounts($has_time, $item);
  34. $amount += $records['amount'];
  35. $data[] = $records;
  36. }
  37. return $this->successJson('ok', [
  38. 'data' => $data,
  39. 'high_light_open' => app('plugins')->isEnabled('high-light') ? 1 : 0,
  40. 'amount' => $amount
  41. ]);
  42. }
  43. return view('finance.withdraw.withdraw-statistics')->render();
  44. }
  45. private function getDate($begin_today = '', $end_today = '', $length = 6)
  46. {
  47. $begin_today = $begin_today ?: mktime(0, 0, 0, date('m'), date('d'), date('Y'));
  48. $end_today = $end_today ?: mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
  49. $data = [];
  50. for ($i = 0; $i <= $length; $i++) {
  51. $data[] = ['start_time' => $begin_today, 'end_time' => $end_today];
  52. $begin_today = $begin_today - 86400;
  53. $end_today = $end_today - 86400;
  54. }
  55. return $data;
  56. }
  57. private function getWithdrawAmounts($has_time, $item)
  58. {
  59. $data = [
  60. 'balance' => $this->withdrawModel->uniacid()->where('pay_way', 'balance')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  61. 'wechat' => $this->withdrawModel->uniacid()->where('pay_way', 'wechat')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  62. 'alipay' => $this->withdrawModel->uniacid()->where('pay_way', 'alipay')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  63. 'manual' => $this->withdrawModel->uniacid()->where('pay_way', 'manual')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  64. 'converge_pay' => $this->withdrawModel->uniacid()->where('pay_way', 'converge_pay')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  65. ];
  66. if (app('plugins')->isEnabled('high-light')) {
  67. $high = [
  68. 'high_light_wechat' => $this->withdrawModel->uniacid()->where('pay_way', 'high_light_wechat')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  69. 'high_light_alipay' => $this->withdrawModel->uniacid()->where('pay_way', 'high_light_alipay')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  70. 'high_light_bank' => $this->withdrawModel->uniacid()->where('pay_way', 'high_light_bank')->whereBetween('created_at', [$item['start_time'], $item['end_time']])->sum('amounts'),
  71. ];
  72. $data = array_merge($data, $high);
  73. }
  74. $data['amount'] = 0;
  75. foreach ($data as $key => $i) {
  76. $data['amount'] = bcadd($data['amount'], $i, 2);
  77. }
  78. $data['time'] = $has_time ? '时间段搜索' : date('Y-m-d', $item['start_time']);
  79. return $data;
  80. }
  81. }