作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :CountProject.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/9/26 14:19
  8 + */
  9 +
  10 +namespace App\Console\Commands\Project;
  11 +
  12 +use App\Models\Project\Project;
  13 +use Illuminate\Console\Command;
  14 +use PhpOffice\PhpSpreadsheet\Spreadsheet;
  15 +use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  16 +
  17 +class countProject extends Command
  18 +{
  19 + /**
  20 + * The name and signature of the console command.
  21 + *
  22 + * @var string
  23 + */
  24 + protected $signature = 'month_count_project';
  25 +
  26 + /**
  27 + * The console command description.
  28 + *
  29 + * @var string
  30 + */
  31 + protected $description = '项目数据统计生成文件';
  32 +
  33 + public function handle(){
  34 + $start = '2024-01';
  35 + $end = '2024-09';
  36 + $data = $this->exportDataProject($start,$end);
  37 + $result = $this->exportData($data);
  38 + echo date('Y-m-d H:i:s') . ' ' . json_encode($result) . PHP_EOL;
  39 + return $result;
  40 +
  41 + }
  42 +
  43 + public function exportData($data){
  44 + // 创建一个新的 Excel 电子表格实例
  45 + $spreadsheet = new Spreadsheet();
  46 + $sheet = $spreadsheet->getActiveSheet();
  47 + // 添加表头
  48 + $sheet->setCellValue('A1', '月份');
  49 + $sheet->setCellValue('B1', '开始时间');
  50 + $sheet->setCellValue('C1', '结束时间');
  51 + $sheet->setCellValue('D1', '创建项目数量');
  52 + $sheet->setCellValue('E1', '上线项目数量');
  53 + $sheet->setCellValue('F1', '上线比例');
  54 + $sheet->setCellValue('G1', '项目总数');
  55 + $sheet->setCellValue('H1', '上线项目总数');
  56 + $sheet->setCellValue('I1', '推广项目总数');
  57 + $sheet->setCellValue('J1', '建站项目总数');
  58 + $sheet->setCellValue('K1', '未上线项目数量');
  59 + $sheet->setCellValue('L1', '删除项目数量');
  60 + $sheet->setCellValue('M1', '上线最快时间');
  61 + $sheet->setCellValue('N1', '上线最慢');
  62 + $sheet->setCellValue('O1', '平均上线天数');
  63 + $rowCount = 2;
  64 + $allData = $this->countAll();
  65 + foreach ($data as $v) {
  66 + $sheet->setCellValue('A' . $rowCount, $v['month']);
  67 + $sheet->setCellValue('B' . $rowCount, $v['start']);
  68 + $sheet->setCellValue('C' . $rowCount, $v['end']);
  69 + $sheet->setCellValue('D' . $rowCount, $v['month_create_project_count']);
  70 + $sheet->setCellValue('E' . $rowCount, $v['month_project_go_online_count']);
  71 + $sheet->setCellValue('F' . $rowCount, $v['month_project_online_rate']);
  72 + $sheet->setCellValue('G' . $rowCount, $allData['count']);
  73 + $sheet->setCellValue('H' . $rowCount, $allData['go_online_count']);
  74 + $sheet->setCellValue('I' . $rowCount, $allData['promotion_web_count']);
  75 + $sheet->setCellValue('J' . $rowCount, $allData['create_web_count']);
  76 + $sheet->setCellValue('K' . $rowCount, $allData['no_go_oline_count']);
  77 + $sheet->setCellValue('L' . $rowCount, $allData['delete_project_count']);
  78 + $sheet->setCellValue('M' . $rowCount, $allData['min_project_count']);
  79 + $sheet->setCellValue('N' . $rowCount, $allData['max_project_count']);
  80 + $sheet->setCellValue('O' . $rowCount, $allData['average']);
  81 + $rowCount++;
  82 + }
  83 + // 创建一个新的 Excel Writer 对象
  84 + $writer = new Xlsx($spreadsheet);
  85 + $filename = time().'.xlsx';
  86 + // 设置导出文件的保存路径和文件名
  87 + $filePath = public_path('upload/excel/'.$filename);
  88 + // 导出 Excel 文件
  89 + $writer->save($filePath);
  90 + // 返回导出文件的响应
  91 + return ['file_link'=>url('upload/excel/'.$filename)];
  92 + }
  93 + /**
  94 + * @remark :获取所有月份
  95 + * @name :getMonthsBetween
  96 + * @author :lyh
  97 + * @method :post
  98 + * @time :2024/9/26 10:43
  99 + */
  100 + public function getMonthsBetween($startDate, $endDate)
  101 + {
  102 + // 创建 DateTime 对象
  103 + $start = new \DateTime($startDate);
  104 + $end = new \DateTime($endDate);
  105 + // 确保结束时间是该月份的最后一天,以包含结束月份
  106 + $end->modify('first day of next month');
  107 + // 用于存储所有月份
  108 + $months = [];
  109 + // 循环遍历每个月
  110 + while ($start < $end) {
  111 + $months[] = $start->format('Y-m'); // 格式化成 YYYY-MM
  112 + $start->modify('+1 month'); // 增加一个月
  113 + }
  114 + return $months;
  115 + }
  116 +
  117 + /**
  118 + * @remark :根据时间获取开始时间+结束时间
  119 + * @name :getStartAndEndOfMonth
  120 + * @author :lyh
  121 + * @method :post
  122 + * @time :2024/9/26 10:44
  123 + */
  124 + public function getStartAndEndOfMonth($month) {
  125 + // 创建指定月份的 DateTime 对象
  126 + $start = new \DateTime($month . '-01'); // 月份的第一天
  127 + // 复制开始日期并获取该月的最后一天
  128 + $end = clone $start;
  129 + $end->modify('last day of this month'); // 修改为该月的最后一天
  130 + // 格式化成 'Y-m-d H:i:s'
  131 + $startTime = $start->format('Y-m-d 00:00:00'); // 开始时间,精确到天的开始
  132 + $endTime = $end->format('Y-m-d 23:59:59'); // 结束时间,精确到天的结束
  133 + return [
  134 + 'start' => $startTime,
  135 + 'end' => $endTime,
  136 + ];
  137 + }
  138 +
  139 + /**
  140 + * @remark :导出数据
  141 + * @name :exportData
  142 + * @author :lyh
  143 + * @method :post
  144 + * @time :2023/8/1 16:45
  145 + */
  146 + public function exportDataProject($start_month,$end_month){
  147 + $data = [];
  148 + $monthData = $this->getMonthsBetween($start_month,$end_month);
  149 + $projectModel = new Project();
  150 + foreach ($monthData as $v){
  151 + $data[$v]['month'] = $v;
  152 + $timeArr = $this->getStartAndEndOfMonth($v);
  153 + $start_time = $timeArr['start'];
  154 + $end_time = $timeArr['end'];
  155 + $data[$v]['start'] = $start_time;
  156 + $data[$v]['end'] = $end_time;
  157 + //每月创建项目数据
  158 + $data[$v]['month_create_project_count'] = $projectModel->counts(['created_at'=>['between',[$start_time,$end_time]],'deleted_at'=>0]);//每月创建项目数量
  159 + $data[$v]['month_project_go_online_count'] = $projectModel->counts(['uptime'=>['between',[$start_time,$end_time]],'deleted_at'=>0]);//当月上线项目数量
  160 + $data[$v]['month_project_online_rate'] = 0;
  161 + if($data[$v]['month_create_project_count'] != 0){
  162 + $data[$v]['month_project_online_rate'] = $data[$v]['month_project_go_online_count'] / $data[$v]['month_create_project_count'];//比例
  163 + }
  164 +// $data[$v]['count'] = $projectModel->count(['deleted_at'=>0]);//所有项目总数
  165 +// $data[$v]['go_online_count'] = $projectModel->count(['uptime'=>['!=',null],'deleted_at'=>0]);//上线项目总数
  166 +// $data[$v]['promotion_web_count'] = $projectModel->count(['type'=>3,'deleted_at'=>0]);//推广项目总数
  167 +// $data[$v]['create_web_count'] = $projectModel->count(['type'=>2,'deleted_at'=>0]);//建站项目总数
  168 +// $data[$v]['no_go_oline_count'] = $projectModel->count(['uptime'=>null,'deleted_at'=>0]);//未上线项目数量
  169 +// $data[$v]['delete_project_count'] = $projectModel->count(['deleted_at'=>1]);//未上线项目数量
  170 +// $min_info = $projectModel->select('diff')->selectRaw('(uptime - created_at) as diff')->where('uptime','!=',null)->orderByRaw('diff ASC')->first();
  171 +// $data[$v]['min_project_count'] = $min_info['diff'];
  172 +// $max_info = $projectModel->select('diff')->selectRaw('(uptime - created_at) as diff')->where('uptime','!=',null)->orderByRaw('diff Desc')->first();
  173 +// $data[$v]['max_project_count'] = $max_info['diff'];
  174 +// $data[$v]['average'] = ceil(($max_info['diff'] + $min_info['diff']) / 2);
  175 + }
  176 + return $data;
  177 + }
  178 +
  179 + /**
  180 + * @remark :所有项目总数
  181 + * @name :countAll
  182 + * @author :lyh
  183 + * @method :post
  184 + * @time :2024/9/26 15:11
  185 + */
  186 + public function countAll(){
  187 + $projectModel = new Project();
  188 + $data['count'] = $projectModel->count(['deleted_at'=>0]);//所有项目总数
  189 + $data['go_online_count'] = $projectModel->counts(['uptime'=>['!=',null],'deleted_at'=>0]);//上线项目总数
  190 + $data['promotion_web_count'] = $projectModel->counts(['type'=>3,'deleted_at'=>0]);//推广项目总数
  191 + $data['create_web_count'] = $projectModel->counts(['type'=>2,'deleted_at'=>0]);//建站项目总数
  192 + $data['no_go_oline_count'] = $projectModel->counts(['uptime'=>null,'deleted_at'=>0]);//未上线项目数量
  193 + $data['delete_project_count'] = $projectModel->counts(['deleted_at'=>1]);//删除项目数量
  194 + $min_info = $projectModel->select('*')
  195 + ->selectRaw('DATEDIFF(STR_TO_DATE(uptime, "%Y-%m-%d"), STR_TO_DATE(created_at, "%Y-%m-%d")) AS diff')
  196 + ->whereNotNull('uptime') // 确保 uptime 字段不为空
  197 + ->orderByRaw('diff ASC')
  198 + ->first();
  199 + $data['min_project_count'] = $min_info['diff'];
  200 + $max_info = $projectModel->select('*')
  201 + ->selectRaw('DATEDIFF(STR_TO_DATE(uptime, "%Y-%m-%d"), STR_TO_DATE(created_at, "%Y-%m-%d")) AS diff')
  202 + ->whereNotNull('uptime') // 确保 uptime 字段不为空
  203 + ->orderByRaw('diff DESC')
  204 + ->first();
  205 + $data['max_project_count'] = $max_info['diff'];
  206 + $data['average'] = ceil(($max_info['diff'] + $min_info['diff']) / 2);
  207 + return $data;
  208 + }
  209 +}
@@ -21,6 +21,8 @@ use Illuminate\Support\Facades\Cache; @@ -21,6 +21,8 @@ use Illuminate\Support\Facades\Cache;
21 use Illuminate\Support\Facades\DB; 21 use Illuminate\Support\Facades\DB;
22 use Illuminate\Support\Facades\Hash; 22 use Illuminate\Support\Facades\Hash;
23 use Illuminate\Support\Facades\Log; 23 use Illuminate\Support\Facades\Log;
  24 +use PhpOffice\PhpSpreadsheet\Spreadsheet;
  25 +use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
24 26
25 /** 27 /**
26 * Class IndexController 28 * Class IndexController
@@ -167,4 +169,6 @@ class IndexController extends BaseController @@ -167,4 +169,6 @@ class IndexController extends BaseController
167 } 169 }
168 $this->response('success',Code::SUCCESS,['dynamic_password'=>$dynamic_password]); 170 $this->response('success',Code::SUCCESS,['dynamic_password'=>$dynamic_password]);
169 } 171 }
  172 +
  173 +
170 } 174 }
@@ -285,7 +285,7 @@ class ProjectController extends BaseController @@ -285,7 +285,7 @@ class ProjectController extends BaseController
285 if($this->map['domain'] == 0){ 285 if($this->map['domain'] == 0){
286 $query = $query->where('gl_project_deploy_optimize.domain',null); 286 $query = $query->where('gl_project_deploy_optimize.domain',null);
287 }else{ 287 }else{
288 - $query = $query->where('gl_project_deploy_optimize.domain',null); 288 + $query = $query->where('gl_project_deploy_optimize.domain','!=',null);
289 } 289 }
290 } 290 }
291 return $query; 291 return $query;
@@ -188,7 +188,7 @@ class InquiryLogic extends BaseLogic @@ -188,7 +188,7 @@ class InquiryLogic extends BaseLogic
188 $num_phone = preg_replace('/\D/', '',$phone) ?? ''; // \D 匹配所有非数字字符 188 $num_phone = preg_replace('/\D/', '',$phone) ?? ''; // \D 匹配所有非数字字符
189 $data = $phoneDataModel->read(['num_phone'=>$num_phone]); 189 $data = $phoneDataModel->read(['num_phone'=>$num_phone]);
190 if($data === false){ 190 if($data === false){
191 - $url = 'https://fob.ai.cc/api/mobile_verify_data/'.$phone; 191 + $url = 'https://fob.ai.cc/api/mobile_verify_data/'.$num_phone;
192 $data = http_get($url); 192 $data = http_get($url);
193 if(!empty($data)){ 193 if(!empty($data)){
194 $param = [ 194 $param = [
@@ -316,7 +316,7 @@ class UserLoginLogic @@ -316,7 +316,7 @@ class UserLoginLogic
316 $is_amp = $amp_info ? $amp_info['amp_status'] : 0; 316 $is_amp = $amp_info ? $amp_info['amp_status'] : 0;
317 } 317 }
318 $info['is_amp'] = $is_amp; 318 $info['is_amp'] = $is_amp;
319 - $info['login_source'] = User::LOGIN_PASSWORD_SOURCE; 319 + $info['login_source'] = User::LOGIN_PASSWORD_SOURCE;//账号密码登录返回
320 //保存项目缓存 320 //保存项目缓存
321 Cache::put('user-'.$info['project_id'],$project,12 * 3600); 321 Cache::put('user-'.$info['project_id'],$project,12 * 3600);
322 return $this->success($info); 322 return $this->success($info);
@@ -116,6 +116,17 @@ class Base extends Model @@ -116,6 +116,17 @@ class Base extends Model
116 } 116 }
117 117
118 /** 118 /**
  119 + * @remark :统计数量
  120 + * @name :count
  121 + * @author :lyh
  122 + * @method :post
  123 + * @time :2024/9/26 10:52
  124 + */
  125 + public function counts($condition){
  126 + $condition = $this->filterRequestData($condition);
  127 + return $this->formatQuery($condition)->count();
  128 + }
  129 + /**
119 * @remark :编辑 130 * @remark :编辑
120 * @name :edit 131 * @name :edit
121 * @author :lyh 132 * @author :lyh