Workorder.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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_objectid($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_objectid($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. if(array_key_exists($val,$this->warning_type)) {
  260. $workorder_warning_type .= $this->warning_type[$val] . "、";
  261. }else{
  262. $workorder_warning_type .= $val."、";
  263. }
  264. } else {
  265. if(array_key_exists($val,$this->warning_type)) {
  266. $workorder_warning_type .= $this->warning_type[$val];
  267. }else{
  268. $workorder_warning_type .= $val;
  269. }
  270. }
  271. $index++;
  272. }
  273. $data['type'] = $workorder_warning_type;
  274. $data['warning_list'] = $warning_list;
  275. if ($this->input->post("remark_content", true)) {
  276. $remarks['remark_content'] = $this->input->post("remark_content", true);
  277. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  278. $remarks['remark_user_id'] = $this->session->user_id;
  279. $data['remark_list'][] = $remarks;
  280. } else {
  281. $data['remark_content'] = "";
  282. $data['remark_time'] = "";
  283. $data['remark_user_id'] = "";
  284. $data['remark_list'] = array();
  285. }
  286. $data['send_type'] = $this->input->post("send_type", true);
  287. if (count($data['send_type']) >= 1) {
  288. $is_validate = true;
  289. } else {
  290. $this->response(array("msg" => "请选择下发方式!", "icon" => 2));
  291. }
  292. if ($is_validate) {
  293. if ($this->input->post("receive_user", true)) {
  294. $user_info = $this->user_model->get_user_with_user_id($this->input->post("receive_user", true));
  295. if (!$user_info) {
  296. $user_info = $this->user_model->set_collection_name("sso_users")->get_user_with_user_id($this->input->post("receive_user", true));
  297. }
  298. if ($user_info) {
  299. if ($user_info['status'] == "10") {
  300. $data['receive_user_id'] = $this->input->post("receive_user", true);
  301. $data['branch'] = $branch;
  302. $data['status'] = "10";
  303. $data['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  304. $data['end_time'] = "";
  305. if ($this->workorder_model->insert_workorder($data)) {
  306. $wheres = array('warning_id' => array('$in' => $ids));
  307. $this->warning_model->set_val("status", $wheres, "30");
  308. $this->notices->create_workorder($data);
  309. $this->response(array("msg" => "工单生成成功!", "icon" => 1));
  310. } else {
  311. $this->response(array("msg" => "工单生成失败!请刷新后重试。", "icon" => 2));
  312. }
  313. } else {
  314. $this->response(array("msg" => "责任人被停用不能指定该责任人!", "icon" => 2));
  315. }
  316. } else {
  317. $this->response(array("msg" => "责任人不存在或者已经被删除!", "icon" => 2));
  318. }
  319. } else {
  320. $this->response(array("msg" => "请选择责任人!", "icon" => 2));
  321. }
  322. }
  323. }
  324. /**
  325. * 查看工单详情
  326. * @param $workorder_id 工单ID
  327. */
  328. public function view($workorder_id)
  329. {
  330. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  331. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  332. $remarks = array();
  333. foreach ($workorder['remark_list'] as $key => $remark) {
  334. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  335. $remarks[] = $remark;
  336. }
  337. $workorder['remark_list'] = $remarks;
  338. $workorder['last_remark_user'] = $remarks[count($remarks) - 1]['remark_user'];
  339. $workorder['last_remark_content'] = $remarks[count($remarks) - 1]['remark_content'];
  340. $workorder['last_remark_time'] = $remarks[count($remarks) - 1]['remark_time'];
  341. $this->assign("workorder", $workorder);
  342. $this->display("workorder/view.html");
  343. }
  344. /**
  345. * 导出工单
  346. * @param $workorder_id 工单ID
  347. */
  348. public function export($workorder_id)
  349. {
  350. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  351. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  352. $remarks = array();
  353. if (array_key_exists($workorder['branch']['branch_id'], $this->branch_array)) {
  354. $workorder['branch'] = $this->branch_array[$workorder['branch']['branch_id']]['branch_name'];
  355. } else {
  356. $workorder['branch'] = '未配置分支';
  357. }
  358. $send_type = "";
  359. foreach ($workorder['send_type'] as $type) {
  360. $send_type .= $this->send_type[$type] . "&nbsp;";
  361. }
  362. $workorder['send_type'] = $send_type;
  363. $workorder['status'] = $this->workorder_status[$workorder['status']];
  364. foreach ($workorder['remark_list'] as $key => $remark) {
  365. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  366. $remarks[] = $remark;
  367. }
  368. $workorder['remark_list'] = $remarks;
  369. $workorder['create_time'] = $workorder['create_time']->toDateTime()->format('Y-m-d h:i:s');
  370. $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>';
  371. foreach ($workorder['warning_list'] as $key => $warning) {
  372. $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>';
  373. }
  374. $warnings .= '</tbody></table>';
  375. $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>';
  376. foreach ($workorder['remark_list'] as $key => $remark) {
  377. $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>';
  378. }
  379. $remarks .= '</tbody></table>';
  380. $workorder['warnings'] = $warnings;
  381. $workorder['remarks'] = $remarks;
  382. $this->assign("workorder", $workorder);
  383. $this->display("export/workorder.html");
  384. }
  385. /**
  386. * 删除工单
  387. * @param $workorder_id 工单ID
  388. */
  389. public function delete($workorder_id)
  390. {
  391. $msg = array();
  392. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  393. if ($workorder_info) {
  394. $ids = array();
  395. foreach ($workorder_info['warning_list'] as $key => $val) {
  396. $ids[] = $val['warning_id'];
  397. }
  398. $wheres = array('warning_id' => array('$in' => $ids));
  399. $this->warning_model->set_val("status", $wheres, "20");
  400. $this->workorder_model->delete_workorder($workorder_id);
  401. $msg['msg'] = "工单删除成功!";
  402. $msg['icon'] = 1;
  403. } else {
  404. $msg['msg'] = "工单不存在或者已经被删除!";
  405. $msg['icon'] = 2;
  406. }
  407. $this->response($msg);
  408. }
  409. /**
  410. * 结束工单
  411. * @param $workorder_id 工单ID
  412. */
  413. public function finish($workorder_id)
  414. {
  415. $msg = array();
  416. if ($this->session->user_type == "1") {
  417. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  418. if ($workorder_info) {
  419. $workorder_info['status'] = "50";
  420. $workorder_info['end_time'] = new \MongoDB\BSON\UTCDateTime(time()*1000);
  421. $ids = array();
  422. foreach ($workorder_info['warning_list'] as $key => $val) {
  423. $ids[] = $val['warning_id'];
  424. }
  425. $wheres = array('warning_id' => array('$in' => $ids));
  426. $this->warning_model->set_val("status", $wheres, "40");
  427. $this->notices->finish_workorder($workorder_info);
  428. $this->workorder_model->update_workorder($workorder_info);
  429. $msg['msg'] = "结束工单操作成功!";
  430. $msg['icon'] = 1;
  431. } else {
  432. $msg['msg'] = "工单不存在或者已经被删除!";
  433. $msg['icon'] = 2;
  434. }
  435. } else {
  436. $msg['msg'] = "没有权限结束工单!";
  437. $msg['icon'] = 2;
  438. }
  439. $this->response($msg);
  440. }
  441. /**
  442. * 驳回工单
  443. * @param $workorder_id 工单ID
  444. */
  445. public function reject($workorder_id)
  446. {
  447. $msg = array();
  448. $remarks = array("remark_content" => "");
  449. if ($this->session->user_type == "1") {
  450. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  451. if ($workorder_info) {
  452. if ($this->input->post("remark_content", true)) {
  453. $remarks['remark_content'] = $this->input->post("remark_content", true);
  454. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  455. $remarks['remark_user_id'] = $this->session->user_id;
  456. $workorder_info['remark_list'][] = $remarks;
  457. }
  458. $workorder_info['status'] = "40";
  459. $this->notices->reject_workorder($workorder_info, $remarks);
  460. $this->workorder_model->update_workorder($workorder_info);
  461. $msg['msg'] = "驳回工单操作成功!";
  462. $msg['icon'] = 1;
  463. } else {
  464. $msg['msg'] = "工单不存在或者已经被删除!";
  465. $msg['icon'] = 2;
  466. }
  467. } else {
  468. $msg['msg'] = "没有权限驳回工单!";
  469. $msg['icon'] = 2;
  470. }
  471. $this->response($msg);
  472. }
  473. /**
  474. * 签收工单
  475. * @param $workorder_id 工单ID
  476. */
  477. public function sign($workorder_id)
  478. {
  479. $msg = array();
  480. $remarks = array("remark_content" => "");
  481. if ($this->session->user_type == "2") {
  482. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  483. if ($workorder_info) {
  484. if ($this->input->post("remark_content", true)) {
  485. $remarks['remark_content'] = $this->input->post("remark_content", true);
  486. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  487. $remarks['remark_user_id'] = $this->session->user_id;
  488. $workorder_info['remark_list'][] = $remarks;
  489. }
  490. $workorder_info['status'] = "20";
  491. $this->notices->sign_workorder($workorder_info, $remarks);
  492. $this->workorder_model->update_workorder($workorder_info);
  493. $msg['msg'] = "签收工单操作成功!";
  494. $msg['icon'] = 1;
  495. } else {
  496. $msg['msg'] = "工单不存在或者已经被删除!";
  497. $msg['icon'] = 2;
  498. }
  499. } else {
  500. $msg['msg'] = "只有工程师才可以签收工单!";
  501. $msg['icon'] = 2;
  502. }
  503. $this->response($msg);
  504. }
  505. /**
  506. * 处理工单
  507. * @param $workorder_id 工单ID
  508. */
  509. public function review($workorder_id)
  510. {
  511. $msg = array();
  512. $remarks = array("remark_content" => "");
  513. $action = $this->input->post("action", true);
  514. if ($this->session->user_type == "2") {
  515. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  516. if ($workorder_info) {
  517. if ($this->input->post("remark_content", true)) {
  518. $remarks['remark_content'] = $this->input->post("remark_content", true);
  519. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  520. $remarks['remark_user_id'] = $this->session->user_id;
  521. $remarks['remark_file'] = $this->input->post("remark_file", true);
  522. $workorder_info['remark_list'][] = $remarks;
  523. }
  524. $workorder_info['status'] = "30";
  525. if ($action == "check") {
  526. $this->notices->check_workorder($workorder_info, $remarks);
  527. } elseif ($action == "doit") {
  528. $this->notices->doit_workorder($workorder_info, $remarks);
  529. }
  530. $this->workorder_model->update_workorder($workorder_info);
  531. $msg['msg'] = "工单处理完成等待复核!";
  532. $msg['icon'] = 1;
  533. } else {
  534. $msg['msg'] = "工单不存在或者已经被删除!";
  535. $msg['icon'] = 2;
  536. }
  537. } else {
  538. $msg['msg'] = "只有工程师才可以处理工单!";
  539. $msg['icon'] = 2;
  540. }
  541. $this->response($msg);
  542. }
  543. /**
  544. * 工单附件上传
  545. */
  546. public function upload()
  547. {
  548. $time = time();
  549. $year = date('Y', $time);
  550. $month = date('m', $time);
  551. $day = date('d', $time);
  552. $subpath = "/{$year}/{$month}{$day}/";
  553. $upload_path = getcwd() . '/static/upload' . $subpath;
  554. if (!file_exists($upload_path)) {
  555. mkdir($upload_path, 0777, true);
  556. }
  557. $config['upload_path'] = $upload_path;
  558. $config['allowed_types'] = 'gif|jpg|png|rar|zip|7z|doc|docx|xls|xlsx|pdf|crv'; //允许上传的文件类型
  559. $config['max_size'] = 5120; //设置上传文件大小 5M
  560. $config['file_name'] = date('YmdHis', $time) . mt_rand(100, 999);
  561. $this->load->library('upload', $config);
  562. if ($this->upload->do_upload('remark_file')) {
  563. $file = $this->upload->data();
  564. $this->response(array("code" => 1, "file" => $subpath . $file['orig_name']));
  565. } else {
  566. $error = array('code' => 0, 'error' => strip_tags($this->upload->display_errors()));
  567. $this->response($error);
  568. }
  569. }
  570. }