CountLogic.php 6.5 KB
<?php

namespace App\Http\Logic\Bside\HomeCount;


use App\Http\Logic\Bside\BaseLogic;
use App\Models\HomeCount\Count;
use App\Models\RankData\RankData as RankDataModel;
use App\Models\Service\Service;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

class CountLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new Count();
    }

    /**
     * @name   :(昨日统计数据)yesterday_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/23 17:30
     */
    public function yesterday_count(){
        $yesterday = Carbon::yesterday()->toDateString();
        $param = [
            'date' => $yesterday,
            'project_id' => $this->user['project_id']
        ];
        $info = $this->model->read($param,['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']);
        if($info === false){
            $info = [];
        }
        return $this->success($info);
    }

    /**
     * @name   :(方案信息)scheme_info
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 11:48
     */
    public function scheme_info(){
        $data = [
            'company'=>$this->project['company'],
            'scheme'=>$this->project['deploy_build']['plan'],
            'service_duration'=>$this->project['deploy_build']['service_duration'],
        ];
        return $this->success($data);
    }

    /**
     * @name   :(总访问量)total_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 13:33
     */
    public function total_count($inquiry_num = ''){
        $pv = DB::table('gl_customer_visit_item')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
        $ip = DB::table('gl_customer_visit')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
        $data = [
            'total_pv'=>$pv,
            'total_ip'=>$ip,
            'conversion_rate' => (isset($inquiry_num) && !empty($inquiry_num) && ($ip != 0)) ? round(($inquiry_num / $ip) * 10,2) : 0,
        ];
        return $this->success($data);
    }

    /**
     * @name   :(前一天关键字排名统计)keyword_data
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 14:03
     */
    public function keyword_data_count(){
        $yesterday = Carbon::yesterday()->toDateString();
        $rankDataModel = new RankDataModel();
        $param = [
            'updated_date' => $yesterday,
            'project_id' => $this->user['project_id']
        ];
        $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
        if($data === false){
            $data = [];
        }
        return $this->success($data);
    }

    /**
     * @name   :(相关数据统计)with_data_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 14:12
     */
    public function with_data_count(){
        $product_count = DB::table('gl_product')->where(['project_id' => $this->user['project_id']])->count();
        $news_count = DB::table('gl_news')->where(['project_id' => $this->user['project_id']])->count();
        $page_count = DB::table('gl_web_template')->where(['project_id' => $this->user['project_id']])->count();
        $data = [
            'product_count' => $product_count,
            'news_count' => $news_count,
            'page_count' => $page_count,
        ];
        return $this->success($data);
    }

    /**
     * @name   :(30天数据统计)visit_data_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 14:18
     */
    public function visit_data_count(){
        $param = [
            'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
            'project_id' => $this->user['project_id']
        ];
        $data = $this->model->list($param,'date',['id','pv_num','ip_num','date']);
        return $this->success($data);
    }

    /**
     * @name   :(访问来源统计)referrer_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 15:32
     */
    public function referrer_count(){
        $data = DB::table('gl_customer_visit')
            ->select('referrer_url', DB::raw('COUNT(*) as count'))
            ->groupBy('referrer_url')->where(['domain'=>$this->project['deploy_build']['test_domain']])
            ->orderByDesc('count')->limit(8)->get()->toArray();
        $total = DB::table('gl_customer_visit')->count();
        if(!empty($data)){
            $data = object_to_array($data);
            foreach ($data as $k=>$v){
                $data[$k]['proportion'] = ($v['count']/$total) * 100;
            }
        }
        return $this->success($data);
    }

    /**
     * @name   :(访问国家统计)access_country_count
     * @author :lyh
     * @method :post
     * @time   :2023/5/24 15:56
     */
    public function access_country_count(){
        $data = DB::table('gl_customer_visit')
            ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
            ->groupBy('country')->where(['domain'=>$this->project['deploy_build']['test_domain']])
            ->orderBy('ip','desc')->limit(20)->get()->toArray();
        if(!empty($data)){
            $data = object_to_array($data);
            foreach ($data as $k => $v){
                $v['pv'] = (int)$v['pv'];
                $data[$k] = $v;
            }
        }
        return $this->success($data);
    }

    /**
     * @name   :(售后服务中心)enterprise_service
     * @author :lyh
     * @method :post
     * @time   :2023/5/25 10:22
     */
    public function enterprise_service(){
        $serviceModel = new Service();
        $lists = $serviceModel->list(['type'=>1],'created_at');
        foreach ($lists as $k => $v){
            switch ($v['key']){
                case 'images':
                    $arr = explode(',',$v['values']);
                    foreach ($arr as $k1 => $v1){
                        $v['images_link'][$k1] = url('a/image/'.$v1);
                    }
                    break;
                case 'android':
                    $v['android_link'] = url('a/image/'.$v['values']);
                    break;
                case 'official_account':
                    $v['official_account_link'] = url('a/image/'.$v['values']);
                    break;
                case 'ios':
                    $v['ios_link'] = url('a/image/'.$v['values']);
                    break;
            }
            $lists[$k] = $v;
        }
        return $this->success($lists);
    }
}