123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\service\OrderService;
- use think\Controller;
- use think\Request;
- /**
- * dd统计
- *
- * @icon fa fa-circle-o
- */
- class Dda extends Backend
- {
- /**
- * @var \app\common\model\Dda
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Dda');
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- $kl = $this->model->order('date', 'desc')->find();
- if ($kl) {
- $start_time = strtotime($kl['date']);
- } else {
- $start_time = time() - 86400 * 30;
- }
- //如果昨日已更新则跳过
- if (date('Ymd', $start_time) != date('Ymd', time() - 86400)) {
- $data = OrderService::instance()->getOrderKlData($start_time, time())->data;
- OrderService::instance()->updateKlTable($data);
- }
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $filter = json_decode($this->request->get('filter'), true);
- $where = [];
- $end = date('Y-m-d');
- if (array_key_exists('date', $filter)) {
- $times = explode(' - ', $filter['date']);
- $start = substr($times[0], 0, 10);
- $end = substr($times[1], 0, 10);
- $where['date'] = ['between', $start.','.$end];
- if(date('Y-m-d') <= $end){
- if ($offset == 0) {
- if ($limit) {
- $limit -= 1;
- }
- } else {
- if ($offset) {
- $offset -= 1;
- }
- }
- }
- } else {
- if ($offset == 0) {
- if ($limit) {
- $limit -= 1;
- }
- } else {
- if ($offset) {
- $offset -= 1;
- }
- }
- }
- $total = $this->model
- ->where($where)
- ->order($sort, $order)
- ->count();
- if(date('Y-m-d') <= $end){
- $total += 1;
- }
- $list = $this->model
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- if ($offset == 0 && date('Y-m-d') <= $end) {
- if (!isset($data)) {
- $start_time = strtotime(date('Y-m-d'));
- $data = OrderService::instance()->getOrderKlData($start_time, time())->data;
- }
- array_unshift($list, array_pop($data));
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- }
|