Orders.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. ->find();
  211. if (!empty($todoInfo)) {
  212. $data['title'] = $workType[$todoInfo['work_type_mode']];
  213. $data['realName'] = Db::name('user')
  214. ->where('id', $todoInfo['create_user_id'])
  215. ->value('real_name');
  216. $data['create_time'] = $todoInfo['create_time'];
  217. $data['status_txt'] = Db::name('todo_mode')
  218. ->where('id', $todoInfo['todo_mode'])
  219. ->value('out_content');
  220. $data['start_time'] = "";
  221. $data['end_time'] = "";
  222. $data['type'] = 1;
  223. $data['bus_id'] = $value['bus_id'];
  224. $orderInfo = Db::name('orders')
  225. ->where('id',$todoInfo['order_id'])
  226. ->find();
  227. if($orderInfo['from'] > 0){
  228. $from = '';
  229. if($orderInfo['from'] == 1){
  230. $from = '一键呼叫';
  231. }else if($orderInfo['from'] == 2){
  232. $from = '隐患预警';
  233. }else if($orderInfo['from'] == 3){
  234. $from = '投诉';
  235. }
  236. $data['title'] = $data['title'].'('.$from.')';
  237. }
  238. $data['patrol_mode'] = 0;
  239. $data['status'] = $todoInfo['todo_mode'];
  240. $data['work_type_mode'] = $orderInfo['work_type_mode'];
  241. if($data['work_type_mode'] == 1 && $todoInfo['todo_mode'] == 2 && $todoInfo['pause'] == 1){ //维修,检查是否挂起
  242. $data['status_txt'] = '已挂起';
  243. }
  244. $data['addressTitle'] = "";
  245. $data['typeName'] = "";
  246. $data['content'] = $orderInfo['content']?$orderInfo['content']:'';
  247. $data['startName'] = "";
  248. $data['endName'] = "";
  249. if($orderInfo['work_type_mode']==1){
  250. $typeInfo = (new \app\common\model\OrderType())
  251. ->getTypeByOrderId($orderInfo['id']);
  252. if($typeInfo){
  253. $order_type = $typeInfo && isset($typeInfo['title']) ? $typeInfo['title'] : '';
  254. $order_type_matter = $typeInfo && isset($typeInfo['child_title']) ? $typeInfo['child_title'] : '';
  255. $data['typeName'] = $order_type.'/'.$order_type_matter;
  256. $data['addressTitle'] = $typeInfo ? $typeInfo['address_title'] : '';
  257. }
  258. }
  259. if($orderInfo['work_type_mode']==3){
  260. $oc = Db::name('order_convey')
  261. ->where('order_id', $orderInfo['id'])
  262. ->find();
  263. if($oc){
  264. $start_name = Db::name('address')->where('id',$oc['start'])
  265. ->value('title');
  266. $end_name = Db::name('address')->where('id',$oc['end'])
  267. ->value('title');
  268. $data['startName'] = $start_name?$start_name:"";
  269. $data['endName'] = $end_name?$end_name:"";
  270. }
  271. }
  272. $data['priority'] = $value['priority'];
  273. $list[] = $data;
  274. }
  275. } elseif($value['type'] == 2) {//巡更巡检
  276. $patrolInfo = Db::name('patrol_task')
  277. ->where('id', $value['bus_id'])
  278. ->find();
  279. if (!empty($patrolInfo)) {
  280. $title = Db::name('patrol_mode')
  281. ->where('id', $patrolInfo['patrol_mode'])
  282. ->value('name');
  283. $data['title'] = $patrolInfo['title']?$title.'-'.$patrolInfo['title']:$title;
  284. $data['realName'] = "";
  285. $data['create_time'] = $patrolInfo['create_time'];
  286. $data['status_txt'] = $patrolStatus[$patrolInfo['status']];
  287. $data['start_time'] = $patrolInfo['start_time'];
  288. $data['end_time'] = $patrolInfo['end_time'];
  289. $data['bus_id'] = $value['bus_id'];
  290. $data['type'] = 2;
  291. $data['work_type_mode'] = 0;
  292. $data['patrol_mode'] = $patrolInfo['patrol_mode'];
  293. $data['status'] = $patrolInfo['status'];
  294. $data['addressTitle'] = "";
  295. $data['typeName'] = "";
  296. $data['content'] = '';
  297. $data['startName'] = "";
  298. $data['endName'] = "";
  299. $data['priority'] = $value['priority'];
  300. $list[] = $data;
  301. }
  302. }elseif ($value['type'] == 3){ // 日常工作
  303. $dailyInfo = Db::name('daily_task')
  304. ->where('id', $value['bus_id'])
  305. ->find();
  306. if (!empty($dailyInfo)) {
  307. $data['title'] = '日常工作';
  308. $data['realName'] = "";
  309. $data['create_time'] = $dailyInfo['create_time'];
  310. $data['status_txt'] = $patrolStatus[$dailyInfo['status']];
  311. $data['start_time'] = $dailyInfo['start_time'];
  312. $data['end_time'] = $dailyInfo['end_time'];
  313. $data['bus_id'] = $value['bus_id'];
  314. $data['type'] = 3;
  315. $data['work_type_mode'] = 0;
  316. $data['patrol_mode'] = 0;
  317. $data['status'] = $dailyInfo['status'];
  318. $data['addressTitle'] = "";
  319. $data['typeName'] = "";
  320. $data['content'] = '';
  321. $data['startName'] = "";
  322. $data['endName'] = "";
  323. $data['priority'] = $value['priority'];
  324. $list[] = $data;
  325. }
  326. }elseif ($value['type'] == 4){ // 设备台账
  327. $deviceInfo = Db::name('device_task')
  328. ->where('id', $value['bus_id'])
  329. ->find();
  330. if (!empty($deviceInfo)) {
  331. $data['title'] = $deviceInfo['title']? '设备维保'.'-'.$deviceInfo['title']:'设备维保';
  332. $data['realName'] = "";
  333. $data['create_time'] = $deviceInfo['create_time'];
  334. $data['status_txt'] = $patrolStatus[$deviceInfo['status']];
  335. $data['start_time'] = $deviceInfo['start_time'];
  336. $data['end_time'] = $deviceInfo['end_time'];
  337. $data['bus_id'] = $value['bus_id'];
  338. $data['type'] = 4;
  339. $data['work_type_mode'] = 0;
  340. $data['patrol_mode'] = 0;
  341. $data['status'] = $deviceInfo['status'];
  342. $data['addressTitle'] = "";
  343. $data['typeName'] = "";
  344. $data['content'] = '';
  345. $data['startName'] = "";
  346. $data['endName'] = "";
  347. $data['priority'] = $value['priority'];
  348. $list[] = $data;
  349. }
  350. }
  351. }
  352. $orgGrabOrder = (new Config())->getConfig('org_grab_order',$this->orgId);
  353. $r = [
  354. 'list' => $list,
  355. 'count' => count($list),
  356. 'org_grab_order'=>$orgGrabOrder?(int)$orgGrabOrder:0
  357. ];
  358. HelpHander::success($r);
  359. }
  360. //抢单列表
  361. public function queryGrabOrders(){
  362. $page = input('page', 1);
  363. $size = input('size', 10);
  364. $list = $this->model->queryGrabOrders($page,$size,$this->userId,$this->orgId);
  365. HelpHander::success($list);
  366. }
  367. // 抢单
  368. public function grabOrders(){
  369. $orderId = input('orderId');
  370. $order = Db::name('orders')
  371. ->where('id',$orderId)
  372. ->where('org_id',$this->orgId)
  373. ->find();
  374. if(!$order || $order['del'] == 1){
  375. HelpHander::error('订单不存在');
  376. }
  377. if($order['order_mode'] != 1){
  378. HelpHander::error('订单已被处理');
  379. }
  380. $off = (new Config())->getConfig('org_grab_order',$this->orgId);
  381. if($off !=1){
  382. HelpHander::error('抢单模式未开启');
  383. }
  384. $ret = $this->model->grabOrdersEdit($order,$this->userId);
  385. if(!$ret){
  386. HelpHander::error($this->model->getError());
  387. }
  388. HelpHander::success([],'操作成功');
  389. }
  390. // 扫标本
  391. public function scanSample(){
  392. $orderId = input('orderId/d',0);
  393. $barcode = input('barcode');
  394. $addrId = input('addrId/d',0);
  395. if(!$barcode ){
  396. HelpHander::error('未传标本码');
  397. }
  398. if(!$orderId&&!$addrId){
  399. HelpHander::error('参数错误');
  400. }
  401. if($orderId > 0){
  402. $orderConvey = Db::name('order_convey')
  403. ->where('order_id',$orderId)
  404. ->find();
  405. $addrId = $orderConvey['start'];
  406. }
  407. $res = Db::name('order_convey_lis')
  408. ->where('org_id',$this->orgId)
  409. ->where('order_id',$orderId)
  410. ->where('barcode',$barcode)
  411. ->where('user_id',$this->userId)
  412. ->where('addr_id',$addrId)
  413. ->find();
  414. Db::startTrans();
  415. try{
  416. if($res){
  417. $res = Db::name('order_convey_lis')
  418. ->where('id',$res['id'])->update([
  419. 'create_time' => date('Y-m-d H:i:s')
  420. ]);
  421. }else{
  422. $res = Db::name('order_convey_lis')
  423. ->insert([
  424. 'order_id' => $orderId,
  425. 'barcode' => $barcode,
  426. 'user_id' => $this->userId,
  427. 'create_time' => date('Y-m-d H:i:s'),
  428. 'org_id' => $this->orgId,
  429. 'addr_id' => $addrId
  430. ]);
  431. }
  432. if(!$res){
  433. exception('操作失败');
  434. }
  435. Db::commit();
  436. HelpHander::success([],'操作成功');
  437. }catch (Exception $e){
  438. Db::rollback();
  439. HelpHander::error($e->getMessage());
  440. }
  441. }
  442. //用户订单列表
  443. public function queryUserOrdersByMode(){
  444. $page = input('page', 1);
  445. $size = input('size', 10);
  446. $mode = input('mode', 0);
  447. $type = input('type', 0);
  448. $ret=$this->model->userOrdersByMode($page,$size,$this->userId,$mode,$type,$this->orgId);
  449. HelpHander::success($ret);
  450. }
  451. //用户取消订单
  452. public function updateOrderModeByUser(){
  453. $orderId = input('orderId', 0);
  454. $reason = input('reason', '','trim');
  455. $ret=$this->model->cancel($orderId,$this->userId,1,$reason);
  456. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  457. }
  458. //调度取消订单
  459. public function updateOrderModeByDispatch(){
  460. $orderId = input('orderId', 0);
  461. $reason = input('reason', '');
  462. if(!$reason){
  463. HelpHander::error('请填写取消原因');
  464. }
  465. $ret=$this->model->cancel($orderId,$this->userId,2,$reason);
  466. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  467. }
  468. //调度完成订单
  469. public function finishOrder(){
  470. $orderId = input('orderId', 0);
  471. $ret=$this->model->finish($orderId);
  472. $ret?HelpHander::success([],'操作成功'):HelpHander::error($this->model->getError());
  473. }
  474. //所有订单
  475. public function queryAllOrder(){
  476. $page = input('page', 1);
  477. $size = input('size', 10);
  478. $workTypeMode = input('workTypeMode/d',-1);
  479. $currOrderMode = input('currOrderMode');
  480. $beginTime = input('beginTime');
  481. $endTime = input('endTime');
  482. $list = $this->model->queryAllOrder($this->orgId,$page,$size,$workTypeMode,$currOrderMode,$beginTime,$endTime);
  483. HelpHander::success($list);
  484. }
  485. // 工人添加下一站地址
  486. public function addConveyEnd(){
  487. $orderId = input('orderId/d',0);
  488. $addrId = input('addrId/d',0);
  489. $ret = $this->model->addConveyEnd($this->orgId,$orderId,$addrId);
  490. if(!$ret){
  491. HelpHander::error($this->model->getError());
  492. }
  493. HelpHander::success([],'成功');
  494. }
  495. // 支付运送病人
  496. public function pay(){
  497. $id = input('id/d',0);
  498. $remark = input('remark','','trim');
  499. $info = Db::name('order_convey_pay')->where('id',$id)->find();
  500. if(!$info){
  501. HelpHander::error('订单不存在');
  502. }
  503. if($info['status'] == 1){
  504. HelpHander::error('订单已支付');
  505. }
  506. $res = Db::name('order_convey_pay')->where('id',$id)->update([
  507. 'type' => 1,
  508. 'status' => 1,
  509. 'remark' => $remark,
  510. 'pay_time' => date('Y-m-d H:i:s')
  511. ]);
  512. if($res){
  513. HelpHander::success([],'操作成功');
  514. }else{
  515. HelpHander::error('操作失败');
  516. }
  517. }
  518. // 扫途径地点
  519. public function sweepCode(){
  520. $code = input('code');
  521. $id = input('id/d',0);
  522. $ret = model('Orders')->sweepCode($code,$id);
  523. if(!$ret){
  524. HelpHander::error(model('Orders')->getError());
  525. }
  526. HelpHander::success([],'操作成功');
  527. }
  528. //获取可转单类型
  529. public function orderTransferType(){
  530. $user = Db::name('user')->where('id',$this->userId)->find();
  531. $config = model('Config')->getConfig('web_order_transfer_type');
  532. $modes = $config?explode('|',$config):[];
  533. if($user['type'] != 1){ // 不是总公司人员
  534. $roles = Db::name('user_roles')
  535. ->alias('a')
  536. ->join('roles b','b.id = a.roles_id')
  537. ->where('a.user_id',$this->userId)
  538. ->value('work_type_mode');
  539. if($roles){
  540. $modes = explode(',',$roles);
  541. }
  542. }
  543. $map[] = ['type','=',1];
  544. if($modes){
  545. $map[] = ['id','in',$modes];
  546. }else{
  547. $map[] = ['id','=',-1];
  548. }
  549. $workType = Db::name('work_type_mode')
  550. ->where($map)
  551. ->field('id,name as title')
  552. ->select();
  553. HelpHander::success($workType?$workType:[]);
  554. }
  555. //获取待处理已完成已评价订单数量
  556. public function getOrdersCount(){
  557. $map[] = ['user_id','=',$this->userId];
  558. $map[] = ['org_id','=',$this->orgId];
  559. $map[] = ['del','=',0];
  560. $a1 = Db::name('orders')
  561. ->where($map)
  562. ->where('order_mode',1)
  563. ->count();
  564. $dcl = $a1?$a1:0;
  565. $a2 = Db::name('orders')
  566. ->where($map)
  567. ->where('order_mode',5)
  568. ->count();
  569. $ywc = $a2?$a2:0;
  570. $a3 = Db::name('orders')
  571. ->where($map)
  572. ->where('order_mode',6)
  573. ->count();
  574. $ypj = $a3?$a3:0;
  575. $data = [
  576. 'dcl'=>$dcl,
  577. 'ywc'=>$ywc,
  578. 'ypj'=>$ypj,
  579. ];
  580. HelpHander::success($data);
  581. }
  582. //被驳回的数量
  583. public function rejectCount(){
  584. $map[] = ['org_id', '=', $this->orgId];
  585. $map[] = ['del', '=', 0];
  586. $map2[] = ['todo_mode', '=', 4];
  587. $auth = get_dispatch_auth($this->userId);
  588. if (empty($auth)) {
  589. $map[] = ['work_type_mode', '=', -1];
  590. }
  591. else {
  592. $map[] = ['work_type_mode', 'in', $auth];
  593. }
  594. $org_two_dispatch = (new Config())->getConfig('org_two_dispatch',$this->orgId);
  595. if($org_two_dispatch==0){//二级调度开关关闭
  596. }else{
  597. if (check_two_dispatch($this->userId) == 1) {//二级调度角色
  598. $roles_id = Db::name('user_roles')
  599. ->where('user_id',$this->userId)
  600. ->value('roles_id');
  601. $ids = Db::name('dispatch_log')
  602. ->where('roles_id', $roles_id)
  603. ->whereOr('to_user_id', $this->userId)
  604. ->column('order_id');
  605. if (empty($ids)) {
  606. $map2[] = ['order_id', '=', -1];
  607. }else {
  608. $map2[] = ['order_id', 'in', $ids];
  609. }
  610. }
  611. }
  612. $count = Db::name('todo_view')
  613. ->where($map)
  614. ->where($map2)
  615. ->count();
  616. HelpHander::success($count);
  617. }
  618. //优先级
  619. public function repair_priority(){
  620. $a = [
  621. ['id'=>1,'title'=>"可延缓的"],
  622. ['id'=>2,'title'=>"普通"],
  623. ['id'=>3,'title'=>"紧急"],
  624. ];
  625. HelpHander::success($a);
  626. }
  627. public function userQualityLists() {
  628. $page = input('page', 1);
  629. $size = input('size', 10);
  630. $list = $this->model->userQualityLists($page, $size, $this->userId, $this->orgId);
  631. HelpHander::success($list);
  632. }
  633. public function informerQualityLists() {
  634. $page = input('page', 1);
  635. $size = input('size', 10);
  636. $list = $this->model->informerQualityLists($page, $size, $this->userId, $this->orgId);
  637. HelpHander::success($list);
  638. }
  639. //巡更巡视..一键呼叫发送给自己转成报修单;
  640. public function addBxOrders(){
  641. $data = [
  642. 'user_id'=>$this->userId,
  643. 'org_id'=>$this->orgId,
  644. 'dep_id'=>input('depId/d',0),
  645. 'images'=>input('images',''),
  646. 'videos'=>input('videos',''),
  647. 'voices'=>input('voices',''),
  648. 'content'=>input('content',''),
  649. 'work_type_mode'=>input('workTypeMode/d',1),
  650. 'source_type'=>input('sourceType/d',4),
  651. 'type_id'=>input('typeId',0),
  652. 'address_id'=>input('addressId',0),
  653. 'repair_priority'=>input('repairPriority',0),
  654. ];
  655. $res = model('Orders')->addBxOrders($data);
  656. if (!$res) {
  657. HelpHander::error(model('Orders')->getError());
  658. }
  659. HelpHander::success([],'操作成功');
  660. }
  661. }