ProjectsLogic.php 2.9 KB
<?php

namespace App\Http\Logic\Aside\Optimize;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\GoogleSeoIps\Country as CountryModel;
use App\Models\GoogleSeoIps\Projects;

/**
 * @remark :谷歌流量系统统计表
 * @class  :ProjectsLogic.php
 * @author :lyh
 * @time   :2023/7/11 9:54
 */
class ProjectsLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new Projects();
    }

    /**
     * @remark :获取列表
     * @name   :projectsLists
     * @author :lyh
     * @method :post
     * @time   :2023/7/11 9:56
     */
    public function projectsLists($map,$page,$row,$order = 'id',$filed = ['*']){
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        return $this->success($lists);
    }

    /**
     * @remark :更新
     * @name   :projectsSave
     * @author :lyh
     * @method :post
     * @time   :2023/7/11 10:05
     */
    public function projectsSave(){
        //参数处理
        $this->param = $this->verifyParam($this->param);
        if(isset($this->param['id']) && !empty($this->param['id'])){
            $rs = $this->model->formatQuery(['id'=>$this->param['id']])->update($this->param);
        }else{
            $this->param['last_push'] = date('Y-m-d');
            $this->param['last_crawled'] = date('Y-m-d H:i:s');
            $rs = $this->model->insert($this->param);
        }
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :参数处理
     * @name   :verifyParam
     * @author :lyh
     * @method :post
     * @time   :2023/7/18 10:46
     */
    public function verifyParam($param){
        $param['set_country'] = json_encode($param['set_country'],JSON_UNESCAPED_UNICODE);
        $param['set_ban_country'] = json_encode($param['set_ban_country'],JSON_UNESCAPED_UNICODE);
        $param['set_page_percent'] = json_encode($param['set_page_percent']);
        $param['set_device'] = json_encode($param['set_device']);
        $param['set_referer'] = json_encode($param['set_referer']);
        $param['set_depth'] = json_encode($param['set_depth']);
        $param['time_sleep'] = json_encode([3,5]);//TODO::已弃用
        return $param;
    }

    /**
     * @remark :删除
     * @name   :projectsDel
     * @author :lyh
     * @method :post
     * @time   :2023/7/11 10:07
     */
    public function projectsDel(){
        $rs = $this->model->del($this->param);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :获取国家列表
     * @name   :getCountryList
     * @author :lyh
     * @method :post
     * @time   :2023/7/18 11:12
     */
    public function getCountryList($map){
        $countryModel = new CountryModel();
        $lists = $countryModel->list($map);
        return $this->success($lists);
    }
}