Setting.php
2.94 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
<?php
// +----------------------------------------------------------------------
// | Description: 客户模块设置
// +----------------------------------------------------------------------
// | Author: 瑄客CRM
// +----------------------------------------------------------------------
namespace addons\antis\controller;
use addons\antis\model\Customer;
use addons\antis\model\Staff;
/**
* 客户模块设置
*/
class Setting extends StaffApi
{
/**
* 获取团队成员
*/
public function team()
{
$id = input('id');
$customer = Customer::get($id);
if (empty($customer)) {
$this->error('客户不存在');
}
$owner_staff = Staff::where(['id' => $customer->owner_staff_id])->find();
$rw_staffs = Staff::where(['id' => ['in', explode(',', $customer->rw_staff_id)]])->select();
$ro_staffs = Staff::where(['id' => ['in', explode(',', $customer->ro_staff_id)]])->select();
$staffs = [];
if ($owner_staff) {
$staffs[] = [
'id' => $owner_staff->id,
'name' => $owner_staff->name,
'img' => $owner_staff->img,
'post' => $owner_staff->post,
'mobile' => $owner_staff->mobile,
'roles' => 1,
'is_edit' => 1,
];
}
foreach ($rw_staffs as $v) {
$staffs[] = [
'id' => $v->id,
'name' => $v->name,
'img' => $v->img,
'post' => $v->post,
'mobile' => $v->mobile,
'roles' => 2,
'is_edit' => 1,
];
}
foreach ($ro_staffs as $v) {
$staffs[] = [
'id' => $v->id,
'name' => $v->name,
'img' => $v->img,
'post' => $v->post,
'mobile' => $v->mobile,
'roles' => 2,
'is_edit' => 0,
];
}
$this->success('请求成功', $staffs);
}
/**
* 修改团队成员
*/
public function editShowStaff()
{
$id = input('id');
$staff = input('staff/a');
$model = Customer::get($id);
if (empty($model)) {
$this->error('客户不存在');
}
$ro_staff_id = [];
$rw_staff_id = [];
foreach ($staff as $v) {
if ($v['is_edit'] == 1) {
$rw_staff_id[] = $v['id'];
} else {
$ro_staff_id[] = $v['id'];
}
}
$ro_staff_id = array_diff($ro_staff_id, $rw_staff_id);
$rw_staff_id=implode(',', $rw_staff_id);
$ro_staff_id=implode(',', $ro_staff_id);
$result = $model->save(['rw_staff_id' => ",{$rw_staff_id},",
'ro_staff_id' => ",{$ro_staff_id},"]);
if ($result === false) {
$this->error('修改失败');
}
$this->success('修改成功');
}
}