MonthReportController.php 2.4 KB
<?php
/**
 * @remark :
 * @name   :MonthReportController.php
 * @author :lyh
 * @method :post
 * @time   :2024/2/2 15:01
 */

namespace App\Http\Controllers\Bside\BCom;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\HomeCount\MonthCount;
use Carbon\Carbon;

class MonthReportController extends BaseController
{
    /**
     * @remark :获取项目当前所有月份
     * @name   :getMonth
     * @author :lyh
     * @method :post
     * @time   :2024/2/2 15:14
     */
    public function getMonth(){
        $monthCountModel = new MonthCount();
        $this->map['project_id'] = $this->user['project_id'];
        $month = $monthCountModel->formatQuery($this->map)->pluck('month')->unique()->toArray();
        $this->response('success',Code::SUCCESS,$month);
    }

    /**
     * @remark :月报告详情
     * @name   :monthReportInfo
     * @author :lyh
     * @method :post
     * @time   :2024/2/2 15:02
     */
    public function monthReportInfo(){
        $monthCountModel = new MonthCount();
        $this->map['project_id'] = $this->user['project_id'];
        $info = $monthCountModel->read($this->map);
        foreach ($info as $k => $v){
            if(!empty($v['source_country'])){
                $v['source_country'] = json_decode($v['source_country']);
            }
            if(!empty($v['referrer_port'])){
                $v['referrer_port'] = json_decode($v['referrer_port']);
            }
            if(!empty($v['referrer_url'])){
                $v['referrer_url'] = json_decode($v['referrer_url']);
            }
            if(!empty($v['source'])){
                $v['source'] = json_decode($v['source']);
            }
            if(!empty($v['country'])){
                $v['country'] = json_decode($v['country']);
            }
            //获取上去的流量统计
            // 获取上个月的开始时间
            $startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
            // 获取上个月的结束时间
            $endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
            $param = [
                'date' => ['between',[$startTime,$endTime]],
                'project_id' => $this->user['project_id']
            ];
            $v['pv_ip'] = $this->model->list($param,'date',['id','pv_num','ip_num','date']);
            $info[$k] = $v;
        }
        $this->response('success',Code::SUCCESS,$info);
    }
}