作者 lyh

gx

  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Projects\InquiryInfo;
  6 +use Illuminate\Console\Command;
  7 +use Illuminate\Support\Facades\Log;
  8 +
  9 +/**
  10 + * @remark :
  11 + * @class :InquiryDelay.php
  12 + * @author :lyh
  13 + * @time :2023/7/14 10:16
  14 + */
  15 +class InquiryDelay extends Command
  16 +{
  17 + /**
  18 + * The name and signature of the console command.
  19 + *
  20 + * @var string
  21 + */
  22 + protected $signature = 'inquiry_delay';
  23 +
  24 + /**
  25 + * The console command description.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $description = '延时询盘转发';
  30 +
  31 + /**
  32 + * @remark :延时询盘转发
  33 + * @name :handle
  34 + * @author :lyh
  35 + * @method :post
  36 + * @time :2023/7/14 10:17
  37 + */
  38 + public function handle()
  39 + {
  40 + $inquiryInfoModel = new InquiryInfo();
  41 + $param = $inquiryInfoModel->formatQuery(['status'=>0,'delay'=>['!=',0]])->orderBy('send_time','asc')->first();
  42 + if($param !== false){
  43 + $time = date('Y-m-d H:i:s');
  44 + if($time >= $param['send_time']){
  45 + $data = [];
  46 + //TODO::处理转发的url
  47 + $arr_url = explode(',',$param['forward_url']);
  48 + foreach ($arr_url as $v){
  49 + $data['url'] = $v;
  50 + $this->inquiryForward($data);
  51 + Log::info('询盘转发记录'.json_encode($data),'debug------------------info');
  52 + }
  53 + }
  54 + }
  55 + return true;
  56 + }
  57 +
  58 + /**
  59 + * @remark :询盘转发
  60 + * @name :inquiryForward
  61 + * @author :lyh
  62 + * @method :post
  63 + * @time :2023/7/13 14:39
  64 + */
  65 + public function inquiryForward($post_data){
  66 + $url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f';
  67 + $post_data_new = [];
  68 + $post_data_new['refer'] = $post_data['url'];
  69 + $post_data_new['name'] = $post_data['name'];
  70 + $post_data_new['email'] = $post_data['email'];
  71 + $post_data_new['phone'] = $post_data['phone'];
  72 + $post_data_new['ip'] = $post_data['ip'];
  73 + $post_data_new['message'] = $post_data['message'];
  74 + $post_data_new['submit_time'] = date('Y-m-d H:i:s',time()+20);
  75 + $token = md5($post_data_new['refer'].$post_data_new['name'].$post_data_new['ip'].date("Y-m-d",time()));
  76 + $post_data_new['token'] = $token;
  77 + return http_post($url,$post_data_new);
  78 + }
  79 +}
@@ -30,6 +30,7 @@ class Kernel extends ConsoleKernel @@ -30,6 +30,7 @@ class Kernel extends ConsoleKernel
30 $schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每周执行一次 30 $schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每周执行一次
31 $schedule->command('sync_project')->everyMinute()->withoutOverlapping(1); //同步项目 31 $schedule->command('sync_project')->everyMinute()->withoutOverlapping(1); //同步项目
32 $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录 32 $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
  33 + $schedule->command('inquiry_delay')->everyMinute()->withoutOverlapping(1);//每分钟执行一次
33 // // 更新域名|证书结束时间,每天凌晨1点执行一次 34 // // 更新域名|证书结束时间,每天凌晨1点执行一次
34 // $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); 35 // $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
35 // // B站 - 网站数据统计 36 // // B站 - 网站数据统计
@@ -52,40 +52,20 @@ class InquiryInfoLogic extends BaseLogic @@ -52,40 +52,20 @@ class InquiryInfoLogic extends BaseLogic
52 * @time :2023/7/12 9:22 52 * @time :2023/7/12 9:22
53 */ 53 */
54 public function inquirySave(){ 54 public function inquirySave(){
55 - try {  
56 - $this->inquiryInfoSave();  
57 - }catch (\Exception $e){ 55 + $this->param['user_id'] = $this->manager['id'];
  56 + $this->param['user_name'] = $this->manager['name'];
  57 + $this->param['send_time'] = date('Y-m-d H:i:s',time() + $this->param['delay'] * 60 * 60) ;
  58 + $xp_id = $this->model->insertGetId($this->param);
  59 + if(!$xp_id){
58 $this->fail('error'); 60 $this->fail('error');
59 } 61 }
  62 + //延时时间为0时,询盘转发
  63 + if($this->param['delay'] == 0){
  64 + $this->forwardTime($xp_id);
  65 + }
60 return $this->success(); 66 return $this->success();
61 } 67 }
62 68
63 - /**  
64 - * @remark :保存询盘记录表  
65 - * @name :inquiryInfoSave  
66 - * @author :lyh  
67 - * @method :post  
68 - * @time :2023/7/12 11:12  
69 - */  
70 - public function inquiryInfoSave(){  
71 - //组装数据  
72 - $param = [  
73 - 'name'=>$this->param['name'],  
74 - 'email'=>$this->param['email'],  
75 - 'phone'=>$this->param['phone'],  
76 - 'ip'=>$this->param['ip'],  
77 - 'ip_area'=>$this->param['ip_area'],  
78 - 'message'=>$this->param['message'],  
79 - 'type'=>$this->param['type'],  
80 - 'user_id'=>$this->manager['id'],  
81 - 'user_name'=>$this->manager['name'],  
82 - 'forward_url'=>$this->param['forward_url'],  
83 - 'delay'=>$this->param['delay'],  
84 - ];  
85 - return $this->model->add($param);  
86 - }  
87 -  
88 -  
89 69
90 /** 70 /**
91 * @remark :逻辑删除 71 * @remark :逻辑删除
@@ -167,32 +147,24 @@ class InquiryInfoLogic extends BaseLogic @@ -167,32 +147,24 @@ class InquiryInfoLogic extends BaseLogic
167 * @method :post 147 * @method :post
168 * @time :2023/7/13 17:39 148 * @time :2023/7/13 17:39
169 */ 149 */
170 - public function forwardTime($param){ 150 + public function forwardTime($xp_id){
  151 + $data = [];
  152 + //获取数据详情
  153 + $param = $this->model->read(['id'=>$xp_id]);
171 if($param['delay'] == 0){ 154 if($param['delay'] == 0){
  155 + $data = $param;
172 $arr_url = explode(',',$param['forward_url']); 156 $arr_url = explode(',',$param['forward_url']);
173 foreach ($arr_url as $v){ 157 foreach ($arr_url as $v){
174 - $param['url'] = $v;  
175 - $this->inquiryForward($param); 158 + $data['url'] = $v;
  159 + $this->inquiryForward($data);
  160 + }
  161 + //更新数据库,修改状态为已转发
  162 + $rs = $this->model->edit(['status'=>3],['id'=>$xp_id]);
  163 + if($rs === false){
  164 + $this->fail('error');
176 } 165 }
177 - }else{  
178 - // 获取执行时间  
179 - $scheduledTime = date('Y-m-d H:i:s',time() + $this->param['delay'] * 60 * 60);  
180 - $schedule = new Schedule;  
181 - // 定义定时任务  
182 - $schedule->call(function () use ($param) {  
183 - // 任务执行的代码  
184 - $arr_url = explode(',',$param['forward_url']);  
185 - foreach ($arr_url as $v){  
186 - $param['url'] = $v;  
187 - $this->inquiryForward($param);  
188 - }  
189 - })->cron($scheduledTime);  
190 - // 获取任务调度的命令行参数  
191 - $parameters = $schedule->dueEvents($schedule->events());  
192 - // 执行命令行任务  
193 - Artisan::call($parameters);  
194 } 166 }
195 - return true; 167 + return $this->success();
196 } 168 }
197 169
198 /** 170 /**