ReInquiryCount.php
4.7 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
<?php
namespace App\Models\Inquiry;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Base;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\Task\TaskOwner;
use App\Services\DingService;
use App\Utils\HttpUtils;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
/**
* Class ReInquiryCount
* @package App\Models\Inquiry
* @author zbj
* @date 2024/10/25
*/
class ReInquiryCount extends Base
{
/**
* @var string
*/
protected $table = 'gl_re_inquiry_count';
/**
* @param $task_id
* @param $domain
* @param int $num
* @author zbj
* @date 2024/10/26
*/
public static function addInquiryNum($task_id, $domain, $num = 1, $type = 1, $company = '')
{
$model = self::where('domain', $domain)->first();
if (!$model) {
if($type == 1) {
//新增时获取公司名
$company = '';
$domain_info = DomainInfo::where('domain', $domain)->first();
if ($domain_info) {
$company = Project::where('id', $domain_info['project_id'])->value('company');
} else {
$res = (new QuanqiusouApi())->getV5Agent($domain);
if (!empty($res['status']) && $res['status'] == 200) {
$company = $res['company_name'];
}
}
}
if($type == 2){
$company = $domain;
}
if($type == 3){
$fob_list = self::getFobProjects();
$fob = collect($fob_list)->where('postid', $domain)->first();
$company = $fob['company'] . ' - ' . $fob['plan'];
}
$model = new self();
$model->domain = $domain;
$model->company = $company;
$model->type = $type;
}
$model->task_ids = $model->task_ids + [$task_id];
$model->num = $model->num + $num;
$model->save();
//数量首次达到100, 给钉钉推送消息
if($num > 0 && $model->num == 100){
(new DingService())->handle([
'keyword' => '询盘数量通知',
'msg' =>
'项目名称:' . $model->company . PHP_EOL .
'项目域名:' . $model->domain . PHP_EOL .
'询盘数量:' . $model->num,
'isAtAll' => false, // 是否@所有人
], 'https://oapi.dingtalk.com/robot/send?access_token=cd5733d3e6b810a501e3ea20df7c99ecb616aa6754fa048348837d088c1f5b2c');
}
}
public function setTaskIdsAttribute($value)
{
$this->attributes['task_ids'] = Arr::arrToSet($value);
}
public function getTaskIdsAttribute($value)
{
return Arr::setToArr($value);
}
public function getTasksAttribute()
{
$cache_key = 'ReInquiryCountTasks_' . Arr::arrToSet($this->task_ids);
$tasks = Cache::get($cache_key);
if (!$tasks) {
$tasks = ReInquiryTask::whereIn('id', $this->task_ids)->select(['title', 'industry', 'target', 'status'])->get()->toArray();
foreach ($tasks as &$task) {
$target = collect($task['target'])->where('url', $this->domain)->first();
$task['is_del'] = $target ? 0 : 1;
$task['agent'] = $target['agent'] ?? '';
$task['is_v6'] = $target['is_v6'] ?? '';
$task['agent_group'] = $target['agent_group'] ?? '';
unset($task['target']);
}
Cache::put($cache_key, $tasks, 7200);
}
return $tasks;
}
public static function getFobProjects(){
$cache_key = 'GET_BIND_PROJECT_LIST';
$res = Cache::get($cache_key);
if(!$res){
$res = HttpUtils::get('https://fob.ai.cc/api/get_bind_project_list', []);
$res = json_decode($res, true)['data'] ?? [];
Cache::put($cache_key, $res, 2 * 3600);
}
return $res;
}
public static function getRemainingDays($domain, $type, $project_id)
{
$cache_key = 're_inquiry_count_' . $domain . '_' . date('Ymd');
$data = Cache::get($cache_key);
if($data === null){
if($project_id){
$data = Project::where('id', $project_id)->value('remain_day');
}else if($type == 3){
$data = '-';
}else{
$res = (new QuanqiusouApi())->getV5RemainDay($domain);
$data = $res['data']['remain_day'] ??'-';
}
Cache::put($cache_key, $data, 24 * 3600);
}
return $data;
}
}