0
0

Orders.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. ];
  63. $res = $this->model->addSave($json);
  64. if (!$res) {
  65. HelpHander::error($this->model->getError());
  66. }
  67. HelpHander::success('操作成功');
  68. }
  69. //调度发单
  70. public function dispatchAdd() {
  71. $json = [
  72. 'user_id'=>$this->userId,
  73. 'org_id'=>$this->orgId,
  74. 'dep_id'=>input('depId/d',0),
  75. 'images'=>input('images',''),
  76. 'videos'=>input('videos',''),
  77. 'voices'=>input('voices',''),
  78. 'content'=>input('content',''),
  79. 'work_type_mode'=>input('workTypeMode/d',1),
  80. 'userType'=>input('userType/d',0),
  81. 'to_user_id'=>input('toUserId',''),
  82. 'to_roles_id'=>input('toRolesId/d',0),
  83. 'type_id'=>input('typeId/d',0),
  84. 'address_id'=>input('addressId/d',0),
  85. 'source_type'=>input('sourceType/d',1),
  86. 'todo_content'=>input('todoContent',''),
  87. 'start'=>input('start',''),
  88. 'end'=>input('end',''),
  89. 'xq_time'=>input('xqTime',''),
  90. 'ywc_time'=>input('ywcTime',''),
  91. 'type'=>input('type',''),
  92. 'device_id'=>input('deviceId',''),
  93. 'priority'=>input('priority',''),
  94. 'bed_number'=>input('bedNumber',''),
  95. 'ba_number'=>input('baNumber',''),
  96. 'p_name'=>input('pName',''),
  97. 'gender'=>input('gender',''),
  98. 'back'=>input('back',''),
  99. 'name'=>input('name',''),
  100. 'phone'=>input('phone',''),
  101. 'daily_record_id'=>input('dailyRecordId/d',0), // 品质整改,日常工作记录id
  102. 'repair_priority'=>input('repairPriority',1),
  103. 'quality_type'=>input('qualityType/d',0),
  104. 'quality_cate'=>input('qualityCate/d',0),
  105. 'informer_user'=>input('informerUser/d',0),
  106. ];
  107. $res = $this->model->addSave($json, 1);
  108. if (!$res) {
  109. HelpHander::error($this->model->getError());
  110. }
  111. HelpHander::success('操作成功');
  112. }
  113. //分配订单
  114. public function send(){
  115. $json = [
  116. 'org_id'=>$this->orgId,
  117. 'id'=>input('id/d',0),
  118. 'userType'=>input('userType/d',0),
  119. 'to_user_id'=>input('toUserId',''),
  120. 'to_roles_id'=>input('toRolesId/d',0),
  121. 'type_id'=>input('typeId/d',0),
  122. 'address_id'=>input('addressId/d',0),
  123. 'todo_content'=>input('todoContent',''),
  124. 'work_type_mode'=>input('workTypeMode/d',-1),
  125. 'ba_number'=>input('baNumber','','trim'),
  126. 'back'=>input('back/d',0),
  127. 'bed_number'=>input('bedNumber','','trim'),
  128. 'device_id'=>input('deviceId/d',0),
  129. 'start'=>input('start/d',0),
  130. 'end'=>input('end/d',0),
  131. 'gender'=>input('gender/d',0),
  132. 'name'=>input('name','','trim'),
  133. 'phone'=>input('phone','','trim'),
  134. 'p_name'=>input('pName','','trim'),
  135. 'priority'=>input('priority/d',0),
  136. 'type'=>input('type/d',0),
  137. 'xq_time'=>input('xqTime','','trim'),
  138. 'ywc_time'=>input('ywcTime','','trim'),
  139. 'repair_priority'=>input('repairPriority','','trim'),
  140. ];
  141. $res = model('orders')->send($json['id'],$this->userId,$json);
  142. if(!$res){
  143. HelpHander::error(model('orders')->getError());
  144. }
  145. HelpHander::success('操作成功');
  146. }
  147. //转单分配订单
  148. public function zdSend(){
  149. $json = [
  150. 'org_id'=>$this->orgId,
  151. 'id'=>input('id/d',0),
  152. 'type_id'=>input('typeId/d',0),
  153. 'address_id'=>input('addressId/d',0),
  154. 'todo_content'=>input('todoContent',''),
  155. 'work_type_mode'=>input('workTypeMode/d',-1),
  156. 'ba_number'=>input('baNumber','','trim'),
  157. 'back'=>input('back/d',0),
  158. 'bed_number'=>input('bedNumber','','trim'),
  159. 'device_id'=>input('deviceId/d',0),
  160. 'start'=>input('start/d',0),
  161. 'end'=>input('end/d',0),
  162. 'gender'=>input('gender/d',0),
  163. 'name'=>input('name','','trim'),
  164. 'phone'=>input('phone','','trim'),
  165. 'p_name'=>input('pName','','trim'),
  166. 'priority'=>input('priority/d',0),
  167. 'type'=>input('type/d',0),
  168. 'xq_time'=>input('xqTime','','trim'),
  169. 'ywc_time'=>input('ywcTime','','trim'),
  170. 'repair_priority'=>input('repairPriority','','trim'),
  171. ];
  172. $res = model('orders')->zd_send($json['id'],$json);
  173. if(!$res){
  174. HelpHander::error(model('orders')->getError());
  175. }
  176. HelpHander::success('操作成功');
  177. }
  178. //任务栏工单列表
  179. public function queryOrderList() {
  180. $page = input('page', 1);
  181. $size = input('size', 10);
  182. $offset = ($page-1)*$size;
  183. $task = Db::name('task')
  184. ->where('user_id', $this->userId)
  185. ->where('org_id', $this->orgId)
  186. ->where('type', 1)
  187. ->limit($offset,$size)
  188. ->order(['priority'=>'desc','id'=>'desc'])
  189. ->select();
  190. $workType = [
  191. 1 => '报修工单',
  192. 2 => '保洁工单',
  193. 3 => '运送工单',
  194. 4 => '应急工单',
  195. 15 => '品质整改',
  196. 0 => '一键呼叫',
  197. ];
  198. $patrolStatus = [
  199. 0 => '未执行',
  200. 1 => '执行中',
  201. 2 => '已完成',
  202. 3 => '未完成',
  203. 5 => '中断',
  204. ];
  205. $list = [];
  206. foreach ($task as $k => $value) {
  207. if ($value['type'] == 1) {//工单
  208. $todoInfo = Db::name('todo')
  209. ->where('id', $value['bus_id'])
  210. ->where('del',0)
  211. ->find();
  212. if (!empty($todoInfo)) {
  213. $data['sn'] = $todoInfo['sn'];
  214. $data['title'] = $workType[$todoInfo['work_type_mode']];
  215. $data['realName'] = Db::name('user')
  216. ->where('id', $todoInfo['create_user_id'])
  217. ->value('real_name');
  218. $data['create_time'] = $todoInfo['create_time'];
  219. $data['status_txt'] = Db::name('todo_mode')
  220. ->where('id', $todoInfo['todo_mode'])
  221. ->value('out_content');
  222. $data['start_time'] = "";
  223. $data['end_time'] = "";
  224. $data['type'] = 1;
  225. $data['bus_id'] = $value['bus_id'];
  226. $orderInfo = Db::name('orders')
  227. ->where('id',$todoInfo['order_id'])
  228. ->find();
  229. if($orderInfo['from'] > 0){
  230. $from = '';
  231. if($orderInfo['from'] == 1){
  232. $from = '一键呼叫';
  233. }else if($orderInfo['from'] == 2){
  234. $from = '隐患预警';
  235. }else if($orderInfo['from'] == 3){
  236. $from = '投诉';
  237. }
  238. $data['title'] = $data['title'].'('.$from.')';
  239. }
  240. $data['patrol_mode'] = 0;
  241. $data['status'] = $todoInfo['todo_mode'];
  242. $data['work_type_mode'] = $orderInfo['work_type_mode'];
  243. if($data['work_type_mode'] == 1 && $todoInfo['todo_mode'] == 2 && $todoInfo['pause'] == 1){ //维修,检查是否挂起
  244. $data['status_txt'] = '已挂起';
  245. }
  246. $data['addressTitle'] = "";
  247. $data['typeName'] = "";
  248. $data['content'] = $orderInfo['content']?$orderInfo['content']:'';
  249. $data['startName'] = "";
  250. $data['endName'] = "";
  251. if($orderInfo['work_type_mode']==1){
  252. $typeInfo = (new \app\common\model\OrderType())
  253. ->getTypeByOrderId($orderInfo['id']);
  254. if($typeInfo){
  255. $order_type = $typeInfo && isset($typeInfo['title']) ? $typeInfo['title'] : '';
  256. $order_type_matter = $typeInfo && isset($typeInfo['child_title']) ? $typeInfo['child_title'] : '';
  257. $data['typeName'] = $order_type.'/'.$order_type_matter;
  258. $data['addressTitle'] = $typeInfo ? $typeInfo['address_title'] : '';
  259. }
  260. }
  261. if($orderInfo['work_type_mode']==3){
  262. $oc = Db::name('order_convey')
  263. ->where('order_id', $orderInfo['id'])
  264. ->find();
  265. if($oc){
  266. $start_name = Db::name('address')->where('id',$oc['start'])
  267. ->value('title');
  268. $end_name = Db::name('address')->where('id',$oc['end'])
  269. ->value('title');
  270. $data['startName'] = $start_name?$start_name:"";
  271. $data['endName'] = $end_name?$end_name:"";
  272. }
  273. }
  274. $data['priority'] = $value['priority'];
  275. $list[] = $data;
  276. }
  277. } elseif($value['type'] == 2) {//巡更巡检
  278. $patrolInfo = Db::name('patrol_task')
  279. ->where('id', $value['bus_id'])
  280. ->find();
  281. if (!empty($patrolInfo)) {
  282. $title = Db::name('patrol_mode')
  283. ->where('id', $patrolInfo['patrol_mode'])
  284. ->value('name');
  285. $data['title'] = $patrolInfo['title']?$title.'-'.$patrolInfo['title']:$title;
  286. $data['realName'] = "";
  287. $data['create_time'] = $patrolInfo['create_time'];
  288. $data['status_txt'] = $patrolStatus[$patrolInfo['status']];
  289. $data['start_time'] = $patrolInfo['start_time'];
  290. $data['end_time'] = $patrolInfo['end_time'];
  291. $data['bus_id'] = $value['bus_id'];
  292. $data['type'] = 2;
  293. $data['work_type_mode'] = 0;
  294. $data['patrol_mode'] = $patrolInfo['patrol_mode'];
  295. $data['status'] = $patrolInfo['status'];
  296. $data['addressTitle'] = "";
  297. $data['typeName'] = "";
  298. $data['content'] = '';
  299. $data['startName'] = "";
  300. $data['endName'] = "";
  301. $data['priority'] = $value['priority'];
  302. $list[] = $data;
  303. }
  304. }elseif ($value['type'] == 3){ // 日常工作
  305. $dailyInfo = Db::name('daily_task')
  306. ->where('id', $value['bus_id'])
  307. ->find();
  308. if (!empty($dailyInfo)) {
  309. $data['title'] = '日常工作';
  310. $data['realName'] = "";
  311. $data['create_time'] = $dailyInfo['create_time'];
  312. $data['status_txt'] = $patrolStatus[$dailyInfo['status']];
  313. $data['start_time'] = $dailyInfo['start_time'];
  314. $data['end_time'] = $dailyInfo['end_time'];
  315. $data['bus_id'] = $value['bus_id'];
  316. $data['type'] = 3;
  317. $data['work_type_mode'] = 0;
  318. $data['patrol_mode'] = 0;
  319. $data['status'] = $dailyInfo['status'];
  320. $data['addressTitle'] = "";
  321. $data['typeName'] = "";
  322. $data['content'] = '';
  323. $data['startName'] = "";
  324. $data['endName'] = "";
  325. $data['priority'] = $value['priority'];
  326. $list[] = $data;
  327. }
  328. }elseif ($value['type'] == 4){ // 设备台账
  329. $deviceInfo = Db::name('device_task')
  330. ->where('id', $value['bus_id'])
  331. ->find();
  332. if (!empty($deviceInfo)) {
  333. $data['title'] = $deviceInfo['title']? '设备维保'.'-'.$deviceInfo['title']:'设备维保';
  334. $data['realName'] = "";
  335. $data['create_time'] = $deviceInfo['create_time'];
  336. $data['status_txt'] = $patrolStatus[$deviceInfo['status']];
  337. $data['start_time'] = $deviceInfo['start_time'];
  338. $data['end_time'] = $deviceInfo['end_time'];
  339. $data['bus_id'] = $value['bus_id'];
  340. $data['type'] = 4;
  341. $data['work_type_mode'] = 0;
  342. $data['patrol_mode'] = 0;
  343. $data['status'] = $deviceInfo['status'];
  344. $data['addressTitle'] = "";
  345. $data['typeName'] = "";
  346. $data['content'] = '';
  347. $data['startName'] = "";
  348. $data['endName'] = "";
  349. $data['priority'] = $value['priority'];
  350. $list[] = $data;
  351. }
  352. }
  353. }
  354. $orgGrabOrder = getOrgGrabOrder($this->userId,$this->orgId);
  355. $r = [
  356. 'list' => $list,
  357. 'count' => count($list),
  358. 'org_grab_order'=>$orgGrabOrder?(int)$orgGrabOrder:0
  359. ];
  360. HelpHander::success($r);
  361. }
  362. //抢单列表
  363. public function queryGrabOrders(){
  364. $page = input('page', 1);
  365. $size = input('size', 10);
  366. $list = $this->model->queryGrabOrders($page,$size,$this->userId,$this->orgId);
  367. HelpHander::success($list);
  368. }
  369. // 抢单
  370. public function grabOrders(){
  371. $orderId = input('orderId');
  372. $orderType = input('orderType/d',0);
  373. $addressId = input('addressId/d',0);
  374. $order = Db::name('orders')
  375. ->where('id',$orderId)
  376. ->where('org_id',$this->orgId)
  377. ->find();
  378. if($order['work_type_mode']==1 && empty($orderType)){
  379. HelpHander::error('报修事项不能为空');
  380. }
  381. if(!$order || $order['del'] == 1){
  382. HelpHander::error('订单不存在');
  383. }
  384. if($order['order_mode'] != 1){
  385. HelpHander::error('订单已被处理');
  386. }
  387. $off = (new Config())->getConfig('org_grab_order'.$order['work_type_mode'],$this->orgId);
  388. if($off !=1){
  389. HelpHander::error('抢单模式未开启');
  390. }
  391. $ret = $this->model->grabOrdersEdit($order,$this->userId,$orderType,$addressId);
  392. if(!$ret){
  393. HelpHander::error($this->model->getError());
  394. }
  395. HelpHander::success([],'操作成功');
  396. }
  397. // 扫标本
  398. public function scanSample(){
  399. $orderId = input('orderId/d',0);
  400. $barcode = input('barcode');
  401. $addrId = input('addrId/d',0);
  402. if(!$barcode ){
  403. HelpHander::error('未传标本码');
  404. }
  405. if(!$orderId&&!$addrId){
  406. HelpHander::error('参数错误');
  407. }
  408. if($orderId > 0){
  409. $orderConvey = Db::name('order_convey')
  410. ->where('order_id',$orderId)
  411. ->find();
  412. $addrId = $orderConvey['start'];
  413. }
  414. $res = Db::name('order_convey_lis')
  415. ->where('org_id',$this->orgId)
  416. ->where('order_id',$orderId)
  417. ->where('barcode',$barcode)
  418. ->where('user_id',$this->userId)
  419. ->where('addr_id',$addrId)
  420. ->find();
  421. Db::startTrans();
  422. try{
  423. if($res){
  424. $res = Db::name('order_convey_lis')
  425. ->where('id',$res['id'])->update([
  426. 'create_time' => date('Y-m-d H:i:s')
  427. ]);
  428. }else{
  429. $res = Db::name('order_convey_lis')
  430. ->insert([
  431. 'order_id' => $orderId,
  432. 'barcode' => $barcode,
  433. 'user_id' => $this->userId,
  434. 'create_time' => date('Y-m-d H:i:s'),
  435. 'org_id' => $this->orgId,
  436. 'addr_id' => $addrId
  437. ]);
  438. }
  439. if(!$res){
  440. exception('操作失败');
  441. }
  442. Db::commit();
  443. HelpHander::success([],'操作成功');
  444. }catch (Exception $e){
  445. Db::rollback();
  446. HelpHander::error($e->getMessage());
  447. }
  448. }
  449. //用户订单列表
  450. public function queryUserOrdersByMode(){
  451. $page = input('page', 1);
  452. $size = input('size', 10);
  453. $mode = input('mode', 0);
  454. $type = input('type', 0);
  455. $ret=$this->model->userOrdersByMode($page,$size,$this->userId,$mode,$type,$this->orgId);
  456. HelpHander::success($ret);
  457. }
  458. //用户取消订单
  459. public function updateOrderModeByUser(){
  460. $orderId = input('orderId', 0);
  461. $reason = input('reason', '','trim');
  462. $ret=$this->model->cancel($orderId,$this->userId,1,$reason);
  463. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  464. }
  465. //调度取消订单
  466. public function updateOrderModeByDispatch(){
  467. $orderId = input('orderId', 0);
  468. $reason = input('reason', '');
  469. if(!$reason){
  470. HelpHander::error('请填写取消原因');
  471. }
  472. $ret=$this->model->cancel($orderId,$this->userId,2,$reason);
  473. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  474. }
  475. //调度完成订单
  476. public function finishOrder(){
  477. $orderId = input('orderId', 0);
  478. $ret=$this->model->finish($orderId);
  479. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  480. }
  481. //所有订单
  482. public function queryAllOrder(){
  483. $page = input('page', 1);
  484. $size = input('size', 10);
  485. $workTypeMode = input('workTypeMode/d',-1);
  486. $currOrderMode = input('currOrderMode');
  487. $beginTime = input('beginTime');
  488. $endTime = input('endTime');
  489. $list = $this->model->queryAllOrder($this->orgId,$page,$size,$workTypeMode,$currOrderMode,$beginTime,$endTime);
  490. HelpHander::success($list);
  491. }
  492. // 工人添加下一站地址
  493. public function addConveyEnd(){
  494. $orderId = input('orderId/d',0);
  495. $addrId = input('addrId/d',0);
  496. $ret = $this->model->addConveyEnd($this->orgId,$orderId,$addrId);
  497. if(!$ret){
  498. HelpHander::error($this->model->getError());
  499. }
  500. HelpHander::success([],'成功');
  501. }
  502. // 支付运送病人
  503. public function pay(){
  504. $id = input('id/d',0);
  505. $remark = input('remark','','trim');
  506. $info = Db::name('order_convey_pay')->where('id',$id)->find();
  507. if(!$info){
  508. HelpHander::error('订单不存在');
  509. }
  510. if($info['status'] == 1){
  511. HelpHander::error('订单已支付');
  512. }
  513. $res = Db::name('order_convey_pay')->where('id',$id)->update([
  514. 'type' => 1,
  515. 'status' => 1,
  516. 'remark' => $remark,
  517. 'pay_time' => date('Y-m-d H:i:s')
  518. ]);
  519. if($res){
  520. HelpHander::success([],'操作成功');
  521. }else{
  522. HelpHander::error('操作失败');
  523. }
  524. }
  525. // 扫途径地点
  526. public function sweepCode(){
  527. $code = input('code');
  528. $id = input('id/d',0);
  529. $ret = model('Orders')->sweepCode($code,$id);
  530. if(!$ret){
  531. HelpHander::error(model('Orders')->getError());
  532. }
  533. HelpHander::success([],'操作成功');
  534. }
  535. //获取可转单类型
  536. public function orderTransferType(){
  537. $user = Db::name('user')->where('id',$this->userId)->find();
  538. $config = model('Config')->getConfig('web_order_transfer_type');
  539. $modes = $config?explode('|',$config):[];
  540. if($user['type'] != 1){ // 不是总公司人员
  541. $roles = Db::name('user_roles')
  542. ->alias('a')
  543. ->join('roles b','b.id = a.roles_id')
  544. ->where('a.user_id',$this->userId)
  545. ->value('work_type_mode');
  546. if($roles){
  547. $modes = explode(',',$roles);
  548. }
  549. }
  550. $map[] = ['type','=',1];
  551. if($modes){
  552. $map[] = ['id','in',$modes];
  553. }else{
  554. $map[] = ['id','=',-1];
  555. }
  556. $workType = Db::name('work_type_mode')
  557. ->where($map)
  558. ->field('id,name as title')
  559. ->select();
  560. HelpHander::success($workType?$workType:[]);
  561. }
  562. //获取待处理已完成已评价订单数量
  563. public function getOrdersCount(){
  564. $map[] = ['user_id','=',$this->userId];
  565. $map[] = ['org_id','=',$this->orgId];
  566. $map[] = ['del','=',0];
  567. $a1 = Db::name('orders')
  568. ->where($map)
  569. ->where('order_mode',1)
  570. ->count();
  571. $dcl = $a1?$a1:0;
  572. $a2 = Db::name('orders')
  573. ->where($map)
  574. ->where('order_mode',5)
  575. ->count();
  576. $ywc = $a2?$a2:0;
  577. $a3 = Db::name('orders')
  578. ->where($map)
  579. ->where('order_mode',6)
  580. ->count();
  581. $ypj = $a3?$a3:0;
  582. $data = [
  583. 'dcl'=>$dcl,
  584. 'ywc'=>$ywc,
  585. 'ypj'=>$ypj,
  586. ];
  587. HelpHander::success($data);
  588. }
  589. //被驳回的数量
  590. public function rejectCount(){
  591. $map[] = ['org_id', '=', $this->orgId];
  592. $map[] = ['del', '=', 0];
  593. $map2[] = ['todo_mode', '=', 4];
  594. $auth = get_dispatch_auth($this->userId);
  595. if (empty($auth)) {
  596. $map[] = ['work_type_mode', '=', -1];
  597. }
  598. else {
  599. $map[] = ['work_type_mode', 'in', $auth];
  600. }
  601. $org_two_dispatch = (new Config())->getConfig('org_two_dispatch',$this->orgId);
  602. if($org_two_dispatch==0){//二级调度开关关闭
  603. }else{
  604. if (check_two_dispatch($this->userId) == 1) {//二级调度角色
  605. $roles_id = Db::name('user_roles')
  606. ->where('user_id',$this->userId)
  607. ->value('roles_id');
  608. $ids = Db::name('dispatch_log')
  609. ->where('roles_id', $roles_id)
  610. ->whereOr('to_user_id', $this->userId)
  611. ->column('order_id');
  612. if (empty($ids)) {
  613. $map2[] = ['order_id', '=', -1];
  614. }else {
  615. $map2[] = ['order_id', 'in', $ids];
  616. }
  617. }
  618. }
  619. $count = Db::name('todo_view')
  620. ->where($map)
  621. ->where($map2)
  622. ->count();
  623. HelpHander::success($count);
  624. }
  625. //优先级
  626. public function repair_priority(){
  627. $a = [
  628. ['id'=>1,'title'=>"可延缓的"],
  629. ['id'=>2,'title'=>"普通"],
  630. ['id'=>3,'title'=>"紧急"],
  631. ];
  632. HelpHander::success($a);
  633. }
  634. public function userQualityLists() {
  635. $page = input('page', 1);
  636. $size = input('size', 10);
  637. $list = $this->model->userQualityLists($page, $size, $this->userId, $this->orgId);
  638. HelpHander::success($list);
  639. }
  640. public function informerQualityLists() {
  641. $page = input('page', 1);
  642. $size = input('size', 10);
  643. $list = $this->model->informerQualityLists($page, $size, $this->userId, $this->orgId);
  644. HelpHander::success($list);
  645. }
  646. //巡更巡视..一键呼叫发送给自己转成报修单;
  647. public function addBxOrders(){
  648. $data = [
  649. 'user_id'=>$this->userId,
  650. 'org_id'=>$this->orgId,
  651. 'dep_id'=>input('depId/d',0),
  652. 'images'=>input('images',''),
  653. 'videos'=>input('videos',''),
  654. 'voices'=>input('voices',''),
  655. 'content'=>input('content',''),
  656. 'work_type_mode'=>input('workTypeMode/d',1),
  657. 'source_type'=>input('sourceType/d',4),
  658. 'type_id'=>input('typeId',0),
  659. 'address_id'=>input('addressId',0),
  660. 'repair_priority'=>input('repairPriority',0),
  661. ];
  662. $res = model('Orders')->addBxOrders($data);
  663. if (!$res) {
  664. HelpHander::error(model('Orders')->getError());
  665. }
  666. HelpHander::success([],'操作成功');
  667. }
  668. public function withdraw(){
  669. $id = input('id');
  670. $info = Db::name('orders')
  671. ->where('id',$id)
  672. ->where('del',0)
  673. ->where('order_mode',4)
  674. ->find();
  675. if(!$info){
  676. HelpHander::error('参数错误');
  677. }
  678. $saveOrder = Db::name('orders')
  679. ->where('id',$id)
  680. ->update(['order_mode'=>1,'withdraw_time'=>getTime()]);
  681. Db::name('todo')->where('order_id',$id)->update(['del'=>1]);
  682. $todoIds = Db::name('todo')
  683. ->where('order_id',$id)
  684. ->where('todo_mode',1)
  685. ->column('id');
  686. Db::name('task')
  687. ->where('type',1)
  688. ->whereIn('bus_id',$todoIds)
  689. ->delete();
  690. if(!$saveOrder){
  691. HelpHander::error('操作失败');
  692. }
  693. HelpHander::success('操作成功');
  694. }
  695. }