2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
|
<?php
namespace app\admin\controller\antis\record;
use addons\antis\model\Field;
use addons\antis\model\File;
use addons\antis\model\Remind;
use addons\antis\model\Staff;
use addons\antis\model\Customer;
use app\admin\controller\antis\Base;
use addons\antis\model\Contacts;
use addons\antis\model\Contract;
use addons\antis\model\Leads;
use addons\antis\model\Business;
use addons\antis\model\Comment;
use addons\antis\model\Record as RecordModel;
use app\admin\model\AuthGroup;
use think\DB;
use think\Exception;
/**
* 客户跟进记录
*/
class Record extends Base {
public function _initialize() {
parent::_initialize();
$this->model = new RecordModel();
}
/**
* 客户跟进记录
*/
public function index() {
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage,则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
//$staff_ids = [14,37,38,39,40,41,42,106];
//$wheres['create_staff_id'] = ['in',$staff_ids];
$list = $this->model
->with('staff')
->where($where)
//->where($wheres)
//->whereTime('createtime','last month')
->order($sort, $order)
->paginate($limit);
foreach ($list as &$v){
if($v['relation_type'] == RecordModel::CUSTOMER_TYPE) {
$v['relation_name'] = Customer::where(['id' => $v['relation_id']])->value('name');
}elseif($v['relation_type'] == RecordModel::CONTACTS_TYPE) {
$v['relation_name'] = Contacts::where(['id' => $v['relation_id']])->value('name');
}elseif($v['relation_type'] == RecordModel::CONTRACT_TYPE) {
$v['relation_name'] = Contract::where(['id' => $v['relation_id']])->value('name');
}elseif($v['relation_type'] == RecordModel::LEADS_TYPE) {
$v['relation_name'] = Leads::where(['id' => $v['relation_id']])->value('name');
} elseif($v['relation_type'] == RecordModel::BUSINESS_TYPE) {
$v['relation_name'] = Business::where(['id' => $v['relation_id']])->value('name');
}
}
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
public function export(){
$param = $this->request->param();
$where = [];
if(!empty($param['time'])){
$time = explode(' - ',$param['time']);
$where['follow_time'] = ['between',[$time[0],$time[1]]];
}
$list = (new Staff())->where('status', '1')->where('deletetime','null')->select();
$data = [];
foreach ($list as $item){
$group_ids = $item['group_ids'];
$group_name =implode(',',AuthGroup::where("find_in_set(id, '$group_ids')")->column('name'));
$count = $this->model->where('create_staff_id',$item['id'])->where($where)->count();
$data[]=[
'staff'=>$item['name'], //姓名
'group_name'=>$group_name,
'post'=>$item['post'],
'count'=>$count
];
}
$title = [
'姓名',
'部门',
'岗位',
'跟进数量'
];
$file = export_excel($title, $data, '跟进统计');
if ($file['filePath']) {
$this->success('导出成功', '', $file);
}
$this->error('导出失败');
}
/**
* 添加跟进
*/
public function add($ids = null) {
$relation_type=input('relation_type',1);
if ($this->request->isPost()) {
$params = $this->request->post('row/a');
// 表单验证
if (($result = $this->qingdongValidate($params, 'Record', 'create')) !== true) {
$this->error($result);
}
if(!empty($params['files'])){
$params['files']=File::getId($params['files']);
}
Db::startTrans();
try {
$result = $this->model::createRecord($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result) {
$this->success('创建跟进记录成功');
}
$this->error('创建失败');
}
$follow= Field::getField('客户状态');
$customer=Customer::getList();
$customers = [];
foreach($customer as $k=>$v){
$customers[$v['id']] = $v['name'];
}
if($relation_type == 2){
$contacts=Contacts::where(['id'=>$ids])->column('id,name');
$this->assign('contacts',$contacts);
}
$remind=Remind::where(['type'=>Remind::RECORD_TYPE])->find();
$staff_ids=$remind['staff_ids']??'';
$this->assign('staff_ids', $staff_ids);
$this->assign('ids', $ids);
$this->assign('relation_type', $relation_type);
$this->assign('customer', $customers);
$this->assign('follow', $follow);
$this->assign('staff', Staff::where([])->column('name','id'));
return $this->view->fetch();
}
/**
* 跟进详情
*/
public function detail($ids = null) {
$row = $this->model->with(['staff','file'])->where([
'id' => $ids,
])->find();
if (empty($row)) {
$this->error(__('No Results were found'));
}
$row = $row->toArray();
if($row['staff_id']){
$createname = Staff::where(['id'=>$row['staff_id']])->value('name');
}else{
$createname = isset($row['staff']['name']) ? $row['staff']['name'] : '';
}
$row['createname'] = $createname;
$this->assign('row', $row);
$this->assignconfig("idinfo", ['id' => $ids]);
return $this->view->fetch();
}
/**
* 评论
*/
public function comment() {
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
$record_id = input('record_id','');
$wheres['relation_id'] = $record_id;
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = Comment::where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit);
$row = $list->items();
$result = array("total" => $list->total(), "rows" => $row);
return json($result);
}
return $this->view->fetch();
}
}
|