Dashboard.php 1.6 KB
<?php

namespace app\admin\controller\groupon\store;

use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;


/**
 * 门店统计
 *
 * @icon fa fa-circle-o
 */
class Dashboard extends Backend
{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();

        $this->model = new \app\admin\model\groupon\order\Order;
    }

    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            $params = $this->request->request();
            $datetimerange = $params['datetimerange'] ? explode(' - ', $params['datetimerange']) : [];
            $startTime = strtotime($datetimerange[0]);
            $endTime = strtotime($datetimerange[1]);
            $where = [
                'createtime' => ['between', [$startTime, $endTime]]
            ];

            $list = $this->buildSearch()
                ->with(['item'])
                ->where($where)
                ->order('id')
                ->select();

            $data['order_list'] = $list;

            $this->success('数据中心', null, $data);
        }

        return $this->view->fetch();
    }



    public function buildSearch() 
    {
        $params = $this->request->request();
        $store_id = isset($params['store_id']) ? $params['store_id'] : 0;

        $name = $this->model->getQuery()->getTable();
        $tableName = $name . '.';

        $orders = $this->model->withTrashed();
        
        if ($store_id) {
            $orders = $orders->where('store_id', $store_id);
        }

        return $orders;
    }
}