|
|
@ -198,7 +198,7 @@ class Business extends ApiCommon
|
|
|
|
$fileModel->delRFileByModule('crm_business', $delIds);
|
|
|
|
$fileModel->delRFileByModule('crm_business', $delIds);
|
|
|
|
//删除关联操作记录
|
|
|
|
//删除关联操作记录
|
|
|
|
$actionRecordModel->delDataById(['types' => 'crm_business', 'action_id' => $delIds]);
|
|
|
|
$actionRecordModel->delDataById(['types' => 'crm_business', 'action_id' => $delIds]);
|
|
|
|
$dataInfo = $businessModel->where('business_id',['in',$delIds])->select();
|
|
|
|
$dataInfo = $businessModel->where('business_id', ['in', $delIds])->select();
|
|
|
|
foreach ($dataInfo as $k => $v) {
|
|
|
|
foreach ($dataInfo as $k => $v) {
|
|
|
|
RecordActionLog($userInfo['id'], 'crm_business', 'delete', $v['name'], '', '', '删除了商机:' . $v['name']);
|
|
|
|
RecordActionLog($userInfo['id'], 'crm_business', 'delete', $v['name'], '', '', '删除了商机:' . $v['name']);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -223,10 +223,10 @@ class Business extends ApiCommon
|
|
|
|
$list = cache($key);
|
|
|
|
$list = cache($key);
|
|
|
|
if (!$list) {
|
|
|
|
if (!$list) {
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$authMap = function($query) use ($userInfo){
|
|
|
|
$authMap = function ($query) use ($userInfo) {
|
|
|
|
$query->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'],'is_display'=> 1,'status'=> 1])
|
|
|
|
$query->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'], 'is_display' => 1, 'status' => 1])
|
|
|
|
->whereOr(function ($query) use ($userInfo) {
|
|
|
|
->whereOr(function ($query) use ($userInfo) {
|
|
|
|
$query->where(['structure_id' => ''])->where(['is_display'=> 1,'status'=> 1]);
|
|
|
|
$query->where(['structure_id' => ''])->where(['is_display' => 1, 'status' => 1]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$list = db('crm_business_type')
|
|
|
|
$list = db('crm_business_type')
|
|
|
@ -237,7 +237,7 @@ class Business extends ApiCommon
|
|
|
|
$list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']);
|
|
|
|
$list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache($key, $list, config('business_status_cache_time'));
|
|
|
|
cache($key, $list, config('business_status_cache_time'));
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
cache($key, NULL);
|
|
|
|
cache($key, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -392,71 +392,21 @@ class Business extends ApiCommon
|
|
|
|
if ($businessInfo['is_end']) {
|
|
|
|
if ($businessInfo['is_end']) {
|
|
|
|
return resultArray(['error' => '已结束,不能推进']);
|
|
|
|
return resultArray(['error' => '已结束,不能推进']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//判断权限
|
|
|
|
|
|
|
|
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
|
|
|
|
|
|
|
|
//读写权限
|
|
|
|
|
|
|
|
$rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
|
|
|
|
|
|
|
|
if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
|
|
|
|
|
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
|
|
|
|
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$status_id = $param['status_id'] ?: $businessInfo['status_id'];
|
|
|
|
|
|
|
|
$statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
|
|
|
|
|
|
|
|
if (!$statusInfo && !$is_end) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data = [];
|
|
|
|
$data['update_time'] = time();
|
|
|
|
$data['update_time'] = time();
|
|
|
|
$data['is_end'] = $is_end;
|
|
|
|
$data['is_end'] = $is_end;
|
|
|
|
$data['remark'] = $remark;
|
|
|
|
$data['remark'] = $remark;
|
|
|
|
// if ($is_end) {
|
|
|
|
$data['check_status'] = 1;
|
|
|
|
// $status_id = $is_end;
|
|
|
|
$data['flow_id'] = 13;
|
|
|
|
// }
|
|
|
|
$data['check_user_id'] = $param['check_user_id'];
|
|
|
|
$data['status_id'] = $status_id;
|
|
|
|
$data['flow_user_id'] = $param['check_user_id'];
|
|
|
|
$data['status_time'] = time();
|
|
|
|
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
if (!$res) {
|
|
|
|
if (!$res) {
|
|
|
|
return resultArray(['error' => '推进失败,请重试']);
|
|
|
|
return resultArray(['error' => '推进失败,请重试']);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# 商机变更后的名称
|
|
|
|
|
|
|
|
$businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name');
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $is_end == 1) $businessStatusName = '赢单';
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单';
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效';
|
|
|
|
|
|
|
|
# 添加活动记录
|
|
|
|
|
|
|
|
Db::name('crm_activity')->insert([
|
|
|
|
|
|
|
|
'type' => 3,
|
|
|
|
|
|
|
|
'activity_type' => 5,
|
|
|
|
|
|
|
|
'activity_type_id' => $businessInfo['business_id'],
|
|
|
|
|
|
|
|
'content' => '阶段变更为 ' . $businessStatusName,
|
|
|
|
|
|
|
|
'create_user_id' => $businessInfo['owner_user_id'],
|
|
|
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
|
|
|
'customer_ids' => ',' . $businessInfo['customer_id'] . ','
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//推进记录添加
|
|
|
|
|
|
|
|
$temp['status_id'] = $status_id ?: 0;
|
|
|
|
|
|
|
|
$temp['is_end'] = $is_end ?: 0;
|
|
|
|
|
|
|
|
$temp['business_id'] = $param['business_id'];
|
|
|
|
|
|
|
|
$temp['create_time'] = time();
|
|
|
|
|
|
|
|
$temp['owner_user_id'] = $userInfo['id'];
|
|
|
|
|
|
|
|
$temp['remark'] = $param['statusRemark'] ?: '';
|
|
|
|
|
|
|
|
Db::name('CrmBusinessLog')->insert($temp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 返回商机阶段数据
|
|
|
|
|
|
|
|
$typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
|
|
|
|
|
|
|
|
$businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
'business_id' => $param['business_id'],
|
|
|
|
|
|
|
|
'type_id' => $typeId,
|
|
|
|
|
|
|
|
'status_id' => $param['status_id'],
|
|
|
|
|
|
|
|
'status_list' => $businessStatus
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultArray(['data' => $result]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultArray(['success' => '提交成功']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -616,4 +566,100 @@ class Business extends ApiCommon
|
|
|
|
|
|
|
|
|
|
|
|
return resultArray(['data' => '操作成功!']);
|
|
|
|
return resultArray(['data' => '操作成功!']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function check()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$param = $this->param;
|
|
|
|
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
|
|
|
|
$userModel = new \app\admin\model\User();
|
|
|
|
|
|
|
|
// $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
|
|
|
|
|
|
|
|
// $remark = $param['statusRemark'];
|
|
|
|
|
|
|
|
$check_status = $param['check_status'];
|
|
|
|
|
|
|
|
if (!$param['business_id']) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($check_status == 2) {
|
|
|
|
|
|
|
|
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
|
|
|
|
|
|
|
|
// if ($businessInfo['is_end']) {
|
|
|
|
|
|
|
|
// return resultArray(['error' => '已结束,不能推进']);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断权限
|
|
|
|
|
|
|
|
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
|
|
|
|
|
|
|
|
//读写权限
|
|
|
|
|
|
|
|
$rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
|
|
|
|
|
|
|
|
if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
|
|
|
|
|
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
|
|
|
|
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$status_id = $param['status_id'] ?: $businessInfo['status_id'];
|
|
|
|
|
|
|
|
$statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
|
|
|
|
|
|
|
|
if (!$statusInfo && $businessInfo['is_end']) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$data['update_time'] = time();
|
|
|
|
|
|
|
|
// $data['is_end'] = $is_end;
|
|
|
|
|
|
|
|
// $data['remark'] = $remark;
|
|
|
|
|
|
|
|
$data['check_status'] = $check_status;
|
|
|
|
|
|
|
|
$data['status_id'] = $status_id;
|
|
|
|
|
|
|
|
$data['status_time'] = time();
|
|
|
|
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
|
|
|
|
if (!$res) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '推进失败,请重试']);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# 商机变更后的名称
|
|
|
|
|
|
|
|
$businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name');
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $businessInfo['is_end'] == 1) $businessStatusName = '赢单';
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $businessInfo['is_end'] == 2) $businessStatusName = '输单';
|
|
|
|
|
|
|
|
if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效';
|
|
|
|
|
|
|
|
# 添加活动记录
|
|
|
|
|
|
|
|
Db::name('crm_activity')->insert([
|
|
|
|
|
|
|
|
'type' => 3,
|
|
|
|
|
|
|
|
'activity_type' => 5,
|
|
|
|
|
|
|
|
'activity_type_id' => $businessInfo['business_id'],
|
|
|
|
|
|
|
|
'content' => '阶段变更为 ' . $businessStatusName,
|
|
|
|
|
|
|
|
'create_user_id' => $businessInfo['owner_user_id'],
|
|
|
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
|
|
|
'customer_ids' => ',' . $businessInfo['customer_id'] . ','
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//推进记录添加
|
|
|
|
|
|
|
|
$temp['status_id'] = $status_id ?: 0;
|
|
|
|
|
|
|
|
$temp['is_end'] = $businessInfo['is_end'] ?: 0;
|
|
|
|
|
|
|
|
$temp['business_id'] = $param['business_id'];
|
|
|
|
|
|
|
|
$temp['create_time'] = time();
|
|
|
|
|
|
|
|
$temp['owner_user_id'] = $userInfo['id'];
|
|
|
|
|
|
|
|
$temp['remark'] = $param['statusRemark'] ?: '';
|
|
|
|
|
|
|
|
Db::name('CrmBusinessLog')->insert($temp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 返回商机阶段数据
|
|
|
|
|
|
|
|
$typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
|
|
|
|
|
|
|
|
$businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
'business_id' => $param['business_id'],
|
|
|
|
|
|
|
|
'type_id' => $typeId,
|
|
|
|
|
|
|
|
'status_id' => $param['status_id'],
|
|
|
|
|
|
|
|
'status_list' => $businessStatus
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultArray(['data' => $result]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$data['update_time'] = time();
|
|
|
|
|
|
|
|
$data['is_end'] = 0;
|
|
|
|
|
|
|
|
$data['remark'] = '';
|
|
|
|
|
|
|
|
$data['check_status'] = $check_status;
|
|
|
|
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
|
|
|
|
if (!$res) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '推进失败,请重试']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|