InquiryFormData.php
14.1 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
namespace App\Models\Inquiry;
use App\Helper\Arr;
use App\Helper\FormGlobalsoApi;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
/**
* Class InquiryFormData
* @package App\Models\Inquiry
* @author zbj
* @date 2023/12/4
*/
class InquiryFormData extends Base
{
use SoftDeletes;
//设置关联表名
/**
* @var mixed
*/
protected $connection = "custom_mysql";
protected $table = 'gl_inquiry_form_data';
/**
* 根据提交数据的key获取表单id
* @param $form_id
* @param $domain
* @param $ip
* @param $country
* @param $referer
* @param $user_agent
* @param $submit_at
* @param $data
* @return mixed
* @author zbj
* @date 2023/12/4
*/
public static function saveData($form_id, $domain, $ip, $country, $referer, $user_agent, $submit_at, $data, $project_id, $traffic = 0){
if(!empty($data['email'])){
$data['email'] = str_replace(' ', '', $data['email']);
}
if(!empty($data['phone'])){
$data['phone'] = str_replace(' ', '', $data['phone']);
}
//数据标识
$sign_data = $data;
ksort($sign_data);
if(!empty($sign_data['globalso-date'])){
unset($sign_data['globalso-date']);
}
if(!empty($sign_data['__amp_source_origin'])){
unset($sign_data['__amp_source_origin']);
unset($data['__amp_source_origin']);
}
$sign = md5(json_encode($sign_data));
//30分钟内是否有重复数据
$is_exist = self::where('sign', $sign)->where('created_at', '>', date('Y-m-d H:i:s', strtotime('-30 minute')))->first();
if($is_exist){
return 0;
}
if(!empty($data['name']) && !empty($data['email']) && !empty($data['message'])){
Log::channel('inquiry')->info('开始发邮件' . PHP_EOL);
unset($data['globalso-domain_host_url']);
unset($data['globalso-domain']);
unset($data['globalso-edition']);
unset($data['globalso-date']);
//推送邮件发送
foreach ($data as $k => $v){
if(empty($v)){
continue;
}
if(is_array($v) && !empty($v['path'])){
$v = getImageUrl($v['path']);
$data[$k] = $v;
}
if(is_string($v)){
$arr = json_decode($v, true);
if(is_array($arr)){
$v = implode('', Arr::formatForHtml($arr));
}
}
//其他字段补充到message里
if(!in_array($k, ['name', 'email', 'message', 'phone', 'ip', 'date', 'cname', 'domain', 'edition', 'domain_host_url'])){
$data['message'].= "<br/>" . $k .': ' . $v;
}
}
$res = (new FormGlobalsoApi())->submitInquiry($ip, $referer, $submit_at, $data, $traffic);
//自定义推送
if($project_id == 3870) { //走这里发送的,关杰那边也要取消发送邮件
list($mobile, $email) = self::SpecialMailPhone($referer);
Log::channel('inquiry')->info('自定义推送', [$mobile, $email]);
$body = self::specialInquiryTemplate($data['name'], $data['email'], $data['phone'] ?? "", $data['message'], $domain, $ip, $country);
(new FormGlobalsoApi())->customizeInquiryEmail($email, '询盘客户<' . $data['name'] . '>', $body, $ip, $referer, $submit_at);
(new FormGlobalsoApi())->customizeInquirySms($mobile, $country, $domain);
}
Log::channel('inquiry')->info('询盘发送邮件', [$data, $res]);
if(!$res){
throw new \Exception('询盘发送邮件失败');
}
}
$model = new self();
$model->form_id = $form_id;
$model->domain = $domain;
$model->ip = $ip;
$model->country = $country;
$model->referer = $referer;
$model->user_agent = $user_agent;
$model->submit_at = $submit_at;
$model->data = $data;
$model->sign = $sign;
$model->save();
return $model->id;
}
/**
* 获取推送邮箱和手机号
* 邮件地址和手机号 根据链接匹配,没匹配到随机取一个邮件和手机号
* @param $referer
* @author zbj
* @date 2025/10/25
*/
public static function SpecialMailPhone($referer)
{
$mail_mobile_map = [
'luchfitness' => [15262817624, 'Sales02@luchfitness.com'],
'modernsporting' => [13073258707,'sales@modernsporting.com'],
'liveupsports' => [18355892630,'sales@liveupsports.com'],
'topflor' => [13912296731,'alan@topflor.cn'],
];
$url_map = [
'luchfitness' => [
'/supplier/nantong-luch-fitness-co-ltd',
'/benches-machines-luch-fitness',
'/free-weight-luch-fitness',
'/functional-training-luch-fitness/s',
'/studio-exercise-luch-fitness',
'/commercial-gym-half-power-rack-for-strength-training-product',
'/heavy-duty-fitness-flat-bench-for-home-commercial-gym-product',
'/durable-gym-dumbbell-flat-bench-for-weight-training-product',
'/rubber-colored-bumper-plate-for-olympic-weightlifting-product',
'/urethane-competition-bumper-plate-for-strength-training-product',
'/10-pair-dumbbell-storage-rack-for-commercial-gyms-product',
'/tpu-coated-dumbbells-for-home-and-commercial-fitness-product',
'/urethane-weight-plate-for-powerlifting-strength-gym-product',
'/iphifun-cpu-weight-plate-for-professional-training-product',
'/men-s-weightlifting-barbell-bar-for-strength-training-product',
'/women-s-weightlifting-barbell-bar-for-olympic-lifts-product',
'/steel-competition-kettlebell-for-functional-training-product',
'/adjustable-strength-jump-plyo-boxes-for-gym-training-product',
'/commercial-soft-plyo-box-for-functional-gym-training-product',
'/power-training-weight-bull-bag-for-strength-workout-product',
'/pu-leather-power-bag-for-functional-strength-training-product',
'/abdominal-muscle-mat-for-core-and-sit-up-training-product',
'/gymnastics-training-mat-for-fitness-and-yoga-workout-product',
'/adjustable-bench-stepper-for-aerobic-and-strength-gym-product',
'/rubber-body-pump-set-for-cardio-and-strength-training-product',
'/balance-training-yoga-ball-for-core-stability-workout-product',
'/pull-up-resistance-band-for-strength-and-stretching-product',
],
'modernsporting' => [
'/supplier/nantong-modern-sporting-industrial-co-ltd',
'/barbell-bars-modern-sporting',
'/storage-racks-modern-sporting',
'/dumbbells-modern-sporting',
'/rubber-plates-modern-sporting',
'/training-handles-modern-sporting',
'/md4137-201cm-weightlifting-beginner-bar-product',
'/md4143-220cm-hybrid-training-bar-product',
'/md4149-powder-coated-pentagon-bar-product',
'/gym-home-10-pairs-dumbbell-rack-stand-md6242-product',
'/10-pairs-dumbbell-rack-for-home-gym-workouts-md6247-product',
'/10-pairs-dumbbell-storage-rack-for-gym-home-md6250-product',
'/urethane-dumbbells-set-for-strength-training-md2117-product',
'/md2123-rubber-coated-studio-dumbbells-product',
'/md2135-12-side-tpu-coated-dumbbells-product',
'/rubber-bumper-plates-for-weightlifting-gym-use-md1056-product',
'/high-quality-rubber-bumper-plates-for-gym-lifting-md1057-product',
'/md1058-competition-weight-plates-product',
'/tricep-press-down-bar-for-cable-machines-strength-md5128-product',
'/md5132-tricep-press-down-bar-product',
'/md5132-tricep-press-down-bar-product',
],
'liveupsports' => [
'/supplier/nantong-liveup-sports-co-ltd',
'/yoga-pilates-liveup-sports',
'/training-equipment-liveup-sports',
'/gym-racks-and-equipment-liveup-sports',
'/20-25-30cm-pvc-customised-pilates-stability-exercise-ball-inflatable-soft-mini-pilates-small-yoga-bal-product',
'/55-65-75cm-bloom-workout-fitness-exercise-balance-gym-abs-anti-burst-yoga-ball-anti-slip-swiss-pilates-ball-product',
'/bodybuilding-fitness-exercise-custom-logo-gym-yoga-latex-hip-resistance-bands-loop-bands-set-product',
'/bloom-2080x4-5cm-natural-latex-loop-yoga-elastic-stretch-long-resistance-bands-exercise-band-product',
'/custom-logo-manufacturer-high-quality-eco-friendly-fitness-pilates-anti-slip-3-10mm-pu-rubber-tpe-cork-nbr-pvc-printed-yoga-mat-product',
'/custom-professional-manufacture-cheap-solid-cast-iron-dumbbell-weights-rubber-hex-dumbbell-sets-5-100lb-product',
'/professional-wholesale-custom-logo-free-weight-colored-rubber-bumper-gym-weight-barbell-plates-with-kg-mark-product',
'/gym-equipment-free-weights-fitness-12-sided-weightlifting-exercise-barbell-weight-lifting-polyurethane-fixed-barbell-product',
'/livepro-high-quality-steel-fitness-equipment-training-competition-gym-power-weightlifting-20kg-barbell-bar-product',
'/livepro-gym-commercial-equipment-fitness-storage-system-professional-multifunctional-training-frame-gym-storage-rack-product',
'/livepro-commercial-floor-mount-free-standing-cross-training-gym-rigs-multi-functional-training-rack-fitness-gym-rig-product',
'/livepro-oem-odm-fitness-equipment-multi-functional-trainer-smith-machine-station-home-using-gym-full-frame-cage-squat-power-rack-product',
],
'topflor' => [
'/supplier/nantong-topflor-co-ltd',
'/sports-flooring-topflor',
'/healthcare-flooring-topflor',
'/gym-flooring-topflor',
'/sprint-track-turf-for-high-performance-indoor-and-outdoor-training-product',
'/durable-gym-rubber-flooring-with-shock-absorption-and-slip-resistance-product',
'/interlocking-gym-flooring-tilesinterlocking-gym-flooring-tiles-product',
'/premium-hospital-vinyl-flooring-with-anti-bacterial-and-easy-clean-surface-product',
'/high-performance-healthcare-flooring-for-safe-and-hygienic-environments-product',
'/homogeneous-vinyl-flooring-with-high-durability-and-low-maintenance-product',
'/clinic-vinyl-flooring-with-anti-bacterial-and-wear-resistant-properties-product',
'/medical-pvc-flooring-with-anti-slip-hygienic-and-durable-features-product',
'/professional-badminton-court-pvc-sports-flooring-with-high-grip-and-shock-absorption-product',
'/indoor-basketball-sports-flooring-with-superior-ball-bounce-and-player-comfort-product',
'/multi-sport-indoor-pvc-flooring-for-volleyball-handball-badminton-and-fitness-product',
'/durable-multi-purpose-sports-flooring-for-schools-gyms-and-community-centers-product',
'/high-performance-multi-use-indoor-sports-flooring-with-easy-maintenance-product',
],
];
foreach ($url_map as $k=>$urls) {
foreach ($urls as $url) {
if(Str::contains(strtolower($referer), strtolower($url))){
return $mail_mobile_map[$k];
}
}
}
return $mail_mobile_map[array_rand($mail_mobile_map)];
}
/**
* 特殊项目 邮件模版
* FIXME 后期有多个特殊项目,需要按照项目ID设置模板
* @param $name
* @param $email
* @param $phone
* @param $message
* @param $domain
* @param $country
* @return string
*/
public static function specialInquiryTemplate($name, $email, $phone, $message, $domain, $ip, $country)
{
$template = "
客户姓名:$name
客户邮箱:$email
客户电话:$phone
--------------------------------------------------------------------
询盘内容:
$message
--------------------------------------------------------------------
发送询盘网址: $domain
客户IP地址: $ip
IP所在国家/地区: $country
--------------------------------------------------------------------";
return $template;
}
public function setDataAttribute($value)
{
$this->attributes['data'] = json_encode($value);
}
public function getDataAttribute($value)
{
return json_decode($value, true);
}
/**
* 非默认表单的数量统计
* @author zbj
* @date 2023/12/12
*/
public static function getCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->count();
}
/**
* 非默认表单的国家统计
* @author zbj
* @date 2023/12/12
*/
public static function getCountryCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
}
}