field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $wherePool = (new Customer())->getWhereByPool(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['action_id']])->where($wherePool)->find(); if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) { $this->error = '无权操作!'; return false; } } # 商机模块快捷编辑权限验证 if ($types == 'crm_business') { $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); if (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre) { $this->error = '无权操作!'; return false; } } # 合同模块快捷编辑权限验证 if ($types == 'crm_contract') { $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) { $this->error = '无权操作!'; return false; } } foreach ($param AS $key => $value) { # 查询自定义字段信息 $fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name']) ->where('types', $types)->where('field', $key)->find(); # 字符长度 if (!empty($fieldInfo['max_length']) && strlen($value) > $fieldInfo['max_length']) { $this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!'; return false; } # 必填 if (!empty($fieldInfo['is_null']) && empty($value)) { $this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!'; return false; } # 唯一 if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($key, $value)->value($primaryKey)) { $this->error = $fieldInfo['name'] . ' 内容重复!'; return false; } } # 编辑参数 $data = []; if (!empty($param['list'])) { foreach ($param['list'] AS $key => $value) { foreach ($value AS $k => $v) { # 处理下次联系时间格式 if ($k == 'next_time') { $data[$k] = !empty($v) ? strtotime($v) : ''; } else { $data[$k] = $v; } # 处理产品类别 if ($types == 'crm_product' && $k == 'category_id') { $categorys = explode(',', $v); $data[$k] = $categorys[count($categorys) - 1]; } } } $data[$primaryKey] = $actionId; } return $model->update($data); } }