zm #3

Merged
mengfucius merged 2 commits from zm into master 2 years ago

@ -198,7 +198,7 @@ class Business extends ApiCommon
$fileModel->delRFileByModule('crm_business', $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) {
RecordActionLog($userInfo['id'], 'crm_business', 'delete', $v['name'], '', '', '删除了商机:' . $v['name']);
}
@ -223,10 +223,10 @@ class Business extends ApiCommon
$list = cache($key);
if (!$list) {
$userInfo = $this->userInfo;
$authMap = function($query) use ($userInfo){
$query->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'],'is_display'=> 1,'status'=> 1])
$authMap = function ($query) use ($userInfo) {
$query->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'], 'is_display' => 1, 'status' => 1])
->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')
@ -237,7 +237,7 @@ class Business extends ApiCommon
$list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']);
}
cache($key, $list, config('business_status_cache_time'));
}else{
} else {
cache($key, NULL);
}
@ -392,71 +392,21 @@ class Business extends ApiCommon
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 && !$is_end) {
return resultArray(['error' => '参数错误']);
}
$data = [];
$data['update_time'] = time();
$data['is_end'] = $is_end;
$data['remark'] = $remark;
// if ($is_end) {
// $status_id = $is_end;
// }
$data['status_id'] = $status_id;
$data['status_time'] = time();
$data['check_status'] = 1;
$data['flow_id'] = 13;
$data['check_user_id'] = $param['check_user_id'];
$data['flow_user_id'] = $param['check_user_id'];
$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) && $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' => '操作成功!']);
}
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' => '推进失败,请重试']);
}
}
}
}

@ -447,14 +447,15 @@ class ExamineLogic extends Common
->count();
break;
case 4:// 商机
$list = db('crm_bussiness')
$list = db('crm_business')
->alias('a')
->join('__ADMIN_USER__ user', 'user.id = a.create_user_id', 'LEFT')
->join('__ADMIN_EXAMINE_FLOW__ examine_flow', 'examine_flow.flow_id = a.flow_id', 'LEFT')
->where($where)
->where('a.is_end',['in',[1,2,3]])
->where($whereOr)
->field(
'a.invoice_id as catagory_id ,a.invoice_apple_number as name,a.create_time,a.check_status,a.create_user_id,a.check_user_id,a.flow_user_id,user.realname,examine_flow.name as examine_name'
'a.business_id as catagory_id ,a.name as name,a.create_time,a.check_status,a.create_user_id,a.check_user_id,a.flow_user_id,user.realname,examine_flow.name as examine_name'
)
->page($param['page'], $param['limit'])
->order('a.create_time desc')
@ -463,7 +464,7 @@ class ExamineLogic extends Common
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
}
$dataCount = db('crm_invoice')
$dataCount = db('crm_business')
->alias('a')
->join('__ADMIN_USER__ user', 'user.id = a.create_user_id', 'LEFT')
->where($where)

Loading…
Cancel
Save