作者 刘锟

手动转发询盘

  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Optimize;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Http\Logic\Aside\Optimize\InquiryForwardLogic;
  8 +
  9 +class InquiryForwardController extends BaseController
  10 +{
  11 + /**
  12 + * 获取询盘转发列表
  13 + * @param InquiryForwardLogic $inquiryForwardLogic
  14 + * @author Akun
  15 + * @date 2025/02/21 10:55
  16 + */
  17 + public function lists(InquiryForwardLogic $inquiryForwardLogic)
  18 + {
  19 + if (isset($this->param['url'])) {
  20 + $this->map['url'] = ['like', '%' . $this->map['url'] . '%'];
  21 + }
  22 + if (isset($this->param['email'])) {
  23 + $this->map['email'] = ['like', '%' . $this->map['email'] . '%'];
  24 + }
  25 + if (isset($this->param['url_title'])) {
  26 + $this->map['url_title'] = ['like', '%' . $this->map['url_title'] . '%'];
  27 + }
  28 + if (isset($this->param['url_keyword'])) {
  29 + $this->map['url_keyword'] = ['like', '%' . $this->map['url_keyword'] . '%'];
  30 + }
  31 + $lists = $inquiryForwardLogic->getInquiryLists($this->map, $this->page, $this->row, $this->order);
  32 + $this->response('success', Code::SUCCESS, $lists);
  33 + }
  34 +
  35 + /**
  36 + * 获取询盘类型
  37 + * @param InquiryForwardLogic $inquiryForwardLogic
  38 + * @author Akun
  39 + * @date 2025/02/21 11:20
  40 + */
  41 + public function getInquiryType(InquiryForwardLogic $inquiryForwardLogic)
  42 + {
  43 + $list = $inquiryForwardLogic->getType();
  44 + $this->response('success', Code::SUCCESS, $list);
  45 + }
  46 +
  47 + /**
  48 + * 手动转发询盘
  49 + * @param InquiryForwardLogic $inquiryForwardLogic
  50 + * @throws \App\Exceptions\AsideGlobalException
  51 + * @throws \App\Exceptions\BsideGlobalException
  52 + * @author Akun
  53 + * @date 2025/02/21 14:54
  54 + */
  55 + public function forwardInquiry(InquiryForwardLogic $inquiryForwardLogic)
  56 + {
  57 + $this->validationParam();
  58 + $inquiryForwardLogic->inquiryForward();
  59 + $this->response('success');
  60 + }
  61 +
  62 + /**
  63 + * 手动转发询盘:参数验证
  64 + * @author Akun
  65 + * @date 2025/02/21 14:19
  66 + */
  67 + public function validationParam()
  68 + {
  69 + $this->request->validate([
  70 + 'id' => 'required',//ID
  71 + 'name' => 'required',//名称
  72 + 'email' => 'required',//邮箱
  73 + 'phone' => 'required',//电话号码
  74 + 'ip' => 'required',//ip
  75 + 'forward_url' => 'required',//转发网址
  76 + 'message' => 'required',//发送内容
  77 + 'inquiry_diff' => 'required',//发送时区
  78 + 'inquiry_date' => 'required',//发送时间
  79 + ], [
  80 + 'id.required' => 'ID不能为空',
  81 + 'name.required' => '名称不能为空',
  82 + 'email.required' => '邮箱不能为空',
  83 + 'phone.required' => '电话号码不能为空',
  84 + 'ip.required' => 'ip不能为空',
  85 + 'forward_url.required' => '转发网址不能为空',
  86 + 'message.required' => '内容不能为空',
  87 + 'inquiry_diff.required' => '发送时区不能为空',
  88 + 'inquiry_date.required' => '发送时间不能为空',
  89 + ]);
  90 + }
  91 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside\Optimize;
  4 +
  5 +use App\Http\Logic\Aside\BaseLogic;
  6 +use App\Models\Inquiry\InquiryInfo;
  7 +use App\Models\Inquiry\InquiryProject;
  8 +use App\Models\Inquiry\InquiryRelayDetail;
  9 +use Illuminate\Support\Facades\DB;
  10 +use Illuminate\Support\Facades\Log;
  11 +
  12 +/**
  13 + * @remark :询盘中心
  14 + * @class :InquiryForwardLogic.php
  15 + * @author :akun
  16 + * @time :2025/2/21 11:17
  17 + */
  18 +class InquiryForwardLogic extends BaseLogic
  19 +{
  20 +
  21 + public function __construct()
  22 + {
  23 + parent::__construct();
  24 + $this->param = $this->requestAll;
  25 + $this->model = new InquiryInfo();
  26 + }
  27 +
  28 + /**
  29 + * 获取类型
  30 + * @return array
  31 + * @author Akun
  32 + * @date 2025/02/21 11:19
  33 + */
  34 + public function getType()
  35 + {
  36 + return $this->success($this->model->typeMap());
  37 + }
  38 +
  39 + /**
  40 + * 获取列表
  41 + * @param $map
  42 + * @param $page
  43 + * @param $row
  44 + * @param string $order
  45 + * @param string[] $filed
  46 + * @return array
  47 + * @author Akun
  48 + * @date 2025/02/21 11:19
  49 + */
  50 + public function getInquiryLists($map, $page, $row, $order = 'id', $filed = ['*'])
  51 + {
  52 + $lists = $this->model->lists($map, $page, $row, $order, $filed);
  53 + return $this->success($lists);
  54 + }
  55 +
  56 + /**
  57 + * 转发询盘
  58 + * @return array
  59 + * @throws \App\Exceptions\AsideGlobalException
  60 + * @throws \App\Exceptions\BsideGlobalException
  61 + * @author Akun
  62 + * @date 2025/02/21 14:54
  63 + */
  64 + public function inquiryForward()
  65 + {
  66 + $info = $this->model->read(['id' => $this->param['id']]);
  67 + if ($info === false) {
  68 + $this->fail('获取询盘详情失败');
  69 + }
  70 + if ($info['status'] != InquiryInfo::STATUS_INIT) {
  71 + $this->fail('当前询状态无法转发');
  72 + }
  73 +
  74 + DB::beginTransaction();
  75 + try {
  76 + $num = 0;
  77 + foreach ($this->param['forward_url'] as $website) {
  78 + //获取站点对应项目版本
  79 + $project_version = InquiryProject::select(['version'])->where('domain', 'like', '%' . $website . '%')->orWhere('test_domain', 'like', '%' . $website . '%')->first();
  80 + if (!$project_version) {
  81 + continue;
  82 + }
  83 +
  84 + //计算发送时间
  85 + if ($this->param['inquiry_diff'] > 0) {
  86 + $start_at = date('Y-m-d H:i:s', strtotime($this->param['inquiry_date']) . ' -' . $this->param['inquiry_diff'] . ' hours');
  87 + } elseif ($this->param['inquiry_diff'] < 0) {
  88 + $start_at = date('Y-m-d H:i:s', strtotime($this->param['inquiry_date']) . ' +' . abs($this->param['inquiry_diff']) . ' hours');
  89 + } else {
  90 + $start_at = $this->param['inquiry_date'];
  91 + }
  92 +
  93 + InquiryRelayDetail::insert([
  94 + 'form_id' => $info['id'],
  95 + 'website' => $website,
  96 + 'country' => $info['country'],
  97 + 'ip' => $this->param['ip'],
  98 + 'name' => $this->param['name'],
  99 + 'email' => $this->param['email'],
  100 + 'phone' => $this->param['phone'],
  101 + 'message' => $this->param['message'],
  102 + 'is_v6' => $project_version->version == 6 ? 1 : 0,
  103 + 'start_at' => $start_at,
  104 + 'created_at' => date('Y-m-d H:i:s'),
  105 + 'updated_at' => date('Y-m-d H:i:s')
  106 + ]);
  107 +
  108 + $num += 1;
  109 + }
  110 +
  111 + //更改询盘状态及转发数量
  112 + $this->model->edit(['status' => 1, 'num' => $num], ['id' => $this->param['id']]);
  113 +
  114 + DB::commit();
  115 + } catch (\Exception $e) {
  116 + DB::rollback();
  117 +
  118 + Log::error('inquiry_forward error:' . $e->getMessage());
  119 + $this->fail('转发询盘失败');
  120 + }
  121 +
  122 + return $this->success();
  123 + }
  124 +}
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2024/9/30
  6 + * Time: 14:56
  7 + */
  8 +namespace App\Models\Inquiry;
  9 +
  10 +use Illuminate\Database\Eloquent\Model;
  11 +
  12 +/**
  13 + * 询盘转发详情
  14 + * Class ReInquiryDetail
  15 + * @package App\Models\Inquiry
  16 + */
  17 +class InquiryRelayDetail extends Model
  18 +{
  19 + /**
  20 + * @var string
  21 + */
  22 + protected $table = 'gl_inquiry_relay_detail';
  23 +
  24 + /**
  25 + * 任务状态, 0:初始化,1:待处理,2:处理成功,3:抛弃数据,9:处理失败
  26 + */
  27 + const STATUS_INIT = 0;
  28 + const STATUS_PEND = 1;
  29 + const STATUS_SUCCESS = 2;
  30 + const STATUS_FORGO = 3;
  31 + const STATUS_FAIL = 9;
  32 +
  33 + /**
  34 + * 状态映射
  35 + * @return array
  36 + */
  37 + public static function statusMap()
  38 + {
  39 + return [
  40 + self::STATUS_INIT => '初始化',
  41 + self::STATUS_PEND => '待处理',
  42 + self::STATUS_SUCCESS => '处理成功',
  43 + self::STATUS_FORGO => '抛弃数据',
  44 + self::STATUS_FAIL => '处理失败',
  45 + ];
  46 + }
  47 +
  48 + /**
  49 + * 创建询盘转发详情待处理任务
  50 + * @param $task_id
  51 + * @param $form_id
  52 + * @param $re_website
  53 + * @param $country
  54 + * @param $ip
  55 + * @param $name
  56 + * @param $email
  57 + * @param $phone
  58 + * @param $message
  59 + * @param $text_id
  60 + * @param $device_port
  61 + * @param $user_agent
  62 + * @param $referrer
  63 + * @param $urls
  64 + * @param $is_v6
  65 + * @param $start_at
  66 + * @param int $status
  67 + * @return ReInquiryDetail
  68 + */
  69 + public static function createInquiry($task_id, $form_id, $re_website, $country, $ip, $name, $email, $phone, $message, $text_id, $device_port,
  70 + $user_agent, $referrer, $urls, $is_v6, $start_at, $status = self::STATUS_INIT, $type = 1)
  71 + {
  72 + $self = new self();
  73 + $self->task_id = $task_id;
  74 + $self->form_id = $form_id;
  75 + $self->re_website = $re_website;
  76 + $self->country = $country;
  77 + $self->ip = $ip;
  78 + $self->name = $name;
  79 + $self->email = $email;
  80 + $self->phone = $phone;
  81 + $self->message = $message;
  82 + $self->text_id = $text_id;
  83 + $self->device_port = $device_port;
  84 + $self->user_agent = $user_agent;
  85 + $self->referrer = $referrer;
  86 + $self->urls = json_encode($urls);
  87 + $self->is_v6 = $is_v6;
  88 + $self->num = count($urls) + 1;
  89 + $self->start_at = $start_at;
  90 + $self->status = $status;
  91 + $self->type = $type;
  92 + $self->save();
  93 + return $self;
  94 + }
  95 +
  96 + /**
  97 + * 转发日志详情
  98 + * @return \Illuminate\Database\Eloquent\Relations\HasMany
  99 + */
  100 + public function detailLog()
  101 + {
  102 + return $this->hasMany(InquiryRelayDetailLog::class, 'detail_id', 'id');
  103 + }
  104 +}
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2024/10/08
  6 + * Time: 14:10
  7 + */
  8 +namespace App\Models\Inquiry;
  9 +
  10 +use Illuminate\Database\Eloquent\Model;
  11 +
  12 +/**
  13 + * 转发详情日志
  14 + * Class ReInquiryDetailLog
  15 + * @package App\Models\Inquiry
  16 + */
  17 +class InquiryRelayDetailLog extends Model
  18 +{
  19 + /**
  20 + * @var string
  21 + */
  22 + protected $table = 'gl_inquiry_relay_detail_log';
  23 +
  24 + /**
  25 + * 任务状态, 0:初始化,1:待处理,2:处理成功,9:处理失败
  26 + */
  27 + const STATUS_INIT = 0;
  28 + const STATUS_PEND = 1;
  29 + const STATUS_SUCCESS = 2;
  30 + const STATUS_FAIL = 9;
  31 +
  32 + /**
  33 + * 执行类型, 1:访问, 2:询盘
  34 + */
  35 + const TYPE_VISIT = 1;
  36 + const TYPE_INQUIRY = 2;
  37 +
  38 + /**
  39 + * 状态映射
  40 + * @return array
  41 + */
  42 + public static function statusMap()
  43 + {
  44 + return [
  45 + self::STATUS_INIT => '初始化',
  46 + self::STATUS_PEND => '待处理',
  47 + self::STATUS_SUCCESS => '处理成功',
  48 + self::STATUS_FAIL => '处理失败',
  49 + ];
  50 + }
  51 +
  52 +
  53 + /**
  54 + * 创建转发详情日志
  55 + * @param $detail_id
  56 + * @param $type
  57 + * @param $pre
  58 + * @param $url
  59 + * @param $start_at
  60 + * @return ReInquiryDetailLog
  61 + */
  62 + public static function createInquiryLog($detail_id, $type, $pre, $url, $start_at)
  63 + {
  64 + $self = self::where(compact('detail_id', 'type', 'pre'))->first();
  65 + if ($self)
  66 + return $self;
  67 + $self = new self();
  68 + $self->detail_id = $detail_id;
  69 + $self->type = $type;
  70 + $self->pre = $pre;
  71 + $self->url = $url;
  72 + $self->start_at = $start_at;
  73 + $self->save();
  74 + return $self;
  75 + }
  76 +}
@@ -340,6 +340,13 @@ Route::middleware(['aloginauth'])->group(function () { @@ -340,6 +340,13 @@ Route::middleware(['aloginauth'])->group(function () {
340 Route::any('/getInternalCount', [Aside\Optimize\InquiryInfoController::class, 'getInternalCount'])->name('admin.inquiry_getInternalCount'); 340 Route::any('/getInternalCount', [Aside\Optimize\InquiryInfoController::class, 'getInternalCount'])->name('admin.inquiry_getInternalCount');
341 }); 341 });
342 342
  343 + //手动转发询盘
  344 + Route::prefix('inquiry_forward')->group(function () {
  345 + Route::any('/', [Aside\Optimize\InquiryForwardController::class, 'lists'])->name('admin.inquiry_lists');
  346 + Route::any('/getInquiryType', [Aside\Optimize\InquiryForwardController::class, 'getInquiryType'])->name('admin.inquiry_getInquiryType');
  347 + Route::any('/forwardInquiry', [Aside\Optimize\InquiryForwardController::class, 'forwardInquiry'])->name('admin.inquiry_forwardInquiry');
  348 + });
  349 +
343 Route::prefix('custom_module')->group(function () { 350 Route::prefix('custom_module')->group(function () {
344 Route::any('/', [\App\Http\Controllers\Aside\CustomModule\CustomModuleController::class, 'lists'])->name('custom_lists'); 351 Route::any('/', [\App\Http\Controllers\Aside\CustomModule\CustomModuleController::class, 'lists'])->name('custom_lists');
345 Route::any('/save', [\App\Http\Controllers\Aside\CustomModule\CustomModuleController::class, 'save'])->name('custom_save'); 352 Route::any('/save', [\App\Http\Controllers\Aside\CustomModule\CustomModuleController::class, 'save'])->name('custom_save');