MonthReportController.php 3.7 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\Count;
use App\Models\HomeCount\MonthCount;
use App\Models\Inquiry\InquiryIP;
use App\Models\Inquiry\InquirySet;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Visit\Visit;
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'];
        $this->map['month'] = ['>=',date('Y-m',strtotime($this->user['uptime']))];
        $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);
        if(!empty($info['source_country'])){
            $info['source_country'] = json_decode($info['source_country']);
        }
        if(!empty($info['referrer_port'])){
            $info['referrer_port'] = json_decode($info['referrer_port']);
        }
        if(!empty($info['referrer_url'])){
            $info['referrer_url'] = json_decode($info['referrer_url']);
        }
        if(!empty($info['source'])){
            $info['source'] = json_decode($info['source']);
        }
        if(!empty($info['country'])){
            $info['country'] = json_decode($info['country']);
        }
        // 获取上个月的开始时间
        $startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
        // 获取上个月的结束时间
        $endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
        $param = [
            'date' => ['between',[$startTime,$endTime]],
            'project_id' => $this->user['project_id']
        ];
        $info['pv_ip'] = (new Count())->list($param,'date',['id','pv_num','ip_num','date']);
        $categoryModel = new Category();
        $info['category_num'] = $categoryModel->formatQuery(['status'=>1])->count();
        $productModel = new Product();
        $info['products_num'] = $productModel->formatQuery(['status'=>1])->count();
        $info['products_num_last_30'] = $productModel->formatQuery(
            ['status'=>1,'created_at'=>['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]]
            ])->count();
        $newsModel = new News();
        $info['news_num'] = $newsModel->formatQuery(['status'=>1])->count();
        $info['news_num_last_7'] = $newsModel->formatQuery(
            ['status'=>1,'created_at'=>['between',[now()->subDays(7)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]]
            ])->count();
        $info['service_duration'] = $this->user['service_duration'];//服务天数
        $info['ip_total'] = (new Visit())->count();//ip总数

        $info['remain_day'] = $this->user['remain_day'];//剩余服务天数
        $info['speed'] = round((0.3 + mt_rand()/mt_getrandmax() * (1-0.3)),2);
        $info['month_total'] = (int)$info['month_total'];
        $this->response('success',Code::SUCCESS,$info);
    }
}