ReInquiryCount.php
2.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
<?php
namespace App\Models\Inquiry;
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 Illuminate\Database\Eloquent\Model;
/**
* 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)
{
$model = self::where('domain', $domain)->first();
if (!$model) {
//新增时获取公司名
$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'];
}
}
$model = new self();
$model->domain = $domain;
$model->company = $company;
}
$model->task_ids = $model->task_ids + [$task_id];
$model->num = $model->num + $num;
$model->save();
}
public function setTaskIdsAttribute($value)
{
$this->attributes['task_ids'] = Arr::arrToSet($value);
}
public function getTaskIdsAttribute($value)
{
return Arr::setToArr($value);
}
public function getTasksAttribute(){
$tasks = ReInquiryTask::whereIn('id', $this->task_ids)->select(['title', 'industry','target'])->get()->toArray();
foreach ($tasks as &$task){
$target = collect($task['target'])->where('url', $this->domain)->first();
$task['agent'] = $target['agent'] ?? '';
$task['is_v6'] = $target['is_v6'] ?? '';
$task['agent_group'] = $target['agent_group'] ?? '';
unset($task['target']);
}
return $tasks;
}
}