InquiryForwardLogic.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace App\Http\Logic\Aside\Optimize;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Inquiry\InquiryInfo;
use App\Models\Inquiry\InquiryProject;
use App\Models\Inquiry\InquiryRelayDetail;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* @remark :询盘中心
* @class :InquiryForwardLogic.php
* @author :akun
* @time :2025/2/21 11:17
*/
class InquiryForwardLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new InquiryInfo();
}
/**
* 获取类型
* @return array
* @author Akun
* @date 2025/02/21 11:19
*/
public function getType()
{
return $this->success($this->model->typeMap());
}
/**
* 获取列表
* @param $map
* @param $page
* @param $row
* @param string $order
* @param string[] $filed
* @return array
* @author Akun
* @date 2025/02/21 11:19
*/
public function getInquiryLists($map, $page, $row, $order = 'id', $filed = ['*'])
{
$lists = $this->model->lists($map, $page, $row, $order, $filed);
return $this->success($lists);
}
/**
* 转发询盘
* @return array
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author Akun
* @date 2025/02/21 14:54
*/
public function inquiryForward()
{
$info = $this->model->read(['id' => $this->param['id']]);
if ($info === false) {
$this->fail('获取询盘详情失败');
}
if ($info['status'] != InquiryInfo::STATUS_INIT) {
$this->fail('当前询状态无法转发');
}
DB::beginTransaction();
try {
$num = 0;
$now = date('Y-m-d H:i:s');
foreach ($this->param['forward_url'] as $website) {
//获取站点对应项目版本
$project_version = InquiryProject::select(['version'])->where('domain', 'like', '%' . $website . '%')->orWhere('test_domain', 'like', '%' . $website . '%')->first();
if (!$project_version) {
continue;
}
//计算发送时间
if ($this->param['inquiry_diff'] > 0) {
$start_at = date('Y-m-d H:i:s', strtotime($this->param['inquiry_date'] . ' -' . $this->param['inquiry_diff'] . ' hours'));
} elseif ($this->param['inquiry_diff'] < 0) {
$start_at = date('Y-m-d H:i:s', strtotime($this->param['inquiry_date'] . ' +' . abs($this->param['inquiry_diff']) . ' hours'));
} else {
$start_at = $this->param['inquiry_date'];
}
if ($start_at < $now) {
$start_at = $now;
}
InquiryRelayDetail::insert([
'form_id' => $info['id'],
'website' => $website,
'country' => $info['country'],
'ip' => $this->param['ip'],
'name' => $this->param['name'],
'email' => $this->param['email'],
'phone' => $this->param['phone'],
'message' => $this->param['message'],
'is_v6' => $project_version->version == 6 ? 1 : 0,
'start_at' => $start_at,
'created_at' => $now,
'updated_at' => $now
]);
$num += 1;
}
//更改询盘状态及转发数量
$this->model->edit(['status' => 1, 'num' => $num], ['id' => $this->param['id']]);
DB::commit();
} catch (\Exception $e) {
DB::rollback();
Log::error('inquiry_forward error:' . $e->getMessage());
$this->fail('转发询盘失败');
}
return $this->success();
}
}