MonthCountLogic.php 2.9 KB
<?php

namespace App\Http\Logic\Bside\HomeCount;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\HomeCount\Count;
use App\Models\HomeCount\MonthCount;
use App\Models\Project\ProjectKeyword;

class MonthCountLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new MonthCount();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :获取数据
     * @name   :getCountLists
     * @author :lyh
     * @method :post
     * @time   :2023/7/3 9:39
     */
    public function getCountLists($map,$order = 'created_at',$filed = ['*']){
        $map['project_id'] = $this->user['project_id'];
        $lists = $this->model->list($map,$order,$filed,'desc',10);
        if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){
            foreach ($lists as $k => $v){
                if(empty($v['source_country'])){
                    continue;
                }
                $source_country = json_decode($v['source_country']);
                foreach ($source_country as $k1 => $v1){
                    $v1 = (array)$v1;
                    if($v1['country'] == '中国'){
                        unset($source_country[$k1]);
                    }
                }
                $v['source_country'] = json_encode(array_values($source_country));
                $v['total'] = $new['total'] ?? $v['total'];
                $lists[$k] = $v;
            }
        }
        return $this->success($lists);
    }

    /**
     * @remark :根据时间获取pv,ip
     * @name   :getIpPvCount
     * @author :lyh
     * @method :post
     * @time   :2023/7/3 10:30
     */
    public function getIpPvCount(){
        $count = new Count();
        $startTime = date("Y-m-d", strtotime("-9 months", mktime(0, 0, 0)));
        $ensTime = date('Y-m-d',time());
        $lists = $count->list(['date'=>['between',[$startTime,$ensTime]],'project_id'=>$this->user['project_id']],'id',['*'],'asc');
        $groupedData = [];
        foreach ($lists as $k=>$v){
            $month = date('Y-m', strtotime($v['date']));
            if(!isset($groupedData[$month])){
                $groupedData[$month] = [];
            }
            if(empty($v['country'])){
                $v['country'] = [];
            }
            $groupedData[$month][] = $v;
        }
        return $this->success($groupedData);
    }

    /**
     * @remark :获取关键字列表
     * @name   :getKeywordLists
     * @author :lyh
     * @method :post
     * @time   :2023/7/4 10:19
     */
    public function getKeywordLists(){
        $projectKeywordModel = new ProjectKeyword();
        $info = $projectKeywordModel->read(['project_id'=>$this->user['project_id']],['main_keyword','customer_keywords']);
        if($info === false){
            $info = [
                'main_keyword'=>'',
                'customer_keywords'=>''
            ];
        }
        return $this->success($info);
    }
}