作者 lyh

gx

<?php
namespace App\Console\Commands;
use App\Models\Projects\InquiryInfo;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
/**
* @remark :
* @class :InquiryDelay.php
* @author :lyh
* @time :2023/7/14 10:16
*/
class InquiryDelay extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'inquiry_delay';
/**
* The console command description.
*
* @var string
*/
protected $description = '延时询盘转发';
/**
* @remark :延时询盘转发
* @name :handle
* @author :lyh
* @method :post
* @time :2023/7/14 10:17
*/
public function handle()
{
$inquiryInfoModel = new InquiryInfo();
$param = $inquiryInfoModel->formatQuery(['status'=>0,'delay'=>['!=',0]])->orderBy('send_time','asc')->first();
if($param !== false){
$time = date('Y-m-d H:i:s');
if($time >= $param['send_time']){
$data = [];
//TODO::处理转发的url
$arr_url = explode(',',$param['forward_url']);
foreach ($arr_url as $v){
$data['url'] = $v;
$this->inquiryForward($data);
Log::info('询盘转发记录'.json_encode($data),'debug------------------info');
}
}
}
return true;
}
/**
* @remark :询盘转发
* @name :inquiryForward
* @author :lyh
* @method :post
* @time :2023/7/13 14:39
*/
public function inquiryForward($post_data){
$url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f';
$post_data_new = [];
$post_data_new['refer'] = $post_data['url'];
$post_data_new['name'] = $post_data['name'];
$post_data_new['email'] = $post_data['email'];
$post_data_new['phone'] = $post_data['phone'];
$post_data_new['ip'] = $post_data['ip'];
$post_data_new['message'] = $post_data['message'];
$post_data_new['submit_time'] = date('Y-m-d H:i:s',time()+20);
$token = md5($post_data_new['refer'].$post_data_new['name'].$post_data_new['ip'].date("Y-m-d",time()));
$post_data_new['token'] = $token;
return http_post($url,$post_data_new);
}
}
... ...
... ... @@ -30,6 +30,7 @@ class Kernel extends ConsoleKernel
$schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每周执行一次
$schedule->command('sync_project')->everyMinute()->withoutOverlapping(1); //同步项目
$schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
$schedule->command('inquiry_delay')->everyMinute()->withoutOverlapping(1);//每分钟执行一次
// // 更新域名|证书结束时间,每天凌晨1点执行一次
// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
// // B站 - 网站数据统计
... ...
... ... @@ -52,41 +52,21 @@ class InquiryInfoLogic extends BaseLogic
* @time :2023/7/12 9:22
*/
public function inquirySave(){
try {
$this->inquiryInfoSave();
}catch (\Exception $e){
$this->param['user_id'] = $this->manager['id'];
$this->param['user_name'] = $this->manager['name'];
$this->param['send_time'] = date('Y-m-d H:i:s',time() + $this->param['delay'] * 60 * 60) ;
$xp_id = $this->model->insertGetId($this->param);
if(!$xp_id){
$this->fail('error');
}
return $this->success();
//延时时间为0时,询盘转发
if($this->param['delay'] == 0){
$this->forwardTime($xp_id);
}
/**
* @remark :保存询盘记录表
* @name :inquiryInfoSave
* @author :lyh
* @method :post
* @time :2023/7/12 11:12
*/
public function inquiryInfoSave(){
//组装数据
$param = [
'name'=>$this->param['name'],
'email'=>$this->param['email'],
'phone'=>$this->param['phone'],
'ip'=>$this->param['ip'],
'ip_area'=>$this->param['ip_area'],
'message'=>$this->param['message'],
'type'=>$this->param['type'],
'user_id'=>$this->manager['id'],
'user_name'=>$this->manager['name'],
'forward_url'=>$this->param['forward_url'],
'delay'=>$this->param['delay'],
];
return $this->model->add($param);
return $this->success();
}
/**
* @remark :逻辑删除
* @name :inquiryInfoDel
... ... @@ -167,32 +147,24 @@ class InquiryInfoLogic extends BaseLogic
* @method :post
* @time :2023/7/13 17:39
*/
public function forwardTime($param){
public function forwardTime($xp_id){
$data = [];
//获取数据详情
$param = $this->model->read(['id'=>$xp_id]);
if($param['delay'] == 0){
$data = $param;
$arr_url = explode(',',$param['forward_url']);
foreach ($arr_url as $v){
$param['url'] = $v;
$this->inquiryForward($param);
}
}else{
// 获取执行时间
$scheduledTime = date('Y-m-d H:i:s',time() + $this->param['delay'] * 60 * 60);
$schedule = new Schedule;
// 定义定时任务
$schedule->call(function () use ($param) {
// 任务执行的代码
$arr_url = explode(',',$param['forward_url']);
foreach ($arr_url as $v){
$param['url'] = $v;
$this->inquiryForward($param);
$data['url'] = $v;
$this->inquiryForward($data);
}
//更新数据库,修改状态为已转发
$rs = $this->model->edit(['status'=>3],['id'=>$xp_id]);
if($rs === false){
$this->fail('error');
}
})->cron($scheduledTime);
// 获取任务调度的命令行参数
$parameters = $schedule->dueEvents($schedule->events());
// 执行命令行任务
Artisan::call($parameters);
}
return true;
return $this->success();
}
/**
... ...