InquiryLogic.php
4.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
<?php
namespace App\Http\Logic\Bside\Inquiry;
use App\Helper\Arr;
use App\Helper\FormGlobalsoApi;
use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryOther;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryLogic
* @package App\Http\Logic\Bside
* @author zbj
* @date 2023/5/4
*/
class InquiryLogic extends BaseLogic
{
protected $form_globalso_api;
public function __construct()
{
parent::__construct();
$this->form_globalso_api = new FormGlobalsoApi();
}
public function getApiList($export = false)
{
$page_size = $export ? 1000 : 20;
$search = $this->request['search'] ?: '';
$page = $this->request['page'] ?: 1;
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = (!empty(
$project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$list = $this->form_globalso_api->getInquiryList($domain, $search, $page, $page_size);
//处理格式 免得前端又改
$data = [
"list" => [],
"total" => 0,
"page" => $page,
"total_page" => 1,
"size" => $page_size
];
if (!empty($list['status']) && $list['status'] == 200) {
foreach ($list['data']['data'] as $item) {
$data['list'][] = $item;
}
$data['total'] = $list['data']['total'];
$data['total_page'] = $list['data']['last_page'];
}
return $this->success($data);
}
public function getOtherList($export = false){
$page_size = $export ? 1000 : 20;
$search = $this->request['search'] ?: '';
$page = $this->request['page'] ?: 1;
$map = [];
if($search){
$map['email'] = ['like','%'.$search.'%'];
}
ProjectServer::useProject($this->user['project_id']);
$data = (new InquiryOther())->lists($map,$page,$page_size,'id',
['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time']
);
return $this->success($data);
}
public function getInfo($id)
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
//修改状态为已读
if($this->request['read_status']){
$this->form_globalso_api->saveInquiryRead($domain, $id);
}
//翻译
$trans_message = '';
if($this->request['message']){
$trans_message = Translate::tran($this->request['message'], 'zh');
}
return $this->success(['trans_message' => $trans_message]);
}
public function getOtherInfo($id){
//修改状态为已读
if($this->request['read_status']){
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->edit(['status' => 1], ['id' => $id]);
}
return $this->success(['trans_message' => '']);
}
public function delete($ids, $map = [])
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
$this->form_globalso_api->delInquiry($domain, $ids);
return $this->success();
}
public function deleteOther($ids, $map = [])
{
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->del(['id'=>['in',$ids]]);
return $this->success();
}
}