InquiryInfoLogic.php
6.2 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
namespace App\Http\Logic\Aside\Projects;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\InquiryIP;
use App\Models\Projects\InquiryInfo;
use App\Models\Projects\InquiryUser;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\Scheduling\Schedule;
/**
* @remark :询盘中心
* @class :InquiryInfoLogic.php
* @author :lyh
* @time :2023/7/11 15:20
*/
class InquiryInfoLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new InquiryInfo();
//TODO::测试数据
$this->manager = [
'id'=>1,
'name'=>'cs'
];
}
/**
* @remark :获取列表
* @name :getInquiryLists
* @author :lyh
* @method :post
* @time :2023/7/11 15:25
*/
public function getInquiryLists($map,$page,$row,$order = 'id',$filed = ['*']){
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :自定义添加特殊询盘信息
* @name :inquirySave
* @author :lyh
* @method :post
* @time :2023/7/12 9:22
*/
public function inquirySave(){
try {
$this->inquiryInfoSave();
}catch (\Exception $e){
$this->fail('error');
}
return $this->success();
}
/**
* @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);
}
/**
* @remark :逻辑删除
* @name :inquiryInfoDel
* @author :lyh
* @method :post
* @time :2023/7/12 14:15
*/
public function inquiryInfoDel(){
DB::beginTransaction();
try {
$this->model->del(['id'=>$this->param['id']]);
$inquiryUserModel = new InquiryUser();
$inquiryUserModel->del(['xp_id'=>$this->param['id']]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
return $this->success();
}
/**
* @remark :转发详情
* @name :inquiryForwardInfo
* @author :lyh
* @method :post
* @time :2023/7/12 17:43
*/
public function inquiryForwardInfo(){
$inquiryUserModel = new InquiryUser();
$info = $inquiryUserModel->read(['xp_id'=>$this->param['id']]);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @remark :导入保存数据
* @name :ImportInquiryInfoSave
* @author :lyh
* @method :post
* @time :2023/7/13 10:59
*/
public function ImportInquiryInfoSave($row){
$this->param = [
'name'=>$row[0],
'email'=>$row[1],
'phone'=>$row[2],
'ip'=>$row[3],
'ip_area'=>$row[4],
'message'=>$row[5],
'type'=>$row[6],
'forward_url'=>$row[7],
'delay'=>$row[8],
];
$this->inquirySave();
return $this->success();
}
/**
* @remark :根据国家获取随机ip
* @name :getSearchIp
* @author :lyh
* @method :post
* @time :2023/7/13 11:43
*/
public function getSearchIp(){
$inquiryIpModel = new InquiryIP();
$info = $inquiryIpModel->where($this->param)->inRandomOrder()->first();
return $this->success($info);
}
/**
* @remark :根据时间转发
* @name :forwardTime
* @author :lyh
* @method :post
* @time :2023/7/13 17:39
*/
public function forwardTime($param){
if($param['delay'] == 0){
$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);
}
})->cron($scheduledTime);
// 获取任务调度的命令行参数
$parameters = $schedule->dueEvents($schedule->events());
// 执行命令行任务
Artisan::call($parameters);
}
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);
}
}