Merge pull request 'zm' (#3) from zm into master

Reviewed-on: mengfucius/wkcrm#3
pull/5/head^2
张萌 2 years ago
commit c9a654d2b7

@ -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' => '推进失败,请重试']);
}
}
}
} }

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

Loading…
Cancel
Save