Workorder.php 28 KB

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