field('id,type')->find(); $rule_data = AgentType::where([['root_id','=',$root_id],['id','=',$agent['type']]])->value('count'); $daoday = !empty($rule_data) ? json_decode($rule_data,true) : ''; //$daoday=CreditsSetting::where([['code','in',$rule_type],['root_id','=',$agt_root]])->column('value', 'code'); $deposit_time = isset($daoday['agent_hx_time']) ? $daoday['agent_hx_time'] : 0; $sign_time = isset($daoday['agent_hxtime_sign']) ? $daoday['agent_hxtime_sign'] : 0; $adddeposit_time=time()-$deposit_time*86400; $addsign_time=time()-$sign_time*86400; Db::startTrans(); try { $list=AgentIntegral::where([ //['addtime','<',$addtime], ['status','=',1], ['agent_id','=',$agentid] ])->lock(true)->select()->toArray(); if(!empty($list)){ $xin=0; $xinid=null; foreach($list as $key=>$val){ if(in_array($val['type'],[1,4,5,6])){ $xin+=$val['integral']; $xinid.=$val['id'].','; } if($val['type']==2 && $val['addtime'] < $adddeposit_time){ $xin+=$val['integral']; $xinid.=$val['id'].','; } if($val['type']==3 && $val['addtime'] < $addsign_time){ $xin+=$val['integral']; $xinid.=$val['id'].','; } } $agt_data=AgentIntegralLog::where('agt_id',$agentid)->order('id desc')->find(); if(empty($agt_data)){ $agt_data['now_integral']=0; } $now_integral=$xin+$agt_data['now_integral']; $add=array( 'agt_id'=>$agentid, 'addtime'=>time(), 'integral_id'=>trim($xinid,','), 'integral'=>$xin, 'now_integral'=>$now_integral, 'type'=>1 ); $ms=AgentIntegralLog::insert($add); AgentIntegral::where('id','in',$xinid)->update(['status'=>2]); } Db::commit(); }catch (\Exception $e) { Db::rollback(); } } /** * 客户检测手机号的重复 * $from sign 活动 add 添加 */ public function checkPepeat($pharr, $orgids, $employee_id, $id = null, $from = 'add') { $emp = Employee::where('id', $employee_id)->find(); if (empty($emp)) { return ''; } $root_id = $emp['root_id']; $emp_org = $emp['org_id']; // 同部门能否重复录入开关设置 $empcrm_repeat[] = ['root_id', '=', $root_id]; $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat']; $repeat_setting = Setting::where($empcrm_repeat)->findOrEmpty(); foreach($pharr as $key=>$val){ if(empty($val)) continue; // 先判断公海 只有添加时候判断 且不是活动报名 if (empty($id) && $from != 'sign') { $poolExist = Customer::where([ ['phone|phone1|phone2', '=', cypherphone(trim($val))], ['org_id', '=', $emp_org], ['employee_id', 'null', null], ['is_resource', '=', 0] ])->column('id'); if (!empty($poolExist)) { $poolCrmIdStr = implode(',', $poolExist); return json(['code' => 3, 'data' => $poolCrmIdStr, 'msg' => '录入失败:客户信息已在公海中。']); } } // 新建档,检测手机号是否重复 $customerExist = Customer::where([ ['phone|phone1|phone2', '=', cypherphone(trim($val))], ['org_id', 'in', $orgids], ['employee_id', '>', 0] // 员工客户 ])->where( function($query) { $not_sure = Customer::changeState('待确认', 'chaos'); $or1[] = ['crm_res_id', 'null', null]; $or2[] = ['crm_res_id', '>', 0]; $or2[] = ['state', 'not in', $not_sure]; $query->whereOr([$or1, $or2]); } )->field('id,employee_id,is_resource,org_id')->select()->toArray(); $id_arr = array_column($customerExist, 'id'); $employee_id_arr = array_column($customerExist, 'employee_id'); if (empty($id)) { // 对非当前业务员名下重复客户不在判断 if (in_array($employee_id, $employee_id_arr)) { // 是否已存在为自己的客户 if ($from == 'sign') { // 活动报名 return json(['code' => 1, 'msg' => '您已是' . $emp['name'] . '的客户,请联系他预约']); } else { return json(['code' => 2, 'msg' => '录入失败。' . $val . '已经是您的客户。']); } } } else { if (!in_array($id, $id_arr) && in_array($employee_id, $employee_id_arr)) { // 是否已存在为自己的客户 if ($from == 'sign') { return json(['code' => 1, 'msg' => '您已是' . $emp['name'] . '的客户,请联系他预约']); } else { return json(['code' => 2, 'msg' => '录入失败。' . $val . '已经是您的客户。']); } } } //判断同部门 if (!$repeat_setting->isEmpty()) { $repeat_org = explode(',', $repeat_setting['content']); if (in_array($emp_org, $repeat_org)) { // 需要验证 if (!empty($customerExist)) { foreach ($customerExist as $ex) { if (in_array($ex['org_id'], $repeat_org) && $ex['employee_id'] != $employee_id) { $have_emp = Employee::where('id', '=', $ex['employee_id'])->value('name'); if ($from == 'sign') { return json(['code' => 1, 'msg' => '您已是' . $have_emp . '的客户,请联系他预约']); } else { return json(['code' => 2, 'msg' => '该客户与员工' . $have_emp . '撞单,无法录入']); } } } } } } } } } ?>