Dda.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\main\service\OrderService;
  5. use think\Controller;
  6. use think\Request;
  7. /**
  8. * dd统计
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Dda extends Backend
  13. {
  14. /**
  15. * @var \app\common\model\Dda
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('Dda');
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags']);
  30. if ($this->request->isAjax())
  31. {
  32. $kl = $this->model->order('date', 'desc')->find();
  33. if ($kl) {
  34. $start_time = strtotime($kl['date']);
  35. } else {
  36. $start_time = time() - 86400 * 30;
  37. }
  38. //如果昨日已更新则跳过
  39. if (date('Ymd', $start_time) != date('Ymd', time() - 86400)) {
  40. $data = OrderService::instance()->getOrderKlData($start_time, time())->data;
  41. OrderService::instance()->updateKlTable($data);
  42. }
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('pkey_name'))
  45. {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $filter = json_decode($this->request->get('filter'), true);
  50. $where = [];
  51. $end = date('Y-m-d');
  52. if (array_key_exists('date', $filter)) {
  53. $times = explode(' - ', $filter['date']);
  54. $start = substr($times[0], 0, 10);
  55. $end = substr($times[1], 0, 10);
  56. $where['date'] = ['between', $start.','.$end];
  57. if(date('Y-m-d') <= $end){
  58. if ($offset == 0) {
  59. if ($limit) {
  60. $limit -= 1;
  61. }
  62. } else {
  63. if ($offset) {
  64. $offset -= 1;
  65. }
  66. }
  67. }
  68. } else {
  69. if ($offset == 0) {
  70. if ($limit) {
  71. $limit -= 1;
  72. }
  73. } else {
  74. if ($offset) {
  75. $offset -= 1;
  76. }
  77. }
  78. }
  79. $total = $this->model
  80. ->where($where)
  81. ->order($sort, $order)
  82. ->count();
  83. if(date('Y-m-d') <= $end){
  84. $total += 1;
  85. }
  86. $list = $this->model
  87. ->where($where)
  88. ->order($sort, $order)
  89. ->limit($offset, $limit)
  90. ->select();
  91. if ($offset == 0 && date('Y-m-d') <= $end) {
  92. if (!isset($data)) {
  93. $start_time = strtotime(date('Y-m-d'));
  94. $data = OrderService::instance()->getOrderKlData($start_time, time())->data;
  95. }
  96. array_unshift($list, array_pop($data));
  97. }
  98. $result = array("total" => $total, "rows" => $list);
  99. return json($result);
  100. }
  101. return $this->view->fetch();
  102. }
  103. }