InquiryDelay.php 2.4 KB
<?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));
                }
            }
        }
        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;
        $header = array(
            'CLIENT-IP: '.$post_data['ip'],
            'X-FORWARDED-FOR: '.$post_data['ip']
        );
        return http_post($url,$post_data_new,$header);
    }
}