ReInquiryForm.php
3.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
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/9/30
* Time: 14:31
*/
namespace App\Models\Inquiry;
use App\Helper\Translate;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
/**
* 广告询盘表单内容
* Class ReInquiryForm
* @package App\Models\Inquiry
*/
class ReInquiryForm extends Model
{
/**
* @var string
*/
protected $table = 'gl_re_inquiry_form';
/**
* 任务状态, 1:待处理,2:处理成功,3:抛弃数据,9:处理失败
*/
const STATUS_INIT = 1;
const STATUS_SUCCESS = 2;
const STATUS_FORGO = 3;
const STATUS_FAIL = 9;
/**
* 状态映射
* @return array
*/
public static function statusMap()
{
return [
self::STATUS_INIT => '待处理',
self::STATUS_SUCCESS => '处理成功',
self::STATUS_FORGO => '抛弃数据',
self::STATUS_FAIL => '处理失败',
];
}
/**
* 创建询盘表单信息
* @param $id
* @param $origin_id
* @param $ad_set_id
* @param $ad_set_name
* @param $ad_id
* @param $ad_name
* @param $full_name
* @param $email
* @param $phone
* @param $whatsapp
* @param $message
* @param $country
* @param $inquiry_date
* @return mixed
*/
public static function createInquiry($id, $origin_id, $ad_set_id, $ad_set_name, $ad_id, $ad_name, $full_name, $email, $phone, $whatsapp, $message, $country, $inquiry_date)
{
if($country){
$country_name = self::getCountryName($country);
}
$self = self::where(['id' => $id])->first();
if (empty($self)) {
$self = new self();
// 同步 表单内容,以ID为唯一值
$self->id = $id;
}
$self->origin_id = $origin_id;
$self->ad_set_id = $ad_set_id;
$self->ad_set_name = $ad_set_name;
$self->ad_id = $ad_id;
$self->ad_name = $ad_name;
$self->full_name = $full_name;
$self->email = $email;
$self->phone = $phone;
$self->whatsapp = $whatsapp;
$self->message = $message;
$self->inquiry_date = $inquiry_date;
$self->country = $country;
$self->country_name = $country_name??'';
$self->save();
return $self;
}
public static function getCountryName($country){
if (strlen($country) == 2) {
$country = self::getCountry($country);
} else {
$country = Translate::tran($country, 'zh');
}
return $country;
}
public static function getCountry($code)
{
$cache_key = 'inquiry_world_country';
$country_code = Cache::get($cache_key, function () use ($cache_key) {
$country_code = DB::table('gl_world_country_city')->where(['pid' => 0])->pluck('chinese_name', 'iso2')->toArray();
Cache::put($cache_key, $country_code, 86400);
return $country_code;
});
return empty($country_code[$code]) ? '' : $country_code[$code];
}
}