Orders.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\common\model\Config;
  5. use app\hander\HelpHander;
  6. use think\App;
  7. use think\Db;
  8. use think\Exception;
  9. use think\exception\Handle;
  10. class Orders extends Base {
  11. public function __construct(App $app = null) {
  12. parent::__construct($app);
  13. $this->model = new \app\common\model\Orders();
  14. }
  15. public function lists() {
  16. $page = input('page', 1);
  17. $size = input('size', 10);
  18. $type = input('curOrderMode', 0);
  19. $list = $this->model->lists($page, $size, $type, $this->userId, $this->orgId);
  20. HelpHander::success($list);
  21. }
  22. public function detail() {
  23. $orderId = input('orderId', 0);
  24. $info = $this->model->detail($orderId);
  25. HelpHander::success($info);
  26. }
  27. //获取部门
  28. public function getDep() {
  29. $list = model('dep')->getList($this->orgId);
  30. HelpHander::success($list);
  31. }
  32. //发起订单
  33. public function add() {
  34. $json = [
  35. 'user_id'=>$this->userId,
  36. 'org_id'=>$this->orgId,
  37. 'dep_id'=>input('depId/d',0),
  38. 'images'=>input('images',''),
  39. 'videos'=>input('videos',''),
  40. 'voices'=>input('voices',''),
  41. 'content'=>input('content',''),
  42. 'work_type_mode'=>input('workTypeMode/d',1),
  43. 'source_type'=>input('sourceType/d',1),
  44. 'type_id'=>input('typeId/d',0),
  45. 'address_id'=>input('addressId/d',0),
  46. 'start'=>input('start',''),
  47. 'end'=>input('end',''),
  48. 'xq_time'=>input('xqTime',''),
  49. 'ywc_time'=>input('ywcTime',''),
  50. 'type'=>input('type',''),
  51. 'device_id'=>input('deviceId',''),
  52. 'priority'=>input('priority',''),
  53. 'bed_number'=>input('bedNumber',''),
  54. 'ba_number'=>input('baNumber',''),
  55. 'p_name'=>input('pName',''),
  56. 'gender'=>input('gender',''),
  57. 'back'=>input('back',''),
  58. 'name'=>input('name',''),
  59. 'phone'=>input('phone',''),
  60. 'isSpontaneous'=>input('isSpontaneous',0),
  61. 'repair_priority'=>input('repairPriority',2),
  62. 'way_addr'=>input('wayAddr','','trim'),
  63. ];
  64. $res = $this->model->addSave($json);
  65. if (!$res) {
  66. HelpHander::error($this->model->getError());
  67. }
  68. HelpHander::success('操作成功');
  69. }
  70. //调度发单
  71. public function dispatchAdd() {
  72. $json = [
  73. 'user_id'=>$this->userId,
  74. 'org_id'=>$this->orgId,
  75. 'dep_id'=>input('depId/d',0),
  76. 'images'=>input('images',''),
  77. 'videos'=>input('videos',''),
  78. 'voices'=>input('voices',''),
  79. 'content'=>input('content',''),
  80. 'work_type_mode'=>input('workTypeMode/d',1),
  81. 'userType'=>input('userType/d',0),
  82. 'to_user_id'=>input('toUserId',''),
  83. 'to_roles_id'=>input('toRolesId/d',0),
  84. 'type_id'=>input('typeId/d',0),
  85. 'address_id'=>input('addressId/d',0),
  86. 'source_type'=>input('sourceType/d',1),
  87. 'todo_content'=>input('todoContent',''),
  88. 'start'=>input('start',''),
  89. 'end'=>input('end',''),
  90. 'xq_time'=>input('xqTime',''),
  91. 'ywc_time'=>input('ywcTime',''),
  92. 'type'=>input('type',''),
  93. 'device_id'=>input('deviceId',''),
  94. 'priority'=>input('priority',''),
  95. 'bed_number'=>input('bedNumber',''),
  96. 'ba_number'=>input('baNumber',''),
  97. 'p_name'=>input('pName',''),
  98. 'gender'=>input('gender',''),
  99. 'back'=>input('back',''),
  100. 'name'=>input('name',''),
  101. 'phone'=>input('phone',''),
  102. 'daily_record_id'=>input('dailyRecordId/d',0), // 品质整改,日常工作记录id
  103. 'repair_priority'=>input('repairPriority',1),
  104. 'quality_type'=>input('qualityType/d',0),
  105. 'quality_cate'=>input('qualityCate/d',0),
  106. 'informer_user'=>input('informerUser/d',0),
  107. 'way_addr'=>input('wayAddr','','trim'),
  108. ];
  109. $res = $this->model->addSave($json, 1);
  110. if (!$res) {
  111. HelpHander::error($this->model->getError());
  112. }
  113. HelpHander::success('操作成功');
  114. }
  115. //分配订单
  116. public function send(){
  117. $json = [
  118. 'org_id'=>$this->orgId,
  119. 'id'=>input('id/d',0),
  120. 'userType'=>input('userType/d',0),
  121. 'to_user_id'=>input('toUserId',''),
  122. 'to_roles_id'=>input('toRolesId/d',0),
  123. 'type_id'=>input('typeId/d',0),
  124. 'address_id'=>input('addressId/d',0),
  125. 'todo_content'=>input('todoContent',''),
  126. 'work_type_mode'=>input('workTypeMode/d',-1),
  127. 'ba_number'=>input('baNumber','','trim'),
  128. 'back'=>input('back/d',0),
  129. 'bed_number'=>input('bedNumber','','trim'),
  130. 'device_id'=>input('deviceId/d',0),
  131. 'start'=>input('start/d',0),
  132. 'end'=>input('end/d',0),
  133. 'gender'=>input('gender/d',0),
  134. 'name'=>input('name','','trim'),
  135. 'phone'=>input('phone','','trim'),
  136. 'p_name'=>input('pName','','trim'),
  137. 'priority'=>input('priority/d',0),
  138. 'type'=>input('type/d',0),
  139. 'xq_time'=>input('xqTime','','trim'),
  140. 'ywc_time'=>input('ywcTime','','trim'),
  141. 'repair_priority'=>input('repairPriority','','trim'),
  142. ];
  143. $res = model('orders')->send($json['id'],$this->userId,$json);
  144. if(!$res){
  145. HelpHander::error(model('orders')->getError());
  146. }
  147. HelpHander::success('操作成功');
  148. }
  149. //转单分配订单
  150. public function zdSend(){
  151. $json = [
  152. 'org_id'=>$this->orgId,
  153. 'id'=>input('id/d',0),
  154. 'type_id'=>input('typeId/d',0),
  155. 'address_id'=>input('addressId/d',0),
  156. 'todo_content'=>input('todoContent',''),
  157. 'work_type_mode'=>input('workTypeMode/d',-1),
  158. 'ba_number'=>input('baNumber','','trim'),
  159. 'back'=>input('back/d',0),
  160. 'bed_number'=>input('bedNumber','','trim'),
  161. 'device_id'=>input('deviceId/d',0),
  162. 'start'=>input('start/d',0),
  163. 'end'=>input('end/d',0),
  164. 'gender'=>input('gender/d',0),
  165. 'name'=>input('name','','trim'),
  166. 'phone'=>input('phone','','trim'),
  167. 'p_name'=>input('pName','','trim'),
  168. 'priority'=>input('priority/d',0),
  169. 'type'=>input('type/d',0),
  170. 'xq_time'=>input('xqTime','','trim'),
  171. 'ywc_time'=>input('ywcTime','','trim'),
  172. 'repair_priority'=>input('repairPriority','','trim'),
  173. ];
  174. $res = model('orders')->zd_send($json['id'],$json);
  175. if(!$res){
  176. HelpHander::error(model('orders')->getError());
  177. }
  178. HelpHander::success('操作成功');
  179. }
  180. //任务栏工单列表
  181. public function queryOrderList() {
  182. $page = input('page', 1);
  183. $size = input('size', 10);
  184. $type = input('type', 0);
  185. $offset = ($page-1)*$size;
  186. $workType = [
  187. 1 => '报修工单',
  188. 2 => '保洁工单',
  189. 3 => '运送工单',
  190. 4 => '应急工单',
  191. 15 => '品质整改',
  192. 0 => '一键呼叫',
  193. ];
  194. $patrolStatus = [
  195. 0 => '未执行',
  196. 1 => '执行中',
  197. 2 => '已完成',
  198. 3 => '未完成',
  199. 5 => '中断',
  200. ];
  201. $list = [];
  202. $orgGrabOrder = getOrgGrabOrder($this->userId,$this->orgId);
  203. if(in_array($type,[1,2])){
  204. if($type==1){//已完成
  205. $map[] = ['todo_mode','=',3];
  206. $map[] = ['to_user_id','=',$this->userId];
  207. $map[] = ['del','=',0];
  208. $map[] = ['org_id','=',$this->orgId];
  209. $todoList = Db::name('todo')
  210. ->where($map)
  211. ->limit($offset,$size)
  212. ->order('id','desc')
  213. ->select();
  214. }elseif ($type==2){//已评价
  215. $todoList = Db::name('orders')
  216. ->alias('a')
  217. ->join('todo b','a.id=b.order_id')
  218. ->where('a.order_mode',6)
  219. ->where('a.del',0)
  220. ->where('a.org_id',$this->orgId)
  221. ->where('b.to_user_id',$this->userId)
  222. ->field('b.*')
  223. ->group('b.order_id')
  224. ->limit($offset,$size)
  225. ->order('b.id','desc')
  226. ->select();
  227. }
  228. foreach ($todoList as $k=>$todoInfo){
  229. $data['todo_id'] = $todoInfo['id'];
  230. $data['sn'] = $todoInfo['sn'];
  231. $data['title'] = $workType[$todoInfo['work_type_mode']];
  232. $data['realName'] = Db::name('user')
  233. ->where('id', $todoInfo['create_user_id'])
  234. ->value('real_name');
  235. $data['create_time'] = $todoInfo['create_time'];
  236. $data['status_txt'] = Db::name('todo_mode')
  237. ->where('id', $todoInfo['todo_mode'])
  238. ->value('out_content');
  239. $data['start_time'] = "";
  240. $data['end_time'] = "";
  241. $data['type'] = 1;
  242. $data['bus_id'] = 0;
  243. $orderInfo = Db::name('orders')
  244. ->where('id',$todoInfo['order_id'])
  245. ->find();
  246. if($orderInfo['from'] > 0){
  247. $from = '';
  248. if($orderInfo['from'] == 1){
  249. $from = '一键呼叫';
  250. }else if($orderInfo['from'] == 2){
  251. $from = '隐患预警';
  252. }else if($orderInfo['from'] == 3){
  253. $from = '投诉';
  254. }
  255. $data['title'] = $data['title'].'('.$from.')';
  256. }
  257. $data['patrol_mode'] = 0;
  258. $data['status'] = $todoInfo['todo_mode'];
  259. $data['work_type_mode'] = $orderInfo['work_type_mode'];
  260. if($data['work_type_mode'] == 1 && $todoInfo['todo_mode'] == 2 && $todoInfo['pause'] == 1){ //维修,检查是否挂起
  261. $data['status_txt'] = '已挂起';
  262. }
  263. $data['addressTitle'] = "";
  264. $data['typeName'] = "";
  265. $data['content'] = $orderInfo['content']?$orderInfo['content']:'';
  266. $data['startName'] = "";
  267. $data['endName'] = "";
  268. if($orderInfo['work_type_mode']==1){
  269. $typeInfo = (new \app\common\model\OrderType())
  270. ->getTypeByOrderId($orderInfo['id']);
  271. if($typeInfo){
  272. $order_type = $typeInfo && isset($typeInfo['title']) ? $typeInfo['title'] : '';
  273. $order_type_matter = $typeInfo && isset($typeInfo['child_title']) ? $typeInfo['child_title'] : '';
  274. $data['typeName'] = $order_type.'/'.$order_type_matter;
  275. $data['addressTitle'] = $typeInfo ? $typeInfo['address_title'] : '';
  276. }
  277. }
  278. $data['color'] ='';
  279. if($orderInfo['work_type_mode']==3){
  280. $oc = Db::name('order_convey')
  281. ->where('order_id', $orderInfo['id'])
  282. ->find();
  283. if($oc){
  284. $start_name = Db::name('address')->where('id',$oc['start'])
  285. ->value('title');
  286. $end_name = Db::name('address')->where('id',$oc['end'])
  287. ->value('title');
  288. $data['startName'] = $start_name?$start_name:"";
  289. $data['endName'] = $end_name?$end_name:"";
  290. $convey = Db::name('convey_cate')
  291. ->alias('oc')
  292. ->join('time ot', 'ot.id = oc.time_id')
  293. ->where('oc.id', $oc['type'])
  294. ->field('ot.*')
  295. ->find();
  296. $createtime = strtotime($orderInfo['create_time']);
  297. $curtime = time();
  298. $ct = round(($curtime - $createtime) / 60);
  299. $ss = 0;
  300. if ($ct >= $convey['yy_time']) {
  301. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  302. $ss = 1;
  303. } else {
  304. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  305. $ss = 2;
  306. } else {
  307. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  308. $ss = 3;
  309. } else {
  310. $ss = 4;
  311. }
  312. }
  313. }
  314. }
  315. // $delay = 0;
  316. // $delays = Db::name('order_delay')
  317. // ->where('order_id', $orderInfo['id'])
  318. // ->select();
  319. // $delays = $delays ? $delays : [];
  320. // foreach ($delays as $vv) {
  321. // if ($vv['status'] == 0) {
  322. // $delay = 1;
  323. // }
  324. // }
  325. // if ($delay == 1) {
  326. // $status = 3;
  327. // } else {
  328. // if ($orderInfo['order_mode'] == 1) {
  329. // $status = 1;
  330. // } else {
  331. // $status= 2;
  332. // }
  333. // }
  334. if($ss == 1){
  335. $data['color'] = '#acb3d8';
  336. }else if($ss == 2){
  337. $data['color'] = '#fff500';
  338. }else if($ss == 3){
  339. $data['color'] = '#ec891a';
  340. }else if($ss == 4){
  341. $data['color'] = '#e45946';
  342. }else{
  343. $data['color'] = '';
  344. }
  345. }
  346. }
  347. $data['priority'] = 0;
  348. $list[] = $data;
  349. }
  350. $r = [
  351. 'list' => $list,
  352. 'count' => count($list),
  353. 'org_grab_order'=>$orgGrabOrder?(int)$orgGrabOrder:0
  354. ];
  355. HelpHander::success($r);
  356. }
  357. $task = Db::name('task')
  358. ->where('user_id', $this->userId)
  359. ->where('org_id', $this->orgId)
  360. ->where('type', 1)
  361. ->limit($offset,$size)
  362. ->order(['priority'=>'desc','id'=>'desc'])
  363. ->select();
  364. foreach ($task as $k => $value) {
  365. if ($value['type'] == 1) {//工单
  366. $todoInfo = Db::name('todo')
  367. ->where('id', $value['bus_id'])
  368. ->where('del',0)
  369. ->find();
  370. if (!empty($todoInfo)) {
  371. $data['sn'] = $todoInfo['sn'];
  372. $data['title'] = $workType[$todoInfo['work_type_mode']];
  373. $data['realName'] = Db::name('user')
  374. ->where('id', $todoInfo['create_user_id'])
  375. ->value('real_name');
  376. $data['create_time'] = $todoInfo['create_time'];
  377. $data['status_txt'] = Db::name('todo_mode')
  378. ->where('id', $todoInfo['todo_mode'])
  379. ->value('out_content');
  380. $data['start_time'] = "";
  381. $data['end_time'] = "";
  382. $data['type'] = 1;
  383. $data['bus_id'] = $value['bus_id'];
  384. $orderInfo = Db::name('orders')
  385. ->where('id',$todoInfo['order_id'])
  386. ->find();
  387. if($orderInfo['from'] > 0){
  388. $from = '';
  389. if($orderInfo['from'] == 1){
  390. $from = '一键呼叫';
  391. }else if($orderInfo['from'] == 2){
  392. $from = '隐患预警';
  393. }else if($orderInfo['from'] == 3){
  394. $from = '投诉';
  395. }
  396. $data['title'] = $data['title'].'('.$from.')';
  397. }
  398. $data['patrol_mode'] = 0;
  399. $data['status'] = $todoInfo['todo_mode'];
  400. $data['work_type_mode'] = $orderInfo['work_type_mode'];
  401. if($data['work_type_mode'] == 1 && $todoInfo['todo_mode'] == 2 && $todoInfo['pause'] == 1){ //维修,检查是否挂起
  402. $data['status_txt'] = '已挂起';
  403. }
  404. $data['addressTitle'] = "";
  405. $data['typeName'] = "";
  406. $data['content'] = $orderInfo['content']?$orderInfo['content']:'';
  407. $data['startName'] = "";
  408. $data['endName'] = "";
  409. if($orderInfo['work_type_mode']==1){
  410. $typeInfo = (new \app\common\model\OrderType())
  411. ->getTypeByOrderId($orderInfo['id']);
  412. if($typeInfo){
  413. $order_type = $typeInfo && isset($typeInfo['title']) ? $typeInfo['title'] : '';
  414. $order_type_matter = $typeInfo && isset($typeInfo['child_title']) ? $typeInfo['child_title'] : '';
  415. $data['typeName'] = $order_type.'/'.$order_type_matter;
  416. $data['addressTitle'] = $typeInfo ? $typeInfo['address_title'] : '';
  417. }
  418. }
  419. $data['color'] ='';
  420. $data['start_status'] = 0;
  421. if($orderInfo['work_type_mode']==3){
  422. $oc = Db::name('order_convey')
  423. ->where('order_id', $orderInfo['id'])
  424. ->find();
  425. if($oc){
  426. $start_name = Db::name('address')->where('id',$oc['start'])
  427. ->value('title');
  428. $end_name = Db::name('address')->where('id',$oc['end'])
  429. ->value('title');
  430. $data['startName'] = $start_name?$start_name:"";
  431. $data['endName'] = $end_name?$end_name:"";
  432. $convey = Db::name('convey_cate')
  433. ->alias('oc')
  434. ->join('time ot', 'ot.id = oc.time_id')
  435. ->where('oc.id', $oc['type'])
  436. ->field('ot.*')
  437. ->find();
  438. $createtime = strtotime($orderInfo['create_time']);
  439. $curtime = time();
  440. $ct = round(($curtime - $createtime) / 60);
  441. $ss = 0;
  442. if ($ct >= $convey['yy_time']) {
  443. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  444. $ss = 1;
  445. } else {
  446. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  447. $ss = 2;
  448. } else {
  449. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  450. $ss = 3;
  451. } else {
  452. $ss = 4;
  453. }
  454. }
  455. }
  456. }
  457. // $delay = 0;
  458. // $delays = Db::name('order_delay')
  459. // ->where('order_id', $orderInfo['id'])
  460. // ->select();
  461. // $delays = $delays ? $delays : [];
  462. // foreach ($delays as $vv) {
  463. // if ($vv['status'] == 0) {
  464. // $delay = 1;
  465. // }
  466. // }
  467. // if ($delay == 1) {
  468. // $status = 3;
  469. // } else {
  470. // if ($orderInfo['order_mode'] == 1) {
  471. // $status = 1;
  472. // } else {
  473. // $status= 2;
  474. // }
  475. // }
  476. if($ss == 1){
  477. $data['color'] = '#acb3d8';
  478. }else if($ss == 2){
  479. $data['color'] = '#fff500';
  480. }else if($ss == 3){
  481. $data['color'] = '#ec891a';
  482. }else if($ss == 4){
  483. $data['color'] = '#e45946';
  484. }else{
  485. $data['color'] = '';
  486. }
  487. }
  488. $todo_convey = Db::name('todo_convey')
  489. ->where('todo_id',$todoInfo['id'])
  490. ->find();
  491. $start_status = isset($todo_convey['start_time'])&& !empty($todo_convey['start_time'])?1:0;
  492. $data['start_status'] = $start_status;
  493. }
  494. $data['priority'] = $value['priority'];
  495. $list[] = $data;
  496. }
  497. } elseif($value['type'] == 2) {//巡更巡检
  498. $patrolInfo = Db::name('patrol_task')
  499. ->where('id', $value['bus_id'])
  500. ->find();
  501. if (!empty($patrolInfo)) {
  502. $title = Db::name('patrol_mode')
  503. ->where('id', $patrolInfo['patrol_mode'])
  504. ->value('name');
  505. $data['title'] = $patrolInfo['title']?$title.'-'.$patrolInfo['title']:$title;
  506. $data['realName'] = "";
  507. $data['create_time'] = $patrolInfo['create_time'];
  508. $data['status_txt'] = $patrolStatus[$patrolInfo['status']];
  509. $data['start_time'] = $patrolInfo['start_time'];
  510. $data['end_time'] = $patrolInfo['end_time'];
  511. $data['bus_id'] = $value['bus_id'];
  512. $data['type'] = 2;
  513. $data['work_type_mode'] = 0;
  514. $data['patrol_mode'] = $patrolInfo['patrol_mode'];
  515. $data['status'] = $patrolInfo['status'];
  516. $data['addressTitle'] = "";
  517. $data['typeName'] = "";
  518. $data['content'] = '';
  519. $data['startName'] = "";
  520. $data['endName'] = "";
  521. $data['priority'] = $value['priority'];
  522. $list[] = $data;
  523. }
  524. }elseif ($value['type'] == 3){ // 日常工作
  525. $dailyInfo = Db::name('daily_task')
  526. ->where('id', $value['bus_id'])
  527. ->find();
  528. if (!empty($dailyInfo)) {
  529. $data['title'] = '日常工作';
  530. $data['realName'] = "";
  531. $data['create_time'] = $dailyInfo['create_time'];
  532. $data['status_txt'] = $patrolStatus[$dailyInfo['status']];
  533. $data['start_time'] = $dailyInfo['start_time'];
  534. $data['end_time'] = $dailyInfo['end_time'];
  535. $data['bus_id'] = $value['bus_id'];
  536. $data['type'] = 3;
  537. $data['work_type_mode'] = 0;
  538. $data['patrol_mode'] = 0;
  539. $data['status'] = $dailyInfo['status'];
  540. $data['addressTitle'] = "";
  541. $data['typeName'] = "";
  542. $data['content'] = '';
  543. $data['startName'] = "";
  544. $data['endName'] = "";
  545. $data['priority'] = $value['priority'];
  546. $list[] = $data;
  547. }
  548. }elseif ($value['type'] == 4){ // 设备台账
  549. $deviceInfo = Db::name('device_task')
  550. ->where('id', $value['bus_id'])
  551. ->find();
  552. if (!empty($deviceInfo)) {
  553. $data['title'] = $deviceInfo['title']? '设备维保'.'-'.$deviceInfo['title']:'设备维保';
  554. $data['realName'] = "";
  555. $data['create_time'] = $deviceInfo['create_time'];
  556. $data['status_txt'] = $patrolStatus[$deviceInfo['status']];
  557. $data['start_time'] = $deviceInfo['start_time'];
  558. $data['end_time'] = $deviceInfo['end_time'];
  559. $data['bus_id'] = $value['bus_id'];
  560. $data['type'] = 4;
  561. $data['work_type_mode'] = 0;
  562. $data['patrol_mode'] = 0;
  563. $data['status'] = $deviceInfo['status'];
  564. $data['addressTitle'] = "";
  565. $data['typeName'] = "";
  566. $data['content'] = '';
  567. $data['startName'] = "";
  568. $data['endName'] = "";
  569. $data['priority'] = $value['priority'];
  570. $list[] = $data;
  571. }
  572. }
  573. }
  574. $r = [
  575. 'list' => $list,
  576. 'count' => count($list),
  577. 'org_grab_order'=>$orgGrabOrder?(int)$orgGrabOrder:0
  578. ];
  579. HelpHander::success($r);
  580. }
  581. //抢单列表
  582. public function queryGrabOrders(){
  583. $page = input('page', 1);
  584. $size = input('size', 10);
  585. $list = $this->model->queryGrabOrders($page,$size,$this->userId,$this->orgId);
  586. HelpHander::success($list);
  587. }
  588. // 抢单
  589. public function grabOrders(){
  590. $orderId = input('orderId');
  591. $orderType = input('orderType/d',0);
  592. $addressId = input('addressId/d',0);
  593. $order = Db::name('orders')
  594. ->where('id',$orderId)
  595. ->where('org_id',$this->orgId)
  596. ->find();
  597. if($order['work_type_mode']==1 && empty($orderType)){
  598. HelpHander::error('报修事项不能为空');
  599. }
  600. if(!$order || $order['del'] == 1){
  601. HelpHander::error('订单不存在');
  602. }
  603. if($order['order_mode'] != 1){
  604. HelpHander::error('订单已被处理');
  605. }
  606. $off = (new Config())->getConfig('org_grab_order'.$order['work_type_mode'],$this->orgId);
  607. if($off !=1){
  608. HelpHander::error('抢单模式未开启');
  609. }
  610. $ret = $this->model->grabOrdersEdit($order,$this->userId,$orderType,$addressId);
  611. if(!$ret){
  612. HelpHander::error($this->model->getError());
  613. }
  614. HelpHander::success([],'操作成功');
  615. }
  616. // 扫标本
  617. public function scanSample(){
  618. $orderId = input('orderId/d',0);
  619. $barcode = input('barcode');
  620. $addrId = input('addrId/d',0);
  621. if(!$barcode ){
  622. HelpHander::error('未传标本码');
  623. }
  624. if(!$orderId&&!$addrId){
  625. HelpHander::error('参数错误');
  626. }
  627. if($orderId > 0){
  628. $orderConvey = Db::name('order_convey')
  629. ->where('order_id',$orderId)
  630. ->find();
  631. $addrId = $orderConvey['start'];
  632. }
  633. $res = Db::name('order_convey_lis')
  634. ->where('org_id',$this->orgId)
  635. ->where('order_id',$orderId)
  636. ->where('barcode',$barcode)
  637. ->where('user_id',$this->userId)
  638. ->where('addr_id',$addrId)
  639. ->find();
  640. Db::startTrans();
  641. try{
  642. if($res){
  643. $res = Db::name('order_convey_lis')
  644. ->where('id',$res['id'])->update([
  645. 'create_time' => date('Y-m-d H:i:s')
  646. ]);
  647. }else{
  648. $res = Db::name('order_convey_lis')
  649. ->insert([
  650. 'order_id' => $orderId,
  651. 'barcode' => $barcode,
  652. 'user_id' => $this->userId,
  653. 'create_time' => date('Y-m-d H:i:s'),
  654. 'org_id' => $this->orgId,
  655. 'addr_id' => $addrId
  656. ]);
  657. }
  658. if(!$res){
  659. exception('操作失败');
  660. }
  661. Db::commit();
  662. HelpHander::success([],'操作成功');
  663. }catch (Exception $e){
  664. Db::rollback();
  665. HelpHander::error($e->getMessage());
  666. }
  667. }
  668. //用户订单列表
  669. public function queryUserOrdersByMode(){
  670. $page = input('page', 1);
  671. $size = input('size', 10);
  672. $mode = input('mode', 0);
  673. $type = input('type', 0);
  674. $ret=$this->model->userOrdersByMode($page,$size,$this->userId,$mode,$type,$this->orgId);
  675. HelpHander::success($ret);
  676. }
  677. //用户取消订单
  678. public function updateOrderModeByUser(){
  679. $orderId = input('orderId', 0);
  680. $reason = input('reason', '','trim');
  681. $ret=$this->model->cancel($orderId,$this->userId,1,$reason);
  682. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  683. }
  684. //调度取消订单
  685. public function updateOrderModeByDispatch(){
  686. $orderId = input('orderId', 0);
  687. $reason = input('reason', '');
  688. if(!$reason){
  689. HelpHander::error('请填写取消原因');
  690. }
  691. $ret=$this->model->cancel($orderId,$this->userId,2,$reason);
  692. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  693. }
  694. //调度完成订单
  695. public function finishOrder(){
  696. $orderId = input('orderId', 0);
  697. $ret=$this->model->finish($orderId);
  698. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  699. }
  700. //所有订单
  701. public function queryAllOrder(){
  702. $page = input('page', 1);
  703. $size = input('size', 10);
  704. $workTypeMode = input('workTypeMode/d',-1);
  705. $currOrderMode = input('currOrderMode');
  706. $beginTime = input('beginTime');
  707. $endTime = input('endTime');
  708. $list = $this->model->queryAllOrder($this->orgId,$page,$size,$workTypeMode,$currOrderMode,$beginTime,$endTime);
  709. HelpHander::success($list);
  710. }
  711. // 工人添加下一站地址
  712. public function addConveyEnd(){
  713. $orderId = input('orderId/d',0);
  714. $addrId = input('addrId/d',0);
  715. $ret = $this->model->addConveyEnd($this->orgId,$orderId,$addrId);
  716. if(!$ret){
  717. HelpHander::error($this->model->getError());
  718. }
  719. HelpHander::success([],'成功');
  720. }
  721. // 支付运送病人
  722. public function pay(){
  723. $id = input('id/d',0);
  724. $remark = input('remark','','trim');
  725. $info = Db::name('order_convey_pay')->where('id',$id)->find();
  726. if(!$info){
  727. HelpHander::error('订单不存在');
  728. }
  729. if($info['status'] == 1){
  730. HelpHander::error('订单已支付');
  731. }
  732. $res = Db::name('order_convey_pay')->where('id',$id)->update([
  733. 'type' => 1,
  734. 'status' => 1,
  735. 'remark' => $remark,
  736. 'pay_time' => date('Y-m-d H:i:s')
  737. ]);
  738. if($res){
  739. HelpHander::success([],'操作成功');
  740. }else{
  741. HelpHander::error('操作失败');
  742. }
  743. }
  744. // 扫途径地点
  745. public function sweepCode(){
  746. $code = input('code');
  747. $id = input('id/d',0);
  748. $num = input('num/d',0);
  749. $img = input('img','');
  750. $ret = model('Orders')->sweepCode($code,$id,$num,$img,$this->orgId,$this->userId);
  751. if(!$ret){
  752. HelpHander::error(model('Orders')->getError());
  753. }
  754. HelpHander::success([],'操作成功');
  755. }
  756. //获取可转单类型
  757. public function orderTransferType(){
  758. $user = Db::name('user')->where('id',$this->userId)->find();
  759. $config = model('Config')->getConfig('web_order_transfer_type');
  760. $modes = $config?explode('|',$config):[];
  761. if($user['type'] != 1){ // 不是总公司人员
  762. $roles = Db::name('user_roles')
  763. ->alias('a')
  764. ->join('roles b','b.id = a.roles_id')
  765. ->where('a.user_id',$this->userId)
  766. ->value('work_type_mode');
  767. if($roles){
  768. $modes = explode(',',$roles);
  769. }
  770. }
  771. $map[] = ['type','=',1];
  772. if($modes){
  773. $map[] = ['id','in',$modes];
  774. }else{
  775. $map[] = ['id','=',-1];
  776. }
  777. $workType = Db::name('work_type_mode')
  778. ->where($map)
  779. ->field('id,name as title')
  780. ->select();
  781. HelpHander::success($workType?$workType:[]);
  782. }
  783. //获取待处理已完成已评价订单数量
  784. public function getOrdersCount(){
  785. $map[] = ['user_id','=',$this->userId];
  786. $map[] = ['org_id','=',$this->orgId];
  787. $map[] = ['del','=',0];
  788. $a1 = Db::name('orders')
  789. ->where($map)
  790. ->where('order_mode',1)
  791. ->count();
  792. $dcl = $a1?$a1:0;
  793. $a2 = Db::name('orders')
  794. ->where($map)
  795. ->where('order_mode',5)
  796. ->count();
  797. $ywc = $a2?$a2:0;
  798. $a3 = Db::name('orders')
  799. ->where($map)
  800. ->where('order_mode',6)
  801. ->count();
  802. $ypj = $a3?$a3:0;
  803. $data = [
  804. 'dcl'=>$dcl,
  805. 'ywc'=>$ywc,
  806. 'ypj'=>$ypj,
  807. ];
  808. HelpHander::success($data);
  809. }
  810. //被驳回的数量
  811. public function rejectCount(){
  812. $map[] = ['org_id', '=', $this->orgId];
  813. $map[] = ['del', '=', 0];
  814. $map2[] = ['todo_mode', '=', 4];
  815. $auth = get_dispatch_auth($this->userId);
  816. if (empty($auth)) {
  817. $map[] = ['work_type_mode', '=', -1];
  818. }
  819. else {
  820. $map[] = ['work_type_mode', 'in', $auth];
  821. }
  822. $org_two_dispatch = (new Config())->getConfig('org_two_dispatch',$this->orgId);
  823. if($org_two_dispatch==0){//二级调度开关关闭
  824. }else{
  825. if (check_two_dispatch($this->userId) == 1) {//二级调度角色
  826. $roles_id = Db::name('user_roles')
  827. ->where('user_id',$this->userId)
  828. ->value('roles_id');
  829. $ids = Db::name('dispatch_log')
  830. ->where('roles_id', $roles_id)
  831. ->whereOr('to_user_id', $this->userId)
  832. ->column('order_id');
  833. if (empty($ids)) {
  834. $map2[] = ['order_id', '=', -1];
  835. }else {
  836. $map2[] = ['order_id', 'in', $ids];
  837. }
  838. }
  839. }
  840. $count = Db::name('todo_view')
  841. ->where($map)
  842. ->where($map2)
  843. ->count();
  844. HelpHander::success($count);
  845. }
  846. //优先级
  847. public function repair_priority(){
  848. $a = [
  849. ['id'=>1,'title'=>"可延缓的"],
  850. ['id'=>2,'title'=>"普通"],
  851. ['id'=>3,'title'=>"紧急"],
  852. ];
  853. HelpHander::success($a);
  854. }
  855. public function userQualityLists() {
  856. $page = input('page', 1);
  857. $size = input('size', 10);
  858. $list = $this->model->userQualityLists($page, $size, $this->userId, $this->orgId);
  859. HelpHander::success($list);
  860. }
  861. public function informerQualityLists() {
  862. $page = input('page', 1);
  863. $size = input('size', 10);
  864. $list = $this->model->informerQualityLists($page, $size, $this->userId, $this->orgId);
  865. HelpHander::success($list);
  866. }
  867. //巡更巡视..一键呼叫发送给自己转成报修单;
  868. public function addBxOrders(){
  869. $data = [
  870. 'user_id'=>$this->userId,
  871. 'org_id'=>$this->orgId,
  872. 'dep_id'=>input('depId/d',0),
  873. 'images'=>input('images',''),
  874. 'videos'=>input('videos',''),
  875. 'voices'=>input('voices',''),
  876. 'content'=>input('content',''),
  877. 'work_type_mode'=>input('workTypeMode/d',1),
  878. 'source_type'=>input('sourceType/d',4),
  879. 'type_id'=>input('typeId',0),
  880. 'address_id'=>input('addressId',0),
  881. 'repair_priority'=>input('repairPriority',0),
  882. ];
  883. $res = model('Orders')->addBxOrders($data);
  884. if (!$res) {
  885. HelpHander::error(model('Orders')->getError());
  886. }
  887. HelpHander::success([],'操作成功');
  888. }
  889. public function withdraw(){
  890. $id = input('id');
  891. $info = Db::name('orders')
  892. ->where('id',$id)
  893. ->where('del',0)
  894. ->where('order_mode',4)
  895. ->find();
  896. if(!$info){
  897. HelpHander::error('参数错误');
  898. }
  899. $saveOrder = Db::name('orders')
  900. ->where('id',$id)
  901. ->update(['order_mode'=>1,'withdraw_time'=>getTime()]);
  902. Db::name('todo')->where('order_id',$id)->update(['del'=>1]);
  903. $todoIds = Db::name('todo')
  904. ->where('order_id',$id)
  905. ->where('todo_mode',1)
  906. ->column('id');
  907. Db::name('task')
  908. ->where('type',1)
  909. ->whereIn('bus_id',$todoIds)
  910. ->delete();
  911. if($info['work_type_mode'] == 3){
  912. Db::name('order_convey_end')->where('order_id',$info['id'])->setField('del',0);
  913. }
  914. if(!$saveOrder){
  915. HelpHander::error('操作失败');
  916. }
  917. HelpHander::success('操作成功');
  918. }
  919. //病人运送订单删除途径地
  920. public function delOrdersConveyEnd(){
  921. $id = input('id/d',0);
  922. $ret = $ret = Db::name('order_convey_end')
  923. ->where('id',$id)->update([
  924. 'del' => 1,
  925. 'update_time' => date('Y-m-d H:i:s')
  926. ]);
  927. if(!$ret){
  928. HelpHander::error('删除失败');
  929. }
  930. HelpHander::success([],'操作成功');
  931. }
  932. //病人运送订单删除目的地
  933. public function delConveyEnd(){
  934. $orderId = input('orderId/d',0);
  935. $ret = model('Orders')->delConveyEnd($orderId,$this->orgId);
  936. if(!$ret){
  937. HelpHander::error(model('Orders')->getError());
  938. }
  939. HelpHander::success([],'操作成功');
  940. }
  941. public function orderConveyEndInfo(){
  942. $id = input('id');
  943. $info = Db::name('order_convey_end')
  944. ->where('id',$id)
  945. ->where('del',0)
  946. ->find();
  947. HelpHander::success($info);
  948. }
  949. }