123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823 |
- <?php
- namespace app\common\model;
- use app\common\util\AppMsg;
- use think\Db;
- use think\Exception;
- class Complain extends Base
- {
- public $table = 'complain';
- protected $validateName = 'Complain';
- public $from = [
- 0=>'投诉',
- 1=>'一键呼叫',
- 2=>'隐患',
- ];
- public function addSave($info){
- $data=[
- 'org_id'=>$info['orgId'],
- 'dep_id'=>$info['depId'],
- 'create_user_id'=>$info['createUserId'],
- 'content'=>$info['content'],
- 'hide'=>$info['hide'],
- 'images'=>isset($info['images'])?$info['images']:'',
- 'voices'=>isset($info['voices'])?$info['voices']:'',
- 'videos'=>isset($info['videos'])?$info['videos']:'',
- 'create_time'=>getTime(),
- 'create_yyyy'=>date('Y'),
- 'create_yyyymm'=>date('Ym'),
- 'create_yyyymmdd'=>date('Ymd'),
- 'name'=>isset($info['name'])?$info['name']:'',
- 'phone'=>isset($info['phone']) ? $info['phone'] :'',
- ];
- if(!$data['content'] && !$data['voices'] && !$data['videos']){
- $this->error = '请填写信息';
- return false;
- }
- $ret = $this->insert($data);
- return $ret;
- }
- public function lists($page,$size,$orgId,$userId){
- $list = Db::name($this->table)
- ->field('id,content,create_time,status,order_id')
- ->where([
- 'del'=>0,
- 'org_id'=>$orgId,
- 'create_user_id'=>$userId,
- ])
- ->order('id','desc')
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['status_text'] = $this->formatStatus($v['status'],$v['order_id'],$v['id']);
- }
- return $list;
- }
- public function alllists($page,$size,$type,$orgId){
- $hour = (new Config())->getConfig('org_complain_hour',$orgId);
- if($hour > 0 && $type == 1){
- $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
- $map[] = ['create_time','<',$endTime];
- $map[] = ['status','=',0];
- }
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- $list = Db::name($this->table)
- ->where($map)
- ->field('id,content,create_time,status,order_id')
- ->order('id','desc')
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['status_text'] = $this->formatStatus($v['status'],$v['order_id'],$v['id']);
- }
- return $list;
- }
- public function formatStatus($status,$orderId,$id){
- $statusTxt = '';
- if($status == 0){
- $statusTxt = '待处理';
- }else if($status == 1){
- if($orderId > 0){
- $info = Db::name('complain')
- ->where('id',$id)
- ->find();
- if($info['to_from']==0){
- $order = Db::name('orders')->where('id',$orderId)->find();
- if(in_array($order['order_mode'],[3,5,6])){
- $statusTxt = '已处理';
- }else{
- $statusTxt = '处理中(已转单)';
- }
- }elseif ($info['to_from']==1){
- $statusTxt = '已处理(已转单)';
- }
- }else{
- $statusTxt = '已处理';
- }
- }else if ($status==2){
- $statusTxt = '已评价';
- }
- return $statusTxt;
- }
- public function detail($id){
- $info = $this
- ->field('content,create_time,images,voices,videos,create_user_id,org_id,dep_id,note,summary,order_id,status,hide,id,to_from')
- ->where('id',$id)
- ->find()
- ->toArray();
- $info['status_text'] = $this->formatStatus($info['status'],$info['order_id'],$info['id']);
- if($info['order_id'] > 0 && $info['to_from']==0){
- $info['work_type_mode'] = Db::name('orders')->where('id',$info['order_id'])->value('work_type_mode');
- }else{
- $info['work_type_mode'] = 99;
- }
- $info['depName'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');
- if($info['hide'] == 1){
- $info['realName'] = '匿名';
- $info['mobile'] = '';
- }else{
- $user=Db::name('user')
- ->field('real_name,mobile')
- ->where('id',$info['create_user_id'])
- ->find();
- if(!$user) {
- $info['realName'] = '';
- $info['mobile'] = '';
- }
- $info['realName']=$user['real_name'];
- $info['mobile']=$user['mobile'];
- }
- $comment = Db::name('comment')
- ->alias('c')
- ->join('user u','u.id = c.user_id')
- ->where('c.from_id',$id)
- ->where('c.type',16)
- ->field('c.id,c.score,c.content,c.create_time,u.real_name,u.head_image')
- ->order('c.id desc')
- ->select();
- $info['comment'] = $comment?$comment:[];
- return $info?$info:'';
- }
- //派单
- public function send($id, $userId, $data) {
- $complain = Db::name($this->table)->where('id', $id)->where('del',0)->find();
- $odata['dep_id'] = $complain['dep_id'];
- $odata['content'] = $complain['content'];
- $odata['images'] = $complain['images'];
- $odata['videos'] = $complain['videos'];
- $odata['voices'] = $complain['videos'];
- $odata['source_type'] = 2;
- $odata['from'] = 3;
- $odata['user_id'] = $complain['create_user_id'];
- $odata['order_mode'] = 4;
- $odata['work_type_mode'] = $data['work_type_mode'];
- $odata['create_time'] = date('Y-m-d H:i:s');
- $odata['send_time'] = date('Y-m-d H:i:s');
- $odata['create_yyyy'] = date('Y');
- $odata['create_yyyymm'] = date('Ym');
- $odata['create_yyyymmdd'] = date('Ymd');
- $odata['is_deal'] = 0;
- $odata['org_id'] = $data['org_id'];
- $odata['sn'] = get_unique_sn(get_config('sn_prefix'));
- if($complain['status'] == 1){
- $this->error = '该状态不能转单';
- return false;
- }
- $data['userType'] = isset($data['userType']) ? $data['userType'] : 0;
- if(!isset($data['work_type_mode']) || $data['work_type_mode'] <0){
- $this->error = '请选择转单类型';
- return false;
- }
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $workType = explode('|',$config);
- }
- if(!in_array($data['work_type_mode'],$workType)){
- $this->error = '当前类型不能进行转单';
- return false;
- }
- if($data['userType']==0){
- $data['to_user_id'] = !isset($data['to_user_id'])?$data['to_user_id'.$data['work_type_mode']]:$data['to_user_id'];
- }else{
- $data['to_roles_id'] =!isset($data['to_roles_id'])? $data['to_roles_id'.$data['work_type_mode']]:$data['to_roles_id'];
- }
- if ($data['work_type_mode'] == 3) {
- $result = validate('OrdersConvey')->check($data, []);
- if (true !== $result) {
- $this->error = validate('OrdersConvey')->getError();
- return false;
- }
- }
- $pusharr = []; // 需要推送给工人
- $pushdis = []; // 需要推送给二级调度
- if ($data['userType'] == 0) {
- if (!isset($data['to_user_id']) || empty($data['to_user_id'])) {
- $this->error = '请选择执行人';
- return false;
- }
- if ($data['work_type_mode'] == 1) {
- if (!isset($data['type_id']) || empty($data['type_id'])) {
- $this->error = '请选择报修事项';
- return false;
- }
- }
- }
- else {
- if(two_dispatch_off($data['org_id'])!=1){
- $this->error = '二级调度开关未开启';
- return false;
- }
- if (!isset($data['to_roles_id']) || empty($data['to_roles_id'])) {
- $this->error = '请选择二级调度';
- return false;
- }
- }
- $cl_remark = $data['cl_remark'];
- unset($data['cl_remark']);
- $this->startTrans();
- try {
- $orderId = Db::name('orders')->insertGetId($odata);
- if(!$orderId){
- \exception('派单失败');
- }
- $order = Db::name('orders')->where('id',$orderId)->find();
- $saveComplain = Db::name('complain')->where('id',$id)->update(['order_id'=>$orderId,'note'=>$cl_remark,'status'=>1,'update_time'=>getTime()]);
- if(!$saveComplain){
- \exception('投诉更新失败');
- }
- if(!$order){
- $this->error = '派单失败';
- return false;
- }
- if ($data['userType'] == 0) {
- $send_user_num = model('Orders')->sendUserNum($data['work_type_mode'],$data['org_id']);
- $users = explode(',', $data['to_user_id']);
- if($send_user_num==1 && count($users) >1){
- $this->error = '执行人只能选择单人';
- return false;
- }
- $to_user_id = array_unique($users);
- $todoData = [
- 'order_id' => $orderId,
- 'todo_content' => $data['todo_content'],
- 'create_user_id' => $order['user_id'],
- 'org_id' => $data['org_id'],
- 'create_time' => getTime(),
- 'todo_mode' => 1,
- 'work_type_mode' => $data['work_type_mode'],
- 'create_yyyy' => date('Y'),
- 'create_yyyymm' => date('Ym'),
- 'create_yyyymmdd' => date('Ymd'),
- ];
- $taskData = [
- 'org_id' => $data['org_id'],
- 'type' => 1,
- 'start_time' => getTime(),
- 'create_time' => getTime(),
- ];
- if($order['work_type_mode']==1){
- $orderRepair = Db::name('order_repair')
- ->where('order_id',$orderId)
- ->find();
- $taskData['priority'] = !empty($orderRepair) && $orderRepair['repair_priority']==3?1:0;
- }else if ($order['work_type_mode']==3){
- $order_convey = Db::name('order_convey')
- ->where('order_id',$orderId)
- ->find();
- $taskData['priority'] = !empty($order_convey) && $order_convey['priority']==3?2:0;
- }
- $sns = [];
- foreach ($to_user_id as $k => $v) {
- if(empty($v)){
- continue;
- }
- $todoData['to_user_id'] = $v;
- $todoData['sn'] = get_unique_sn(get_config('sn_prefix'));
- while (true){
- if(in_array($todoData['sn'],$sns)){
- $todoData['sn'] = get_unique_sn(get_config('sn_prefix'));
- }else{
- $sns[] = $todoData['sn'];
- break;
- }
- }
- $res = Db::name('todo')
- ->insertGetId($todoData);
- if (!$res) {
- \exception('执行人:' . $v . '派单失败');
- }
- $pusharr[] = [
- 'user_id' => $v,
- 'todo_id' => $res
- ];
- $taskData['user_id'] = $v;
- $taskData['bus_id'] = $res;
- $res = Db::name('task')
- ->insert($taskData);
- if (!$res) {
- \exception('执行人:' . $v . '任务保存失败');
- }
- }
- if($complain['order_id'] > 0){
- if($order['from']==3 && $order['is_deal']==0){
- $rr = ['order_mode' => 4, 'work_type_mode'=>$data['work_type_mode'],'send_time' => getTime()];
- }else{
- $rr = ['order_mode' => 4, 'send_time' => getTime()];
- }
- $res = Db::name('orders')->where('id', $orderId)
- ->update($rr);
- if (!$res) {
- \exception('订单更新失败');
- }
- }
- }
- else {
- $pRolesId = explode(',',$data['to_roles_id']);
- $pp = [];
- foreach ($pRolesId as $k=>$v){
- $logData = [
- 'user_id' => $userId,
- 'to_user_id' =>0,
- 'create_time' => getTime(),
- 'content' => isset($data['todo_content']) ? $data['todo_content'] : '',
- 'order_id' => $orderId,
- 'roles_id' => $v
- ];
- $pp[] = $logData;
- }
- $pushdis = Db::name('user_roles')
- ->where('roles_id','in',$pRolesId)
- ->column('user_id');
- $res = Db::name('dispatch_log')
- ->insertAll($pp);
- if (!$res) {
- \exception('派发失败');
- }
- if($order['from']==3 && $order['is_deal']==0){
- $rrs = ['is_deal' => 1, 'work_type_mode'=>$data['work_type_mode']];
- }else{
- $rrs = ['is_deal' => 1];
- }
- $res = Db::name('orders')->where('id', $orderId)
- ->update($rrs);
- if (!$res) {
- \exception('订单更新失败');
- }
- }
- if ($order['work_type_mode'] == 1) {//报修订单
- $rData = [];
- if (isset($data['type_id']) && !empty($data['type_id'])) {
- $rData['type_id'] = $data['type_id'];
- }
- if (isset($data['address_id']) && !empty($data['address_id'])) {
- $rData['address_id'] = $data['address_id'];
- }
- if (!empty($rData)) {
- $old = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->find();
- if ($old) {
- $rData['update_time'] = getTime();
- $res = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->update($rData);
- }
- else {
- $rData['order_id'] = $orderId;
- $res = Db::name('order_repair')
- ->insert($rData);
- }
- if (!$res) {
- \exception('保存维修扩展失败');
- }
- }
- }else{
- $old = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->find();
- if ($old) {
- $res = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->delete();
- if (!$res) {
- \exception('删除维修扩展失败');
- }
- }
- }
- if($order['from'] == 3 && $order['is_deal']==0){//一键呼叫 转单运送
- if ($data['work_type_mode'] == 3) {
- if (!$data['start'] || !$data['end']) {
- $this->error = '取件与送达地点不能为空';
- return false;
- }
- if ($data['start'] == $data['end']) {
- $this->error = '取件与送达地点不能是同一地点';
- return false;
- }
- if (!$data['xq_time'] || !$data['ywc_time']) {
- $this->error = '应完成时间应和需求时间不能为空';
- return false;
- }
- if ($data['xq_time'] >= $data['ywc_time']) {
- $this->error = '应完成时间应大于需求时间';
- return false;
- }
- if (strtotime($data['xq_time']) < time() - 10 * 60) {
- $this->error = '需求时间已过时';
- return false;
- }
- if (!$data['type']) {
- $this->error = '运送类型不能为空';
- return false;
- }
- if(!$data['name']){
- $this->error = '联系人不能为空';
- return false;
- }
- if(!$data['phone']){
- $this->error = '联系人电话不能为空';
- return false;
- }
- $ysData = array(
- 'order_id' => $orderId,
- 'type' => $data['type'],
- 'start' => $data['start'],
- 'end' => $data['end'],
- 'xq_time' => $data['xq_time'],
- 'ywc_time' => $data['ywc_time'],
- 'name' => $data['name'],
- 'phone' => $data['phone'],
- 'device_id' => isset($data['device_id']) ? (int)$data['device_id'] : 0,
- 'priority' => empty($data['priority']) ? 0 : $data['priority']
- );
- $check = Db::name('order_convey')
- ->where('order_id',$orderId)
- ->find();
- if($check){
- Db::name('order_convey')
- ->where('order_id',$orderId)
- ->update($ysData);
- }else{
- $oCid = Db::name('order_convey')
- ->insertGetId($ysData);
- if (!$oCid) {
- exception('运送信息保存失败');
- }
- }
- $conveyCate = Db::name('convey_cate')
- ->where('id', $data['type'])
- ->find();
- if ($conveyCate['cate'] == 1) {
- $patient = [
- 'order_id' => $orderId,
- 'bed_number' => isset($data['bed_number']) ? $data['bed_number'] : '',
- 'name' => isset($data['p_name']) ? $data['p_name'] : '',
- 'ba_number' => isset($data['ba_number']) ? $data['ba_number'] : '',
- 'gender' => isset($data['gender']) && !empty($data['gender']) ? $data['gender'] : 0,
- 'back' => isset($data['back']) && !empty($data['back']) ? $data['back'] : 0,
- ];
- $cp = Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->find();
- if($cp){
- Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->update($patient);
- }else{
- $ocPid = Db::name('order_convey_patient')
- ->insertGetId($patient);
- if (!$ocPid) {
- exception('保存运送病人扩展失败');
- }
- }
- }
- }else{
- Db::name('order_convey')
- ->where('order_id',$orderId)
- ->delete();
- Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->delete();
- }
- }
- $this->commit();
- if($pusharr){
- foreach ($pusharr as $k=>$v){
- // 极光推送
- send_jpush([$v['user_id']],AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$v['todo_id']]);
- }
- }
- if($pushdis){
- foreach ($pushdis as $k=>$v){
- // 极光推送
- send_jpush([$v],AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$order['id']]);
- }
- }
- // 极光推送
- send_jpush([$order['user_id']],AppMsg::PUSH_USER_ORDER_SEND,'',['id'=>$order['id']]);
- return true;
- } catch (Exception $e) {
- $this->rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- //转单
- public function zd_send($id, $data,$userId) {
- $complain = Db::name($this->table)->where('id', $id)->where('del',0)->find();
- if($complain['order_id'] > 0){
- $this->error = '该投诉已转单,';
- return false;
- }
- if($data['work_type_mode']==99){
- $odata['org_id'] = $data['org_id'];
- $odata['dep_id'] = $complain['dep_id'];
- $odata['content'] = $complain['content'];
- $odata['images'] = $complain['images'];
- $odata['videos'] = $complain['videos'];
- $odata['voices'] = $complain['videos'];
- $odata['from'] = 2;
- $odata['create_user_id'] = $complain['create_user_id'];
- $odata['create_time'] = date('Y-m-d H:i:s');
- $odata['create_yyyy'] = date('Y');
- $odata['create_yyyymm'] = date('Ym');
- $odata['create_yyyymmdd'] = date('Ymd');
- $this->startTrans();
- try {
- $orderId = Db::name('hiddendanger')->insertGetId($odata);
- if (!$orderId) {
- \exception('隐患订单创建失败');
- }
- $res = $this->where('id',$complain['id'])
- ->update(['status'=>1,'update_time'=>getTime(),
- 'hand_user_id'=>$userId,'to_from'=>1,'bus_type'=>2,'order_id'=>$orderId]);
- if (!$res) {
- \exception('投诉订单更新失败');
- }
- $this->commit();
- return true;
- }catch (Exception $e) {
- $this->rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }else{
- $odata['dep_id'] = $complain['dep_id'];
- $odata['content'] = $complain['content'];
- $odata['images'] = $complain['images'];
- $odata['videos'] = $complain['videos'];
- $odata['voices'] = $complain['videos'];
- $odata['source_type'] = $data['work_type_mode']==0?4:2;
- $odata['from'] = 3;
- $odata['user_id'] = $complain['create_user_id'];
- $odata['order_mode'] = 1;
- $odata['work_type_mode'] = $data['work_type_mode'];
- $odata['create_time'] = date('Y-m-d H:i:s');
- $odata['send_time'] = date('Y-m-d H:i:s');
- $odata['create_yyyy'] = date('Y');
- $odata['create_yyyymm'] = date('Ym');
- $odata['create_yyyymmdd'] = date('Ymd');
- $odata['is_deal'] = 0;
- $odata['org_id'] = $data['org_id'];
- $odata['sn'] = get_unique_sn(get_config('sn_prefix'));
- if($complain['status'] == 1){
- $this->error = '该状态不能转单';
- return false;
- }
- if(!isset($data['work_type_mode']) || $data['work_type_mode'] <0){
- $this->error = '请选择转单类型';
- return false;
- }
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $workType = explode('|',$config);
- }
- if(!in_array($data['work_type_mode'],$workType)){
- $this->error = '当前类型不能进行转单';
- return false;
- }
- if ($data['work_type_mode'] == 3) {
- $result = validate('OrdersConvey')->check($data, []);
- if (true !== $result) {
- $this->error = validate('OrdersConvey')->getError();
- return false;
- }
- }
- if ($data['work_type_mode'] == 1) {
- if (!isset($data['type_id']) || empty($data['type_id'])) {
- $this->error = '请选择报修事项';
- return false;
- }
- }
- $cl_remark = $data['cl_remark'];
- unset($data['cl_remark']);
- $this->startTrans();
- try {
- $orderId = Db::name('orders')->insertGetId($odata);
- if (!$orderId) {
- \exception('订单更新失败');
- }
- $order = Db::name('orders')->where('id',$orderId)->find();
- $saveComplain = Db::name('complain')->where('id',$id)->update(['order_id'=>$orderId,'bus_type'=>1,'note'=>$cl_remark,'status'=>1,'update_time'=>getTime()]);
- if(!$saveComplain){
- \exception('投诉更新失败');
- }
- if($order['work_type_mode'] == 3){
- // $score = empty($data['score'])?0:floatval($data['score']);
- // Db::name('order_convey')->where('order_id',$orderId)->update(['score'=>$score]);
- }
- if ($order['work_type_mode'] == 1) {//报修订单
- $rData = [];
- if (isset($data['type_id']) && !empty($data['type_id'])) {
- $rData['type_id'] = $data['type_id'];
- }
- if (isset($data['address_id']) && !empty($data['address_id'])) {
- $rData['address_id'] = $data['address_id'];
- }
- if (!empty($rData)) {
- $old = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->find();
- if ($old) {
- $rData['update_time'] = getTime();
- $res = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->update($rData);
- }
- else {
- $rData['order_id'] = $orderId;
- $res = Db::name('order_repair')
- ->insert($rData);
- }
- if (!$res) {
- \exception('保存维修扩展失败');
- }
- }
- }else{
- $old = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->find();
- if ($old) {
- $res = Db::name('order_repair')
- ->where('order_id', $orderId)
- ->delete();
- if (!$res) {
- \exception('删除维修扩展失败');
- }
- }
- }
- if ($data['work_type_mode'] == 3) {
- if (!$data['start'] || !$data['end']) {
- $this->error = '取件与送达地点不能为空';
- return false;
- }
- if ($data['start'] == $data['end']) {
- $this->error = '取件与送达地点不能是同一地点';
- return false;
- }
- if (!$data['xq_time'] || !$data['ywc_time']) {
- $this->error = '应完成时间应和需求时间不能为空';
- return false;
- }
- if ($data['xq_time'] >= $data['ywc_time']) {
- $this->error = '应完成时间应大于需求时间';
- return false;
- }
- if (strtotime($data['xq_time']) < time() - 10 * 60) {
- $this->error = '需求时间已过时';
- return false;
- }
- if (!$data['type']) {
- $this->error = '运送类型不能为空';
- return false;
- }
- // if(!$data['name']){
- // $this->error = '联系人不能为空';
- // return false;
- // }
- // if(!$data['phone']){
- // $this->error = '联系人电话不能为空';
- // return false;
- // }
- $score = empty($data['score'])?0:floatval($data['score']);
- $ysData = array(
- 'order_id' => $orderId,
- 'type' => $data['type'],
- 'start' => $data['start'],
- 'end' => $data['end'],
- 'xq_time' => $data['xq_time'],
- 'ywc_time' => $data['ywc_time'],
- 'name' => $data['name'],
- 'phone' => $data['phone'],
- 'score' => $score,
- 'device_id' => isset($data['device_id']) ? (int)$data['device_id'] : 0,
- 'priority' => empty($data['priority']) ? 0 : $data['priority']
- );
- $check = Db::name('order_convey')
- ->where('order_id',$orderId)
- ->find();
- if($check){
- Db::name('order_convey')
- ->where('order_id',$orderId)
- ->update($ysData);
- }else{
- $oCid = Db::name('order_convey')
- ->insertGetId($ysData);
- if (!$oCid) {
- exception('运送信息保存失败');
- }
- }
- $conveyCate = Db::name('convey_cate')
- ->where('id', $data['type'])
- ->find();
- if ($conveyCate['cate'] == 1) {
- $patient = [
- 'order_id' => $orderId,
- 'bed_number' => isset($data['bed_number']) ? $data['bed_number'] : '',
- 'name' => isset($data['p_name']) ? $data['p_name'] : '',
- 'ba_number' => isset($data['ba_number']) ? $data['ba_number'] : '',
- 'gender' => isset($data['gender']) && !empty($data['gender']) ? $data['gender'] : 0,
- 'back' => isset($data['back']) && !empty($data['back']) ? $data['back'] : 0,
- ];
- $cp = Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->find();
- if($cp){
- Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->update($patient);
- }else{
- $ocPid = Db::name('order_convey_patient')
- ->insertGetId($patient);
- if (!$ocPid) {
- exception('保存运送病人扩展失败');
- }
- }
- }
- }else{
- Db::name('order_convey')
- ->where('order_id',$orderId)
- ->delete();
- Db::name('order_convey_patient')
- ->where('order_id',$orderId)
- ->delete();
- }
- $this->commit();
- return true;
- } catch (Exception $e) {
- $this->rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- }
- // 投诉已处理推送给投诉人
- public function pushCreateUser($orderId,$userId=0){
- if($orderId > 0){
- $info = Db::name('complain')->where('order_id',$orderId)->where('del',0)->find();
- if($info){
- send_jpush([$info['create_user_id']],AppMsg::PUSH_COMPLAIN_FINISH);
- }
- }else{
- if($userId > 0){
- send_jpush([$userId],AppMsg::PUSH_COMPLAIN_FINISH);
- }
- }
- }
- }
|