|
@@ -0,0 +1,252 @@
|
|
|
+<?php
|
|
|
+namespace app\common\model;
|
|
|
+
|
|
|
+use think\Db;
|
|
|
+use app\common\util\AppMsg;
|
|
|
+class Wlps extends Base
|
|
|
+{
|
|
|
+ private $orgId=103;
|
|
|
+ public function deal_wlps($v){
|
|
|
+ $cate = 25;
|
|
|
+ $orgId = 103;
|
|
|
+ $dep = 798;
|
|
|
+ $userId = 3401;
|
|
|
+ if(!$v['s_bmid'] || !$v['department_no']){
|
|
|
+ // Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'发起部门编号或病区编码为空']);
|
|
|
+ Db::name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'发起部门编号或病区编码为空']);
|
|
|
+ $this->error = '发起部门编号或病区编码为空';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $start = Db::name('address')->where('del',0)->where('org_id',$orgId)->where('','exp',Db::raw("FIND_IN_SET(2,types)"))->where('third_sn',$v['s_bmid'])->find();
|
|
|
+ $end = Db::name('address')->where('del',0)->where('org_id',$orgId)->where('','exp',Db::raw("FIND_IN_SET(2,types)"))->where('third_sn',$v['department_no'])->find();
|
|
|
+ if(!$start || !$end){
|
|
|
+ // Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'未查找到相关联的发起部门编号或病区编码']);
|
|
|
+ Db::name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'未查找到相关联的发起部门编号或病区编码']);
|
|
|
+ $this->error = '未查找到相关联的发起部门编号或病区编码';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $this->startTrans();
|
|
|
+ try{
|
|
|
+ $content = '';
|
|
|
+ if($v['kdg_id']){
|
|
|
+ $content .= '快递柜编号:'.$v['kdg_id'].';';
|
|
|
+ }
|
|
|
+ if($v['qjm']){
|
|
|
+ $content .= '取件码:'.$v['qjm'].';';
|
|
|
+ }
|
|
|
+ if($v['psx_id']){
|
|
|
+ $content .= '配送箱编号:'.$v['psx_id'].';';
|
|
|
+ }
|
|
|
+ if($v['z_num']){
|
|
|
+ $content .= '总数量:'.$v['z_num'].';';
|
|
|
+ }
|
|
|
+ if($v['tpn_num'] > 0){
|
|
|
+ $content .= $v['tpn_name'].':'.$v['tpn_num'].';';
|
|
|
+ }
|
|
|
+ if($v['pt_num'] > 0){
|
|
|
+ $content .= $v['pt_name'].':'.$v['pt_num'].';';
|
|
|
+ }
|
|
|
+ if($v['kss_num'] > 0){
|
|
|
+ $content .= $v['kss_name'].':'.$v['kss_num'].';';
|
|
|
+ }
|
|
|
+ if($v['hl_num'] > 0){
|
|
|
+ $content .= $v['hl_name'].':'.$v['hl_num'].';';
|
|
|
+ }
|
|
|
+ if($v['qjmsg_desc']){
|
|
|
+ $content .= $v['qjmsg_desc'];
|
|
|
+ }
|
|
|
+ // 检查是否设置路线
|
|
|
+ $auto = Db::name('auto_user')
|
|
|
+ ->where('org_id',$orgId)
|
|
|
+ ->where('start',$start['id'])
|
|
|
+ ->where('end',$end['id'])
|
|
|
+ ->where('enable',1)
|
|
|
+ ->find();
|
|
|
+ $data = [
|
|
|
+ 'org_id' => $orgId,
|
|
|
+ 'dep_id' => $dep,
|
|
|
+ 'order_mode' => $auto?5:1,
|
|
|
+ 'content' => $content,
|
|
|
+ 'sn' => get_unique_sn(get_config('sn_prefix')),
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
+ 'create_yyyy' => date('Y'),
|
|
|
+ 'create_yyyymm' => date('Ym'),
|
|
|
+ 'create_yyyymmdd' => date('Ymd'),
|
|
|
+ 'source_type' => 2,
|
|
|
+ 'work_type_mode' => 3
|
|
|
+ ];
|
|
|
+ if($auto){
|
|
|
+ $data['send_time'] = date('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
+
|
|
|
+ $ret = Db::name('orders')->insertGetId($data);
|
|
|
+ if (!$ret) {
|
|
|
+ exception('订单保存失败');
|
|
|
+ }
|
|
|
+ $orderId = $ret;
|
|
|
+
|
|
|
+ $cd = [
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'type' => $cate,
|
|
|
+ 'start' => $start['id'],
|
|
|
+ 'end' => $end['id'],
|
|
|
+ 'xq_time' => date('Y-m-d H:i:s'),
|
|
|
+ 'ywc_time' => date('Y-m-d H:i:s',time() + 30*60),
|
|
|
+ 'priority' => 2
|
|
|
+ ];
|
|
|
+ $res = Db::name('order_convey')->insert($cd);
|
|
|
+ if (!$res) {
|
|
|
+ exception('订单保存失败');
|
|
|
+ }
|
|
|
+ $wd = [
|
|
|
+ 'is_deal'=>1,
|
|
|
+ 'order_id'=>$orderId
|
|
|
+ ];
|
|
|
+ if($auto){
|
|
|
+ $wd['send_time'] = date('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
+ // $res = Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update($wd);
|
|
|
+ $res = Db::name('wlps')->where('id',$v['id'])->update($wd);
|
|
|
+ if (!$res) {
|
|
|
+ exception('订单保存失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动派单
|
|
|
+ if($auto){
|
|
|
+ //添加工单
|
|
|
+ $todo = array(
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'todo_content' => '',
|
|
|
+ 'org_id' => $orgId,
|
|
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
+ 'todo_mode' => 1, //待处理
|
|
|
+ 'work_type_mode' => 3,
|
|
|
+ 'to_user_id' => $auto['user_id']
|
|
|
+ );
|
|
|
+ $todores = $this->add_todo($todo);
|
|
|
+ if(!$todores){
|
|
|
+ exception('工单添加失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->commit();
|
|
|
+
|
|
|
+ if($auto){
|
|
|
+ //极光推送
|
|
|
+ send_jpush(array($auto['user_id']),AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$todores]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->rollback();
|
|
|
+ $this->error = $e->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add_todo($data){
|
|
|
+ try{
|
|
|
+ //TODO::检查是否存在重复工单
|
|
|
+ $data['create_yyyy'] = date('Y',strtotime($data['create_time']));
|
|
|
+ $data['create_yyyymm'] = date('Ym',strtotime($data['create_time']));
|
|
|
+ $data['create_yyyymmdd'] = date('Ymd',strtotime($data['create_time']));
|
|
|
+ $todoid = Db::name('todo')->insertGetId($data);
|
|
|
+ if(!$todoid){
|
|
|
+ exception('调度日志保存失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加调度记录
|
|
|
+ $dis = array(
|
|
|
+ 'user_id' => $data['dispatch_user_id'],
|
|
|
+ 'create_time' => $data['create_time'],
|
|
|
+ 'content' => $data['todo_content'],
|
|
|
+ 'order_id' => $data['order_id']
|
|
|
+ );
|
|
|
+ $dlid=Db::name('dispatch_log')->insert($dis);
|
|
|
+ if(!$dlid){
|
|
|
+ exception('调度日志保存失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $todoid;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新运送用户信息
|
|
|
+ public function updateYsUser($userId,$name,$phone,$rolesId,$orgId){
|
|
|
+ if($this->orgId != $orgId){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 检查角色是否是运送工人
|
|
|
+ $roles = Db::name('roles')->where('id',$rolesId)->find();
|
|
|
+ if(!$roles || ($roles['parent_id'] != 6)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查用户是否已存在
|
|
|
+ $ysuser = Db::name('ysuser')->where('user_id',$userId)->find();
|
|
|
+ if(!$ysuser){
|
|
|
+ Db::name('ysuser')->insert([
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'phone' => $phone,
|
|
|
+ 'jluser_id' => 'JL'.$userId
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ Db::name('ysuser')->where('id',$ysuser['id'])->update([
|
|
|
+ 'name' => $name,
|
|
|
+ 'phone' => $phone,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化运送用户信息
|
|
|
+ public function initYsUser(){
|
|
|
+ $rolesids = [];
|
|
|
+ $list = Db::name('roles')
|
|
|
+ ->whereLike('mode','%'.'182868')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('enable',1)
|
|
|
+ ->column('roles_id');
|
|
|
+ foreach ($list as $kk=>$vv){
|
|
|
+ $rolesids[] = $vv['roles_id'];
|
|
|
+ }
|
|
|
+ if($rolesids){
|
|
|
+ $map[] = $this->whereIn('ur.roles_id',$rolesids);
|
|
|
+ }else{
|
|
|
+ $map[] = $this->where('ur.roles_id',-1);
|
|
|
+ }
|
|
|
+ $map = $map?$map:true;
|
|
|
+ $users = Db::name('user_roles')
|
|
|
+ ->alias('ur')
|
|
|
+ ->field('u.user_id,u.real_name,u.mobile')
|
|
|
+ ->join('user as u','u.user_id = ur.user_id')
|
|
|
+ ->join('roles as r','ur.roles_id = r.roles_id')
|
|
|
+ ->where('u.enable',1)
|
|
|
+ ->where('u.del_ref',0)
|
|
|
+ ->where($map)
|
|
|
+ ->select();
|
|
|
+ $users = $users?$users:[];
|
|
|
+ foreach ($users as $k=>$v){
|
|
|
+ // 检查用户是否已存在
|
|
|
+ $ysuser = Db::name('ysuser')->where('user_id',$v['user_id'])->find();
|
|
|
+ if(!$ysuser){
|
|
|
+ Db::name('ysuser')->insert([
|
|
|
+ 'user_id' => $v['user_id'],
|
|
|
+ 'name' => $v['real_name'],
|
|
|
+ 'phone' => $v['mobile'],
|
|
|
+ 'jluser_id' => 'JL'.$v['user_id']
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ Db::name('ysuser')->where('id',$ysuser['id'])->update([
|
|
|
+ 'name' => $v['real_name'],
|
|
|
+ 'phone' => $v['mobile'],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|