作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

  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站 - 网站数据统计
@@ -150,9 +150,25 @@ class InquiryInfoController extends BaseController @@ -150,9 +150,25 @@ class InquiryInfoController extends BaseController
150 'ip_area'=>'required',// 150 'ip_area'=>'required',//
151 ],[ 151 ],[
152 'ip_area.required' => '国家不能为空', 152 'ip_area.required' => '国家不能为空',
153 -  
154 ]); 153 ]);
155 $info = $inquiryInfoLogic->getSearchIp(); 154 $info = $inquiryInfoLogic->getSearchIp();
156 $this->response('success',Code::SUCCESS,$info); 155 $this->response('success',Code::SUCCESS,$info);
157 } 156 }
  157 +
  158 + /**
  159 + * @remark :手动询盘转发
  160 + * @name :forwardInquiry
  161 + * @author :lyh
  162 + * @method :post
  163 + * @time :2023/7/14 10:43
  164 + */
  165 + public function forwardInquiry(InquiryInfoLogic $inquiryInfoLogic){
  166 + $this->request->validate([
  167 + 'id'=>'required',//
  168 + ],[
  169 + 'id.required' => 'id不能为空',
  170 + ]);
  171 + $inquiryInfoLogic->forwardTime($this->param['id']);
  172 + $this->response('success');
  173 + }
158 } 174 }
@@ -7,8 +7,6 @@ use App\Models\InquiryIP; @@ -7,8 +7,6 @@ use App\Models\InquiryIP;
7 use App\Models\Projects\InquiryInfo; 7 use App\Models\Projects\InquiryInfo;
8 use App\Models\Projects\InquiryUser; 8 use App\Models\Projects\InquiryUser;
9 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\DB;
10 -use Illuminate\Support\Facades\Artisan;  
11 -use Illuminate\Console\Scheduling\Schedule;  
12 10
13 /** 11 /**
14 * @remark :询盘中心 12 * @remark :询盘中心
@@ -52,43 +50,20 @@ class InquiryInfoLogic extends BaseLogic @@ -52,43 +50,20 @@ class InquiryInfoLogic extends BaseLogic
52 * @time :2023/7/12 9:22 50 * @time :2023/7/12 9:22
53 */ 51 */
54 public function inquirySave(){ 52 public function inquirySave(){
55 - try {  
56 - $this->inquiryInfoSave();  
57 - }catch (\Exception $e){ 53 + $xp_id = $this->model->insertGetId($this->param);
  54 + if(!$xp_id){
58 $this->fail('error'); 55 $this->fail('error');
59 } 56 }
60 - return $this->success(); 57 + //延时时间为0时,询盘转发
  58 + if($this->param['delay'] == 0){
  59 + $this->forwardTime($xp_id);
61 } 60 }
62 -  
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); 61 + return $this->success();
86 } 62 }
87 63
88 64
89 -  
90 /** 65 /**
91 - * @remark :逻辑删除 66 + * @remark :删除
92 * @name :inquiryInfoDel 67 * @name :inquiryInfoDel
93 * @author :lyh 68 * @author :lyh
94 * @method :post 69 * @method :post
@@ -116,8 +91,7 @@ class InquiryInfoLogic extends BaseLogic @@ -116,8 +91,7 @@ class InquiryInfoLogic extends BaseLogic
116 * @time :2023/7/12 17:43 91 * @time :2023/7/12 17:43
117 */ 92 */
118 public function inquiryForwardInfo(){ 93 public function inquiryForwardInfo(){
119 - $inquiryUserModel = new InquiryUser();  
120 - $info = $inquiryUserModel->read(['xp_id'=>$this->param['id']]); 94 + $info = $this->model->read(['id'=>$this->param['id']]);
121 if($info === false){ 95 if($info === false){
122 $this->fail('error'); 96 $this->fail('error');
123 } 97 }
@@ -167,32 +141,27 @@ class InquiryInfoLogic extends BaseLogic @@ -167,32 +141,27 @@ class InquiryInfoLogic extends BaseLogic
167 * @method :post 141 * @method :post
168 * @time :2023/7/13 17:39 142 * @time :2023/7/13 17:39
169 */ 143 */
170 - public function forwardTime($param){ 144 + public function forwardTime($xp_id){
  145 + //获取数据详情
  146 + $param = $this->model->read(['id'=>$xp_id]);
171 if($param['delay'] == 0){ 147 if($param['delay'] == 0){
  148 + $data = $param;
172 $arr_url = explode(',',$param['forward_url']); 149 $arr_url = explode(',',$param['forward_url']);
173 foreach ($arr_url as $v){ 150 foreach ($arr_url as $v){
174 - $param['url'] = $v;  
175 - $this->inquiryForward($param);  
176 - }  
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); 151 + $data['url'] = $v;
  152 + $this->inquiryForward($data);
  153 + }
  154 + //更新数据库,修改状态为已转发
  155 + $this->param['status'] = 3;
  156 + $this->param['user_id'] = $this->manager['id'];
  157 + $this->param['user_name'] = $this->manager['name'];
  158 + $this->param['send_time'] = date('Y-m-d H:i:s',time() + $param['delay'] * 60 * 60) ;
  159 + $rs = $this->model->edit($this->param,['id'=>$xp_id]);
  160 + if($rs === false){
  161 + $this->fail('error');
188 } 162 }
189 - })->cron($scheduledTime);  
190 - // 获取任务调度的命令行参数  
191 - $parameters = $schedule->dueEvents($schedule->events());  
192 - // 执行命令行任务  
193 - Artisan::call($parameters);  
194 } 163 }
195 - return true; 164 + return $this->success();
196 } 165 }
197 166
198 /** 167 /**
@@ -267,6 +267,7 @@ Route::group([], function () { @@ -267,6 +267,7 @@ Route::group([], function () {
267 Route::prefix('inquiry')->group(function () { 267 Route::prefix('inquiry')->group(function () {
268 Route::any('/', [Aside\Projects\InquiryInfoController::class, 'lists'])->name('admin.inquiry_lists'); 268 Route::any('/', [Aside\Projects\InquiryInfoController::class, 'lists'])->name('admin.inquiry_lists');
269 Route::any('/save', [Aside\Projects\InquiryInfoController::class, 'save'])->name('admin.inquiry_save'); 269 Route::any('/save', [Aside\Projects\InquiryInfoController::class, 'save'])->name('admin.inquiry_save');
  270 + Route::any('/forwardInquiry', [Aside\Projects\InquiryInfoController::class, 'forwardInquiry'])->name('admin.inquiry_forwardInquiry');
270 Route::any('/forwardInfo', [Aside\Projects\InquiryInfoController::class, 'forwardInfo'])->name('admin.inquiry_forwardInfo'); 271 Route::any('/forwardInfo', [Aside\Projects\InquiryInfoController::class, 'forwardInfo'])->name('admin.inquiry_forwardInfo');
271 Route::any('/importInquirySave', [Aside\Projects\InquiryInfoController::class, 'importInquirySave'])->name('admin.inquiry_importInquirySave'); 272 Route::any('/importInquirySave', [Aside\Projects\InquiryInfoController::class, 'importInquirySave'])->name('admin.inquiry_importInquirySave');
272 Route::any('/getSearchIpInfo', [Aside\Projects\InquiryInfoController::class, 'getSearchIpInfo'])->name('admin.inquiry_getSearchIpInfo'); 273 Route::any('/getSearchIpInfo', [Aside\Projects\InquiryInfoController::class, 'getSearchIpInfo'])->name('admin.inquiry_getSearchIpInfo');