Workorder.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Class 工单管理类
  5. */
  6. class Workorder extends MY_Controller
  7. {
  8. function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->model("warning_model");
  12. $this->load->model("workorder_model");
  13. $this->load->model("user_model");
  14. $this->load->library('MY_pagination');
  15. $this->load->library('notices');
  16. $this->load->helper(array('url', 'form', 'date'));
  17. $this->assign("warning_type", $this->warning_type);
  18. $this->assign("warning_level", $this->warning_level);
  19. $this->assign("warning_status", $this->warning_status);
  20. $this->assign("send_type", $this->send_type);
  21. $this->assign("workorder_status", $this->workorder_status);
  22. $now = new DateTime();
  23. $now = $now->modify("-".$this->setting['save_time']."day");
  24. $now = new \MongoDB\BSON\UTCDateTime($now->getTimestamp()*1000);
  25. $this->workorder_model->filter_finished_workorder($now);
  26. }
  27. /**
  28. * 各个状态工单数量
  29. */
  30. private function counts()
  31. {
  32. $count10 = $this->workorder_model->count_workorder(null, $wheres = array('status' => "10"));
  33. $count20 = $this->workorder_model->count_workorder(null, $wheres = array('status' => "20"));
  34. $count30 = $this->workorder_model->count_workorder(null, $wheres = array('status' => "30"));
  35. $count40 = $this->workorder_model->count_workorder(null, $wheres = array('status' => "40"));
  36. $count50 = $this->workorder_model->count_workorder(null, $wheres = array('status' => "50"));
  37. $this->assign("count10", $count10);
  38. $this->assign("count20", $count20);
  39. $this->assign("count30", $count30);
  40. $this->assign("count40", $count40);
  41. $this->assign("count50", $count50);
  42. }
  43. /**
  44. * 工单列表页
  45. */
  46. public function index()
  47. {
  48. $url = site_url("workorder/index?");
  49. $wheres = array();
  50. $order_info = array();
  51. $keyword = $this->input->get("keyword", TRUE);
  52. $type = $this->input->get("type", TRUE);
  53. $branch_id = $this->input->get("branch_id",TRUE);
  54. $status = $this->input->get("status", TRUE);
  55. $order = $this->input->get("order", TRUE);
  56. $page_num = $this->input->get("per_page", TRUE);
  57. $page_size = $this->input->get("page_size", TRUE);
  58. if ($keyword) {
  59. $url .= "&keyword=" . $keyword;
  60. }
  61. if ($status) {
  62. $wheres = array('$and' => array(array('status' => array('$ne' => "50")), array('status' => $status)));
  63. $url .= "&status=" . $status;
  64. } else {
  65. $wheres = array('$and' => array(array('status' => array('$ne' => "50")), array('status' => array('$ne' => "60"))));
  66. }
  67. if ($type && array_key_exists($type,$this->warning_type)) {
  68. $wheres['type'] = $this->warning_type[$type];
  69. $url .= "&type=" . $type;
  70. }
  71. if($branch_id){
  72. $wheres['branch.branch_id'] = $branch_id;
  73. $url .= "&branch_id=".$branch_id;
  74. }
  75. if ($order) {
  76. $orders = explode(" ", $order);
  77. if (count($orders) == 2) {
  78. $order_info[$orders[0]] = $orders[1];
  79. $url .= "&order=" . $order;
  80. }
  81. }
  82. if ($page_size) {
  83. $this->page_size = $page_size;
  84. $url .= "&page_size=" . $page_size;
  85. }
  86. if ($this->session->user_type != "1") {
  87. $wheres['receive_user_id'] = $this->session->user_id;
  88. }
  89. $count = $this->workorder_model->count_workorder($keyword, $wheres);
  90. $this->assign("count", $count);
  91. $config = $this->page_config($count, $this->page_size, $url);
  92. $this->my_pagination->initialize($config);
  93. if ($page_num && $page_num > 1) {
  94. $offset = (intval($page_num) - 1) * $this->page_size;
  95. } else {
  96. $offset = 0;
  97. }
  98. $workorder_list = $this->workorder_model->list_workorder($this->page_size, $offset, $keyword, $wheres, $order_info);
  99. $workorders = array();
  100. foreach ($workorder_list as $key => $workorder) {
  101. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  102. $remarks = array();
  103. foreach ($workorder['remark_list'] as $key => $remark) {
  104. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  105. $remarks[] = $remark;
  106. }
  107. $workorder['remark_list'] = $remarks;
  108. $workorder['last_remark_user'] = $remarks[count($remarks) - 1]['remark_user'];
  109. $workorder['last_remark_content'] = $remarks[count($remarks) - 1]['remark_content'];
  110. $workorder['last_remark_time'] = $remarks[count($remarks) - 1]['remark_time'];
  111. $workorders[] = $workorder;
  112. }
  113. $this->counts();
  114. $this->assign("keyword", $keyword);
  115. $this->assign("type", $type);
  116. $this->assign("branch_id",$branch_id);
  117. $this->assign("status", $status);
  118. $this->assign("order", $order);
  119. $this->assign("page_size", $this->page_size);
  120. $this->assign("page", $this->my_pagination->create_pages());
  121. $this->assign("workorder_list", $workorders);
  122. $this->display("workorder/index.html");
  123. }
  124. /**
  125. * 已完成工单列表页
  126. */
  127. public function finished()
  128. {
  129. $url = site_url("workorder/finished?");
  130. $wheres = NULL;
  131. $order_info = array();
  132. $keyword = $this->input->get("keyword", TRUE);
  133. $type = $this->input->get("type", TRUE);
  134. $branch_id = $this->input->get("branch_id",TRUE);
  135. $order = $this->input->get("order", TRUE);
  136. $page_num = $this->input->get("per_page", TRUE);
  137. $page_size = $this->input->get("page_size", TRUE);
  138. if ($keyword) {
  139. $url .= "&keyword=" . $keyword;
  140. }
  141. $wheres = array('$and' => array(array('status' => array('$ne' => "60")), array('status' => "50")));
  142. if ($type) {
  143. $wheres['type'] = $type;
  144. $url .= "&type=" . $type;
  145. }
  146. if($branch_id){
  147. $wheres['branch.branch_id'] = $branch_id;
  148. $url .= "&branch_id=".$branch_id;
  149. }
  150. if ($order) {
  151. $orders = explode(" ", $order);
  152. if (count($orders) == 2) {
  153. $order_info[$orders[0]] = $orders[1];
  154. $url .= "&order=" . $order;
  155. }
  156. }
  157. if ($page_size) {
  158. $this->page_size = $page_size;
  159. $url .= "&page_size=" . $page_size;
  160. }
  161. if ($this->session->user_type != "1") {
  162. $wheres['receive_user_id'] = $this->session->user_id;
  163. }
  164. $count = $this->workorder_model->count_workorder($keyword, $wheres);
  165. $this->assign("count", $count);
  166. $config = $this->page_config($count, $this->page_size, $url);
  167. $this->my_pagination->initialize($config);
  168. if ($page_num && $page_num > 1) {
  169. $offset = (intval($page_num) - 1) * $this->page_size;
  170. } else {
  171. $offset = 0;
  172. }
  173. $workorder_list = $this->workorder_model->list_workorder($this->page_size, $offset, $keyword, $wheres, $order_info);
  174. $workorders = array();
  175. foreach ($workorder_list as $key => $workorder) {
  176. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  177. $remarks = array();
  178. foreach ($workorder['remark_list'] as $key => $remark) {
  179. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  180. $remarks[] = $remark;
  181. }
  182. $workorder['remark_list'] = $remarks;
  183. $workorder['last_remark_user'] = $remarks[count($remarks) - 1]['remark_user'];
  184. $workorder['last_remark_content'] = $remarks[count($remarks) - 1]['remark_content'];
  185. $workorder['last_remark_time'] = $remarks[count($remarks) - 1]['remark_time'];
  186. $workorders[] = $workorder;
  187. }
  188. $this->assign("keyword", $keyword);
  189. $this->assign("type", $type);
  190. $this->assign("branch_id",$branch_id);
  191. $this->assign("order", $order);
  192. $this->assign("page_size", $this->page_size);
  193. $this->assign("page", $this->my_pagination->create_pages());
  194. $this->assign("workorder_list", $workorders);
  195. $this->display("workorder/finished.html");
  196. }
  197. /**
  198. * 创建工单
  199. */
  200. public function create()
  201. {
  202. $warning_ids = $this->input->get("ids");
  203. $ids = explode(",", $warning_ids);
  204. $warning_list = array();
  205. $workorder_name = "";
  206. $warning_level = "50";
  207. $branch_id = null;
  208. foreach ($ids as $key => $val) {
  209. $warning = $this->warning_model->get_warning_with_id($val);
  210. if ($warning) {
  211. if (intval($warning['level']) <= intval($warning_level)) {
  212. $warning_level = $warning['level'];
  213. $workorder_name = $warning['warning_name'];
  214. }
  215. $warning_list[] = $warning;
  216. $branch_id = $warning['branch']['branch_id'];
  217. }
  218. }
  219. $user_list = $this->user_model->select_users("2",$branch_id);
  220. $sso_user_list = $this->user_model->set_collection_name("sso_users")->select_users("2",$branch_id);
  221. $this->assign("user_list", $user_list);
  222. $this->assign("sso_user_list", $sso_user_list);
  223. $this->assign("workorder_name", $workorder_name);
  224. $this->assign("id", $this->create_id());
  225. $this->assign("warning_ids", $warning_ids);
  226. $this->assign("warning_list", $warning_list);
  227. $this->display("workorder/create.html");
  228. }
  229. /**
  230. * 保存工单
  231. */
  232. public function save()
  233. {
  234. $is_validate = false;
  235. $data = array();
  236. $data['workorder_id'] = $this->input->post("workorder_id", true);
  237. $data['workorder_name'] = $this->input->post("workorder_name", true);
  238. $warning_names = $this->input->post("warning_name", true);
  239. $contents = $this->input->post("content", true);
  240. $warning_ids = rtrim($this->input->post("warning_ids", true), ",");
  241. $ids = explode(",", $warning_ids);
  242. $warning_type = array();
  243. $branch = null;
  244. foreach ($ids as $key => $val) {
  245. $warning = $this->warning_model->get_warning_with_id($val);
  246. if ($warning) {
  247. $warning_type[] = $warning['type'];
  248. $warning['warning_name'] = $warning_names[$warning['warning_id']];
  249. $warning['content'] = $contents[$warning['warning_id']];
  250. $warning_list[] = $warning;
  251. $branch = $warning['branch'];
  252. }
  253. }
  254. $workorder_warning_type = "";
  255. $warning_type = array_flip(array_flip($warning_type));
  256. $index = 0;
  257. foreach ($warning_type as $key => $val) {
  258. if ($index < count($warning_type) - 1) {
  259. $workorder_warning_type .= $this->warning_type[$val] . "、";
  260. } else {
  261. $workorder_warning_type .= $this->warning_type[$val];
  262. }
  263. $index++;
  264. }
  265. $data['type'] = $workorder_warning_type;
  266. $data['warning_list'] = $warning_list;
  267. if ($this->input->post("remark_content", true)) {
  268. $remarks['remark_content'] = $this->input->post("remark_content", true);
  269. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  270. $remarks['remark_user_id'] = $this->session->user_id;
  271. $data['remark_list'][] = $remarks;
  272. } else {
  273. $data['remark_content'] = "";
  274. $data['remark_time'] = "";
  275. $data['remark_user_id'] = "";
  276. $data['remark_list'] = array();
  277. }
  278. $data['send_type'] = $this->input->post("send_type", true);
  279. if (count($data['send_type']) >= 1) {
  280. $is_validate = true;
  281. } else {
  282. $this->response(array("msg" => "请选择下发方式!", "icon" => 2));
  283. }
  284. if ($is_validate) {
  285. if ($this->input->post("receive_user", true)) {
  286. $user_info = $this->user_model->get_user_with_user_id($this->input->post("receive_user", true));
  287. if (!$user_info) {
  288. $user_info = $this->user_model->set_collection_name("sso_users")->get_user_with_user_id($this->input->post("receive_user", true));
  289. }
  290. if ($user_info) {
  291. if ($user_info['status'] == "10") {
  292. $data['receive_user_id'] = $this->input->post("receive_user", true);
  293. $data['branch'] = $branch;
  294. $data['status'] = "10";
  295. $data['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  296. $data['end_time'] = "";
  297. if ($this->workorder_model->insert_workorder($data)) {
  298. $wheres = array('warning_id' => array('$in' => $ids));
  299. $this->warning_model->set_val("status", $wheres, "30");
  300. $this->notices->create_workorder($data);
  301. $this->response(array("msg" => "工单生成成功!", "icon" => 1));
  302. } else {
  303. $this->response(array("msg" => "工单生成失败!请刷新后重试。", "icon" => 2));
  304. }
  305. } else {
  306. $this->response(array("msg" => "责任人被停用不能指定该责任人!", "icon" => 2));
  307. }
  308. } else {
  309. $this->response(array("msg" => "责任人不存在或者已经被删除!", "icon" => 2));
  310. }
  311. } else {
  312. $this->response(array("msg" => "请选择责任人!", "icon" => 2));
  313. }
  314. }
  315. }
  316. /**
  317. * 查看工单详情
  318. * @param $workorder_id 工单ID
  319. */
  320. public function view($workorder_id)
  321. {
  322. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  323. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  324. $remarks = array();
  325. foreach ($workorder['remark_list'] as $key => $remark) {
  326. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  327. $remarks[] = $remark;
  328. }
  329. $workorder['remark_list'] = $remarks;
  330. $workorder['last_remark_user'] = $remarks[count($remarks) - 1]['remark_user'];
  331. $workorder['last_remark_content'] = $remarks[count($remarks) - 1]['remark_content'];
  332. $workorder['last_remark_time'] = $remarks[count($remarks) - 1]['remark_time'];
  333. $this->assign("workorder", $workorder);
  334. $this->display("workorder/view.html");
  335. }
  336. /**
  337. * 导出工单
  338. * @param $workorder_id 工单ID
  339. */
  340. public function export($workorder_id)
  341. {
  342. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  343. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  344. $remarks = array();
  345. if (array_key_exists($workorder['branch']['branch_id'], $this->branch_array)) {
  346. $workorder['branch'] = $this->branch_array[$workorder['branch']['branch_id']]['branch_name'];
  347. } else {
  348. $workorder['branch'] = '未配置分支';
  349. }
  350. $send_type = "";
  351. foreach ($workorder['send_type'] as $type) {
  352. $send_type .= $this->send_type[$type] . "&nbsp;";
  353. }
  354. $workorder['send_type'] = $send_type;
  355. $workorder['status'] = $this->workorder_status[$workorder['status']];
  356. foreach ($workorder['remark_list'] as $key => $remark) {
  357. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  358. $remarks[] = $remark;
  359. }
  360. $workorder['remark_list'] = $remarks;
  361. $workorder['create_time'] = $workorder['create_time']->toDateTime()->format('Y-m-d h:i:s');
  362. $warnings = '<table style="width: 100%; margin: 0 auto;border-collapse:collapse;"><thead><tr><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;">告警名称</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;">告警类型</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;">告警等级</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;">时间</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;">告警内容</th></tr></thead><tbody>';
  363. foreach ($workorder['warning_list'] as $key => $warning) {
  364. $warnings .= '<tr><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $warning['warning_name'] . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $this->warning_type[$warning['type']] . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $this->warning_level[$warning['level']] . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $warning['create_time']->toDateTime()->format('Y-m-d h:i:s') . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $warning['content'] . '</td></tr>';
  365. }
  366. $warnings .= '</tbody></table>';
  367. $remarks = '<table style="width: 100%; margin: 0 auto;border-collapse:collapse;"><thead><tr><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >备注人</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >备注时间</th><th style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >备注内容</th></tr></thead><tbody>';
  368. foreach ($workorder['remark_list'] as $key => $remark) {
  369. $remarks .= '<tr><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $remark['remark_user']['name'] . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $remark['remark_time']->toDateTime()->format('Y-m-d h:i:s') . '</td><td style="word-break: break-all; border-width: 1px; border-style: solid; border-color: windowtext;" >' . $remark['remark_content'] . '</td>';
  370. }
  371. $remarks .= '</tbody></table>';
  372. $workorder['warnings'] = $warnings;
  373. $workorder['remarks'] = $remarks;
  374. $this->assign("workorder", $workorder);
  375. $this->display("export/workorder.html");
  376. }
  377. /**
  378. * 删除工单
  379. * @param $workorder_id 工单ID
  380. */
  381. public function delete($workorder_id)
  382. {
  383. $msg = array();
  384. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  385. if ($workorder_info) {
  386. $ids = array();
  387. foreach ($workorder_info['warning_list'] as $key => $val) {
  388. $ids[] = $val['warning_id'];
  389. }
  390. $wheres = array('warning_id' => array('$in' => $ids));
  391. $this->warning_model->set_val("status", $wheres, "20");
  392. $this->workorder_model->delete_workorder($workorder_id);
  393. $msg['msg'] = "工单删除成功!";
  394. $msg['icon'] = 1;
  395. } else {
  396. $msg['msg'] = "工单不存在或者已经被删除!";
  397. $msg['icon'] = 2;
  398. }
  399. $this->response($msg);
  400. }
  401. /**
  402. * 结束工单
  403. * @param $workorder_id 工单ID
  404. */
  405. public function finish($workorder_id)
  406. {
  407. $msg = array();
  408. if ($this->session->user_type == "1") {
  409. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  410. if ($workorder_info) {
  411. $workorder_info['status'] = "50";
  412. $workorder_info['end_time'] = new \MongoDB\BSON\UTCDateTime(time()*1000);
  413. $ids = array();
  414. foreach ($workorder_info['warning_list'] as $key => $val) {
  415. $ids[] = $val['warning_id'];
  416. }
  417. $wheres = array('warning_id' => array('$in' => $ids));
  418. $this->warning_model->set_val("status", $wheres, "40");
  419. $this->notices->finish_workorder($workorder_info);
  420. $this->workorder_model->update_workorder($workorder_info);
  421. $msg['msg'] = "结束工单操作成功!";
  422. $msg['icon'] = 1;
  423. } else {
  424. $msg['msg'] = "工单不存在或者已经被删除!";
  425. $msg['icon'] = 2;
  426. }
  427. } else {
  428. $msg['msg'] = "没有权限结束工单!";
  429. $msg['icon'] = 2;
  430. }
  431. $this->response($msg);
  432. }
  433. /**
  434. * 驳回工单
  435. * @param $workorder_id 工单ID
  436. */
  437. public function reject($workorder_id)
  438. {
  439. $msg = array();
  440. $remarks = array("remark_content" => "");
  441. if ($this->session->user_type == "1") {
  442. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  443. if ($workorder_info) {
  444. if ($this->input->post("remark_content", true)) {
  445. $remarks['remark_content'] = $this->input->post("remark_content", true);
  446. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  447. $remarks['remark_user_id'] = $this->session->user_id;
  448. $workorder_info['remark_list'][] = $remarks;
  449. }
  450. $workorder_info['status'] = "40";
  451. $this->notices->reject_workorder($workorder_info, $remarks);
  452. $this->workorder_model->update_workorder($workorder_info);
  453. $msg['msg'] = "驳回工单操作成功!";
  454. $msg['icon'] = 1;
  455. } else {
  456. $msg['msg'] = "工单不存在或者已经被删除!";
  457. $msg['icon'] = 2;
  458. }
  459. } else {
  460. $msg['msg'] = "没有权限驳回工单!";
  461. $msg['icon'] = 2;
  462. }
  463. $this->response($msg);
  464. }
  465. /**
  466. * 签收工单
  467. * @param $workorder_id 工单ID
  468. */
  469. public function sign($workorder_id)
  470. {
  471. $msg = array();
  472. $remarks = array("remark_content" => "");
  473. if ($this->session->user_type == "2") {
  474. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  475. if ($workorder_info) {
  476. if ($this->input->post("remark_content", true)) {
  477. $remarks['remark_content'] = $this->input->post("remark_content", true);
  478. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  479. $remarks['remark_user_id'] = $this->session->user_id;
  480. $workorder_info['remark_list'][] = $remarks;
  481. }
  482. $workorder_info['status'] = "20";
  483. $this->notices->sign_workorder($workorder_info, $remarks);
  484. $this->workorder_model->update_workorder($workorder_info);
  485. $msg['msg'] = "签收工单操作成功!";
  486. $msg['icon'] = 1;
  487. } else {
  488. $msg['msg'] = "工单不存在或者已经被删除!";
  489. $msg['icon'] = 2;
  490. }
  491. } else {
  492. $msg['msg'] = "只有工程师才可以签收工单!";
  493. $msg['icon'] = 2;
  494. }
  495. $this->response($msg);
  496. }
  497. /**
  498. * 处理工单
  499. * @param $workorder_id 工单ID
  500. */
  501. public function review($workorder_id)
  502. {
  503. $msg = array();
  504. $remarks = array("remark_content" => "");
  505. $action = $this->input->post("action", true);
  506. if ($this->session->user_type == "2") {
  507. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  508. if ($workorder_info) {
  509. if ($this->input->post("remark_content", true)) {
  510. $remarks['remark_content'] = $this->input->post("remark_content", true);
  511. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  512. $remarks['remark_user_id'] = $this->session->user_id;
  513. $remarks['remark_file'] = $this->input->post("remark_file", true);
  514. $workorder_info['remark_list'][] = $remarks;
  515. }
  516. $workorder_info['status'] = "30";
  517. if ($action == "check") {
  518. $this->notices->check_workorder($workorder_info, $remarks);
  519. } elseif ($action == "doit") {
  520. $this->notices->doit_workorder($workorder_info, $remarks);
  521. }
  522. $this->workorder_model->update_workorder($workorder_info);
  523. $msg['msg'] = "工单处理完成等待复核!";
  524. $msg['icon'] = 1;
  525. } else {
  526. $msg['msg'] = "工单不存在或者已经被删除!";
  527. $msg['icon'] = 2;
  528. }
  529. } else {
  530. $msg['msg'] = "只有工程师才可以处理工单!";
  531. $msg['icon'] = 2;
  532. }
  533. $this->response($msg);
  534. }
  535. /**
  536. * 工单附件上传
  537. */
  538. public function upload()
  539. {
  540. $time = time();
  541. $year = date('Y', $time);
  542. $month = date('m', $time);
  543. $day = date('d', $time);
  544. $subpath = "/{$year}/{$month}{$day}/";
  545. $upload_path = getcwd() . '/static/upload' . $subpath;
  546. if (!file_exists($upload_path)) {
  547. mkdir($upload_path, 0777, true);
  548. }
  549. $config['upload_path'] = $upload_path;
  550. $config['allowed_types'] = 'gif|jpg|png|rar|zip|7z|doc|docx|xls|xlsx|pdf|crv'; //允许上传的文件类型
  551. $config['max_size'] = 5120; //设置上传文件大小 5M
  552. $config['file_name'] = date('YmdHis', $time) . mt_rand(100, 999);
  553. $this->load->library('upload', $config);
  554. if ($this->upload->do_upload('remark_file')) {
  555. $file = $this->upload->data();
  556. $this->response(array("code" => 1, "file" => $subpath . $file['orig_name']));
  557. } else {
  558. $error = array('code' => 0, 'error' => strip_tags($this->upload->display_errors()));
  559. $this->response($error);
  560. }
  561. }
  562. }