|
|
@@ -57,27 +57,34 @@ class Customer extends Base
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 查看
|
|
|
+ * 查看111
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
|
+ $staff = Staff::info();
|
|
|
+ $staff_id = $staff->id;
|
|
|
if ($this->request->isAjax()) {
|
|
|
+
|
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
//0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
|
|
|
$type = input('type', 0);
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
- $staff = Staff::info();
|
|
|
- $staff_id = $staff->id;
|
|
|
+
|
|
|
switch ($type) {
|
|
|
case 1://我负责
|
|
|
- $wheres['owner_staff_id'] = $staff_id;
|
|
|
+ $wheres[] = Db::raw("FIND_IN_SET($staff_id, owner_staff_id)");
|
|
|
break;
|
|
|
case 2://下属负责
|
|
|
- $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
|
|
|
+ $lowerStaffIds = Staff::getLowerStaffId();
|
|
|
+ $subConditions = [];
|
|
|
+ foreach ($lowerStaffIds as $id) {
|
|
|
+ $subConditions[] = Db::raw("FIND_IN_SET($id, owner_staff_id)");
|
|
|
+ }
|
|
|
+ $wheres[] = Db::raw('(' . implode(' OR ', $subConditions) . ')');
|
|
|
break;
|
|
|
case 3:
|
|
|
$start = date('Y-m-d 00:00:00');
|
|
|
@@ -91,11 +98,10 @@ class Customer extends Base
|
|
|
if ($recordData == 0) {
|
|
|
$relationId[] = $v['relation_id'];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
$wheres['id'] = array('in', $relationId);
|
|
|
$staff = Staff::info();
|
|
|
- $wheres['owner_staff_id'] = $staff->id;
|
|
|
+ $wheres[] = Db::raw("FIND_IN_SET($staff_id, owner_staff_id)");
|
|
|
break;
|
|
|
case 4:
|
|
|
$start = date('Y-m-d 00:00:00');
|
|
|
@@ -109,38 +115,33 @@ class Customer extends Base
|
|
|
if ($recordData >= 1) {
|
|
|
$relationId[] = $v['relation_id'];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
$wheres['id'] = array('in', $relationId);
|
|
|
$staff = Staff::info();
|
|
|
- $wheres['owner_staff_id'] = $staff->id;
|
|
|
+ $wheres[] = Db::raw("FIND_IN_SET($staff_id, owner_staff_id)");
|
|
|
break;
|
|
|
case 5:
|
|
|
$record = collection(Record::where(array('relation_type' => 1, 'next_time' => array('neq', '')))->column('relation_id'))->toArray();
|
|
|
$wheres['id'] = array('not in', $record);
|
|
|
$staff = Staff::info();
|
|
|
- $wheres['owner_staff_id'] = $staff->id;
|
|
|
+ $wheres[] = Db::raw("FIND_IN_SET($staff_id, owner_staff_id)");
|
|
|
break;
|
|
|
default:
|
|
|
- $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
|
|
|
+ $wheres[] = Db::raw("FIND_IN_SET($staff_id, owner_staff_id)");
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
- $owner_staff_id = $wheres['owner_staff_id'];
|
|
|
- unset($wheres['owner_staff_id']);
|
|
|
- $list = $this->model->where($where)->with(['ownerStaff'])
|
|
|
- ->where($wheres)->where(function ($query) use ($staff_id, $owner_staff_id, $type) {
|
|
|
- if ($type == 0) {//全部
|
|
|
- $query->where(['ro_staff_id' => ['like', "%,{$staff_id},%"]])
|
|
|
- ->whereOr('rw_staff_id', 'like', "%,{$staff_id},%")
|
|
|
- ->whereOr(['owner_staff_id' => $owner_staff_id]);
|
|
|
- } else {
|
|
|
- $query->where(['owner_staff_id' => $owner_staff_id]);
|
|
|
- }
|
|
|
- })
|
|
|
+
|
|
|
+// $list = $this->model->where($where)->with(['ownerStaff'])
|
|
|
+// ->where($wheres)
|
|
|
+// ->where('owner_staff_id != 0 and owner_staff_id is not null')
|
|
|
+// ->order($sort, $order)->paginate($limit);
|
|
|
+ $list = $this->model->where($where)
|
|
|
+ ->where($wheres)
|
|
|
->where('owner_staff_id != 0 and owner_staff_id is not null')
|
|
|
->order($sort, $order)->paginate($limit);
|
|
|
+
|
|
|
$rows = $list->items();
|
|
|
+
|
|
|
foreach ($rows as &$v) {
|
|
|
$v['operation_team'] = 'read';
|
|
|
if ($v['owner_staff_id'] == $this->_staff->id ||
|
|
|
@@ -153,18 +154,25 @@ class Customer extends Base
|
|
|
} else {
|
|
|
$v['operation'] = 'read';//只读权限
|
|
|
}
|
|
|
+ if($v['create_staff_id'] == $this->_staff->id){
|
|
|
+ $v['operation'] = 'update';//修改权限
|
|
|
+ }
|
|
|
+ $names = Staff::where('id', 'in', $v['owner_staff_id'])->column('name');
|
|
|
+ $v['owner_staff']['name'] = implode(',', $names);
|
|
|
|
|
|
}
|
|
|
- $result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
+ $result = array("total" => $list->total(), "rows" => $list->items(),"staff_id" => $staff_id);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
$field = FormField::getFields(FormField::CUSTOMER_TYPE);
|
|
|
+ $this->assign('staff_group', $staff->group_ids);
|
|
|
$this->assignconfig('fields', $field);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
@@ -174,6 +182,7 @@ class Customer extends Base
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
+
|
|
|
// 表单验证
|
|
|
if (($result = $this->qingdongValidate($params, 'Customer', 'create')) !== true) {
|
|
|
$this->error($result);
|
|
|
@@ -192,6 +201,7 @@ class Customer extends Base
|
|
|
if ($result !== true) {
|
|
|
$this->error($result);
|
|
|
}
|
|
|
+
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
@@ -222,6 +232,7 @@ class Customer extends Base
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
+
|
|
|
$this->assign('form_data', Form::getDataValue(Form::CUSTOMER_TYPE));
|
|
|
$remind = Remind::where(['type' => Remind::CUSTOMER_TYPE])->find();
|
|
|
$staff_ids = $remind['staff_ids'] ?? '';
|
|
|
@@ -232,7 +243,6 @@ class Customer extends Base
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 修改
|
|
|
*/
|
|
|
@@ -244,12 +254,18 @@ class Customer extends Base
|
|
|
if (empty($row)) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
- if (!in_array($row['owner_staff_id'], Staff::getMyStaffIds()) && $row['owner_staff_id'] != 0) {
|
|
|
+// if (!in_array($row['owner_staff_id'], Staff::getMyStaffIds()) && $row['owner_staff_id'] != 0) {
|
|
|
+//
|
|
|
+// if (!in_array($this->_staff->id, explode(',', $row['rw_staff_id'])) &&
|
|
|
+// !in_array($this->_staff->id, explode(',', $row['ro_staff_id']))) {//是否在团队内
|
|
|
+// $this->error('权限不足');
|
|
|
+// }
|
|
|
+// }
|
|
|
+ $staff = Staff::info();
|
|
|
+ $ownerarray = explode(',', $row['owner_staff_id']);
|
|
|
|
|
|
- if (!in_array($this->_staff->id, explode(',', $row['rw_staff_id'])) &&
|
|
|
- !in_array($this->_staff->id, explode(',', $row['ro_staff_id']))) {//是否在团队内
|
|
|
- $this->error('权限不足');
|
|
|
- }
|
|
|
+ if (!in_array($staff->id, $ownerarray)) {
|
|
|
+ $this->error('权限不足');
|
|
|
}
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
@@ -306,6 +322,7 @@ class Customer extends Base
|
|
|
*/
|
|
|
public function stafflist()
|
|
|
{
|
|
|
+
|
|
|
$data = ['searchlist' => Staff::getList()];
|
|
|
$this->success('', null, $data);
|
|
|
}
|
|
|
@@ -366,6 +383,7 @@ class Customer extends Base
|
|
|
public function batch_change($ids = null)
|
|
|
{
|
|
|
$ids = json_decode($ids, true);
|
|
|
+
|
|
|
$ids = $this->model->where([
|
|
|
'id' => ['in', $ids]
|
|
|
])->column('id');
|
|
|
@@ -373,7 +391,9 @@ class Customer extends Base
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
if ($this->request->isPost()) {
|
|
|
+
|
|
|
$params = $this->request->post("row/a");
|
|
|
+
|
|
|
if ($params) {
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
|
|
|
@@ -414,9 +434,12 @@ class Customer extends Base
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
if (!in_array($row['owner_staff_id'], Staff::getMyStaffIds()) && $row['owner_staff_id'] != 0) {
|
|
|
-
|
|
|
- if (!in_array($this->_staff->id, explode(',', $row['rw_staff_id'])) &&
|
|
|
- !in_array($this->_staff->id, explode(',', $row['ro_staff_id']))) {//是否在团队内
|
|
|
+//
|
|
|
+// if (!in_array($this->_staff->id, explode(',', $row['rw_staff_id'])) &&
|
|
|
+// !in_array($this->_staff->id, explode(',', $row['ro_staff_id'])) ) {//是否在团队内
|
|
|
+// $this->error('权限不足');
|
|
|
+// }
|
|
|
+ if(!in_array($this->_staff->id, explode(',', $row['owner_staff_id']))){
|
|
|
$this->error('权限不足');
|
|
|
}
|
|
|
}
|
|
|
@@ -430,11 +453,14 @@ class Customer extends Base
|
|
|
if (in_array($this->_staff->id, explode(',', $row['rw_staff_id']))) {
|
|
|
$row['operation_team'] = 'update';//可修改客户不可操作其他
|
|
|
}
|
|
|
+
|
|
|
$row['operation'] = 'update';//修改权限
|
|
|
} else {
|
|
|
$row['operation'] = 'read';//只读权限
|
|
|
}
|
|
|
-
|
|
|
+ if($row['create_staff_id'] == $this->_staff->id){
|
|
|
+ $row['operation'] = 'update';//修改权限
|
|
|
+ }
|
|
|
$form = Form::getDataValue(Form::CUSTOMER_TYPE, $row);
|
|
|
foreach ($form as $ks => $vs) {
|
|
|
//备注显示
|