www.au.test.cc/analysis/tr…

www.au.test.cc/analysis/tr…

controller


    /** * Info list */
    public function list()
    {
        // string(98) "( SELECT id,uuid,max(id) maxId,count(*) count FROM `analysis_tracker_202011` GROUP BY maxId desc )"
        $subQuery = $this->model
            ->name($this->model->getTableName())
            ->where($this->model->search())
            ->field('uuid,max(id) id,count(*) count')
            ->group('uuid')
            ->buildSql();

        / / the result set
        $sql = "SELECT * FROM analysis_tracker_202011 JOIN
{$subQuery} p USING(uuid,id) ORDER BY  id desc limit {$this->page}.{$this->limit};";
        /** * Conditional * string(249) "SELECT * FROM analysis_tracker_202011 JOIN * (SELECT uuid, Max (id) id,count(*) count FROM analysis_tracker_202011 JOIN * (SELECT uuid, Max (id) id,count(*) count FROM `analysis_tracker_202011` WHERE * ( `product_name` LIKE '%123%' OR `product_code` LIKE '%123%' ) GROUP BY `uuid` ) p * USING(uuid,id) ORDER BY id desc limit 1,50;" * /

        /** * SELECT * FROM analysis_tracker_202011 JOIN * (SELECT uuid, Max (id) id,count(*) count FROM analysis_tracker_202011 JOIN * (SELECT uuid, Max (id) id,count(*) count FROM analysis_tracker_202011 'analysis_tracker_202011' GROUP BY 'uuid') p * USING(uuid,id) ORDER BY id desc limit 1,50; * * /
        dd($sql);

        // The number of pages
        $sql_count = "SELECT count(*) count FROM analysis_tracker_202011 JOIN
{$subQuery} p USING(uuid,id) ORDER BY  id desc";

// $sql = "SELECT * FROM analysis_tracker_202011 JOIN
//(SELECT uuid, MAX(id) id FROM analysis_tracker_202011 GROUP BY uuid ) p USING(uuid,id)ORDER BY  id desc limit 10;";

        $data_count = $this->model->query($sql_count);
        $lists = $this->model->query($sql);



        foreach ($lists as &$row) {
            $row['ip_formal'] = $this->model->getIpFormalFormal($row['ip']);
            $row['user_formal'] = $this->model->getUserFormal($row['user_id']);
            $row['keep_time'] = $this->model->getKeepTimeFormal($row);
            $row['start_time'] = $this->model->getStartTimeFormal($row['uuid']);
            $row['survival_time'] = 'about' . (($row['count'] * 5) - 4).'秒';
            $row['create_time'] = date('Y-m-d H:i:s'.$row['create_time']);
        }

        return json_encode([
            'code'= >0.'count'= >$data_count[0] ['count'].'data'= >$lists,]); }Copy the code

model


    /** * select the current table dynamically, the default display when viewing the list, or when searching for the specified date table *@return array
     */
    public function getTableName()
    {
        $params = Request::get();
        if (!isset($params['searchParams'])) return $this->name;
        $searchParams = json_decode($params['searchParams'].true);
        $tableName = $searchParams['tableName']????$this->name;
        return $tableName;
    }
    
    
        /** * search *@return array
     */
    public function search()
    {
        $params = Request::get();
        if (!isset($params['searchParams'])) return [];
        $searchParams = json_decode($params['searchParams'].true);
        $where = [];
        unset($searchParams['create_time']);
        foreach ($searchParams as $field= >$value) {
            $value = trim($value);

            if ($field= ='tableName') continue;
            if ($value= =' ') continue;

            $where[] = [$field.'like'."%{$value}%"];
        }

        return $where;
    }
Copy the code