Collectstatement.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * 对账角色用于对账的订单统计
  4. */
  5. namespace app\admin\controller;
  6. use app\admin\service\LogService;
  7. use app\common\controller\Backend;
  8. use app\common\model\OrdersCollect;
  9. use app\main\constants\AdminConstants;
  10. use app\main\constants\ApiConstants;
  11. use app\main\constants\PayConstants;
  12. use app\main\helper\ArrayHelper;
  13. use app\main\service\ApiService;
  14. use think\Db;
  15. /**
  16. * 数据统计-订单汇总
  17. *
  18. * @icon fa fa-circle-o
  19. */
  20. class Collectstatement extends Backend
  21. {
  22. /**
  23. * @var OrdersCollect
  24. */
  25. protected $model = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = model('OrdersCollect');
  30. }
  31. public function index()
  32. {
  33. //今天
  34. $today = date('Ymd', time());
  35. //昨天
  36. $yesterday = date('Ymd', strtotime('-1 days'));
  37. //本月
  38. $month = date('Ym', time()).'01';
  39. $business_line = $this->request->param('business_line');
  40. if (!$business_line) {
  41. $business_line = PayConstants::BUSINESS_WECHAT;
  42. }
  43. if (!$this->request->isAjax()) {
  44. $todayData = $this->model->where(['type'=>'1','flag'=>'2','admin_id'=>0,'createdate'=>$today,'business_line'=> $business_line])->find(); //今天的数据
  45. $yesterdayData = $this->model->where(['type'=>'1','flag'=>'2','admin_id'=>0,'createdate'=>$yesterday,'business_line'=> $business_line])->find(); //昨天的数据
  46. // $monthData = $this->model->where(['type'=>'2','flag'=>'2','admin_id'=>0,'createdate'=>$month])->find(); //当月的数据
  47. $monthData = $this->model->sumCollect(0, 1, 2, $month, $yesterday, $business_line); //当月的数据
  48. // $allData = $this->model->where(['type'=>'3','flag'=>'2','admin_id'=>0,])->find(); //汇总的数据
  49. $allData = $this->model->sumCollect(0, 1, 2, null, null, $business_line); //汇总的数据
  50. if (is_null($todayData)) {
  51. $todayData = [];
  52. }
  53. if (is_null($yesterdayData)) {
  54. $yesterdayData = [];
  55. }
  56. $this->assign('today',$todayData);
  57. $this->assign('yesterday',$yesterdayData);
  58. $this->assign('month',$monthData);
  59. $this->assign('all',$allData);
  60. } else {
  61. $beginDate = date('Ymd', strtotime('-31 days'));
  62. $endDate = date('Ymd', strtotime('-1 days'));
  63. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  64. $condition = [];
  65. $condition['type'] = 1;
  66. $condition['business_line'] = $business_line;
  67. $condition['admin_id'] = 0;
  68. $condition['flag'] = 2;
  69. $total = $this->model
  70. ->where($where)
  71. ->where('createdate', '>=', $beginDate)
  72. ->where('createdate', '<=', $endDate)
  73. ->where($condition)
  74. ->order($sort, $order)
  75. ->count();
  76. $list = $this->model
  77. ->where($where)
  78. ->where('createdate', '>=', $beginDate)
  79. ->where('createdate', '<=', $endDate)
  80. ->where($condition)
  81. ->order($sort, $order)
  82. ->limit($offset, $limit)
  83. ->select();
  84. $result = array("total" => $total, "rows" => $list);
  85. return json($result);
  86. }
  87. return $this->view->fetch();
  88. }
  89. }