Workorder.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. $resp = $this->notices->create_workorder($data);
  322. $msg = "工单生成成功!";
  323. $icon = 1;
  324. if($resp['sms_code'] != 'OK'){
  325. $icon = 0;
  326. $msg .= "短信发送失败!错误信息:".$resp['sms_msg'];
  327. }
  328. if($resp['email_code'] != 'OK'){
  329. $icon = 0;
  330. $msg .= "邮件发送失败!错误信息:".$resp['email_msg'];
  331. }
  332. $this->response(array("msg" => $msg, "icon" => $icon));
  333. } else {
  334. $this->response(array("msg" => "工单生成失败!请刷新后重试。", "icon" => 2));
  335. }
  336. } else {
  337. $this->response(array("msg" => "责任人被停用不能指定该责任人!", "icon" => 2));
  338. }
  339. } else {
  340. $this->response(array("msg" => "责任人不存在或者已经被删除!", "icon" => 2));
  341. }
  342. } else {
  343. $this->response(array("msg" => "请选择责任人!", "icon" => 2));
  344. }
  345. }
  346. }
  347. public function update_warning_status($ids){
  348. if(!is_array($ids)){
  349. $ids = explode(",", $ids);
  350. }
  351. foreach ($ids as $key => $val) {
  352. $wheres = array('_id' => new MongoDB\BSON\objectID($val));
  353. $this->warning_model->set_val("status", $wheres, "30");
  354. }
  355. }
  356. /**
  357. * 查看工单详情
  358. * @param $workorder_id 工单ID
  359. */
  360. public function view($workorder_id)
  361. {
  362. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  363. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  364. $remarks = array();
  365. foreach ($workorder['remark_list'] as $key => $remark) {
  366. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  367. $remarks[] = $remark;
  368. }
  369. $workorder['remark_list'] = $remarks;
  370. /*$workorder['last_remark_user'] = $remarks[count($remarks) - 1]['remark_user'];
  371. $workorder['last_remark_content'] = $remarks[count($remarks) - 1]['remark_content'];
  372. $workorder['last_remark_time'] = $remarks[count($remarks) - 1]['remark_time'];*/
  373. $this->assign("workorder", $workorder);
  374. $this->display("workorder/view.html");
  375. }
  376. /**
  377. * 导出工单
  378. * @param $workorder_id 工单ID
  379. */
  380. public function export($workorder_id)
  381. {
  382. $workorder = $this->workorder_model->get_workorder_with_id($workorder_id);
  383. $workorder['receive_user'] = $this->user_model->get_user_with_user_id($workorder['receive_user_id']);
  384. $remarks = array();
  385. if (array_key_exists($workorder['branch']['branch_id'], $this->branch_array)) {
  386. $workorder['branch'] = $this->branch_array[$workorder['branch']['branch_id']]['branch_name'];
  387. } else {
  388. $workorder['branch'] = '未配置分支';
  389. }
  390. $send_type = "";
  391. foreach ($workorder['send_type'] as $type) {
  392. $send_type .= $this->send_type[$type] . "&nbsp;";
  393. }
  394. $workorder['send_type'] = $send_type;
  395. $workorder['status'] = $this->workorder_status[$workorder['status']];
  396. foreach ($workorder['remark_list'] as $key => $remark) {
  397. $remark['remark_user'] = $this->user_model->get_user_with_user_id($remark['remark_user_id']);
  398. $remarks[] = $remark;
  399. }
  400. $workorder['remark_list'] = $remarks;
  401. $workorder['create_time'] = $workorder['create_time']->toDateTime()->format('Y-m-d h:i:s');
  402. $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>';
  403. foreach ($workorder['warning_list'] as $key => $warning) {
  404. if(!array_key_exists($warning['type'],$this->warning_type)) $warning['type']="unknown";
  405. $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>';
  406. }
  407. $warnings .= '</tbody></table>';
  408. $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>';
  409. foreach ($workorder['remark_list'] as $key => $remark) {
  410. $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>';
  411. }
  412. $remarks .= '</tbody></table>';
  413. $workorder['warnings'] = $warnings;
  414. $workorder['remarks'] = $remarks;
  415. $this->assign("workorder", $workorder);
  416. $this->display("export/workorder.html");
  417. }
  418. /**
  419. * 删除工单
  420. * @param $workorder_id 工单ID
  421. */
  422. public function delete($workorder_id)
  423. {
  424. $msg = array();
  425. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  426. if ($workorder_info) {
  427. $ids = array();
  428. foreach ($workorder_info['warning_list'] as $key => $val) {
  429. $ids[] = $val['warning_id'];
  430. }
  431. $wheres = array('warning_id' => array('$in' => $ids));
  432. $this->warning_model->set_val("status", $wheres, "20");
  433. $this->workorder_model->delete_workorder($workorder_id);
  434. $msg['msg'] = "工单删除成功!";
  435. $msg['icon'] = 1;
  436. } else {
  437. $msg['msg'] = "工单不存在或者已经被删除!";
  438. $msg['icon'] = 2;
  439. }
  440. $this->response($msg);
  441. }
  442. /**
  443. * 结束工单
  444. * @param $workorder_id 工单ID
  445. */
  446. public function finish($workorder_id)
  447. {
  448. $msg = array();
  449. if ($this->session->user_type == "1") {
  450. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  451. if ($workorder_info) {
  452. $workorder_info['status'] = "50";
  453. $workorder_info['end_time'] = new \MongoDB\BSON\UTCDateTime(time()*1000);
  454. $ids = array();
  455. foreach ($workorder_info['warning_list'] as $key => $val) {
  456. $ids[] = $val['warning_id'];
  457. }
  458. $wheres = array('warning_id' => array('$in' => $ids));
  459. $this->warning_model->set_val("status", $wheres, "40");
  460. $resp = $this->notices->finish_workorder($workorder_info);
  461. $this->workorder_model->update_workorder($workorder_info);
  462. $msg['msg'] = "结束工单操作成功!";
  463. $msg['icon'] = 1;
  464. if($resp['sms_code'] != 'OK'){
  465. $msg['icon'] = 0;
  466. $msg['msg'] .= "短信发送失败!错误信息:".$resp['sms_msg'];
  467. }
  468. if($resp['email_code'] != 'OK'){
  469. $msg['icon'] = 0;
  470. $msg['msg'] .= "邮件发送失败!错误信息:".$resp['email_msg'];
  471. }
  472. } else {
  473. $msg['msg'] = "工单不存在或者已经被删除!";
  474. $msg['icon'] = 2;
  475. }
  476. } else {
  477. $msg['msg'] = "没有权限结束工单!";
  478. $msg['icon'] = 2;
  479. }
  480. $this->response($msg);
  481. }
  482. /**
  483. * 驳回工单
  484. * @param $workorder_id 工单ID
  485. */
  486. public function reject($workorder_id)
  487. {
  488. $msg = array();
  489. $remarks = array("remark_content" => "");
  490. if ($this->session->user_type == "1") {
  491. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  492. if ($workorder_info) {
  493. if ($this->input->post("remark_content", true)) {
  494. $remarks['remark_content'] = $this->input->post("remark_content", true);
  495. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  496. $remarks['remark_user_id'] = $this->session->user_id;
  497. $workorder_info['remark_list'][] = $remarks;
  498. }
  499. $workorder_info['status'] = "40";
  500. $resp = $this->notices->reject_workorder($workorder_info, $remarks);
  501. $this->workorder_model->update_workorder($workorder_info);
  502. $msg['msg'] = "驳回工单操作成功!";
  503. $msg['icon'] = 1;
  504. if($resp['sms_code'] != 'OK'){
  505. $msg['icon'] = 0;
  506. $msg['msg'] .= "短信发送失败!错误信息:".$resp['sms_msg'];
  507. }
  508. if($resp['email_code'] != 'OK'){
  509. $msg['icon'] = 0;
  510. $msg['msg'] .= "邮件发送失败!错误信息:".$resp['email_msg'];
  511. }
  512. } else {
  513. $msg['msg'] = "工单不存在或者已经被删除!";
  514. $msg['icon'] = 2;
  515. }
  516. } else {
  517. $msg['msg'] = "没有权限驳回工单!";
  518. $msg['icon'] = 2;
  519. }
  520. $this->response($msg);
  521. }
  522. /**
  523. * 签收工单
  524. * @param $workorder_id 工单ID
  525. */
  526. public function sign($workorder_id)
  527. {
  528. $msg = array();
  529. $remarks = array("remark_content" => "");
  530. if ($this->session->user_type == "2") {
  531. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  532. if ($workorder_info) {
  533. if ($this->input->post("remark_content", true)) {
  534. $remarks['remark_content'] = $this->input->post("remark_content", true);
  535. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  536. $remarks['remark_user_id'] = $this->session->user_id;
  537. $workorder_info['remark_list'][] = $remarks;
  538. }
  539. $workorder_info['status'] = "20";
  540. $resp = $this->notices->sign_workorder($workorder_info, $remarks);
  541. $this->workorder_model->update_workorder($workorder_info);
  542. $msg['msg'] = "签收工单操作成功!";
  543. $msg['icon'] = 1;
  544. if($resp['sms_code'] != 'OK'){
  545. $msg['icon'] = 0;
  546. $msg['msg'] .= "短信发送失败!错误信息:".$resp['sms_msg'];
  547. }
  548. if($resp['email_code'] != 'OK'){
  549. $msg['icon'] = 0;
  550. $msg['msg'] .= "邮件发送失败!错误信息:".$resp['email_msg'];
  551. }
  552. } else {
  553. $msg['msg'] = "工单不存在或者已经被删除!";
  554. $msg['icon'] = 2;
  555. }
  556. } else {
  557. $msg['msg'] = "只有工程师才可以签收工单!";
  558. $msg['icon'] = 2;
  559. }
  560. $this->response($msg);
  561. }
  562. /**
  563. * 处理工单
  564. * @param $workorder_id 工单ID
  565. */
  566. public function review($workorder_id)
  567. {
  568. $msg = array();
  569. $remarks = array("remark_content" => "");
  570. $action = $this->input->post("action", true);
  571. if ($this->session->user_type == "2") {
  572. $workorder_info = $this->workorder_model->get_workorder_with_id($workorder_id);
  573. if ($workorder_info) {
  574. if ($this->input->post("remark_content", true)) {
  575. $remarks['remark_content'] = $this->input->post("remark_content", true);
  576. $remarks['remark_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  577. $remarks['remark_user_id'] = $this->session->user_id;
  578. $remarks['remark_file'] = $this->input->post("remark_file", true);
  579. $workorder_info['remark_list'][] = $remarks;
  580. }
  581. $workorder_info['status'] = "30";
  582. if ($action == "check") {
  583. $resp = $this->notices->check_workorder($workorder_info, $remarks);
  584. } elseif ($action == "doit") {
  585. $resp = $this->notices->doit_workorder($workorder_info, $remarks);
  586. }
  587. $this->workorder_model->update_workorder($workorder_info);
  588. $msg['msg'] = "工单处理完成等待复核!";
  589. $msg['icon'] = 1;
  590. if($resp['sms_code'] != 'OK'){
  591. $msg['icon'] = 0;
  592. $msg['msg'] .= "短信发送失败!错误信息:".$resp['sms_msg'];
  593. }
  594. if($resp['email_code'] != 'OK'){
  595. $msg['icon'] = 0;
  596. $msg['msg'] .= "邮件发送失败!错误信息:".$resp['email_msg'];
  597. }
  598. } else {
  599. $msg['msg'] = "工单不存在或者已经被删除!";
  600. $msg['icon'] = 2;
  601. }
  602. } else {
  603. $msg['msg'] = "只有工程师才可以处理工单!";
  604. $msg['icon'] = 2;
  605. }
  606. $this->response($msg);
  607. }
  608. /**
  609. * 工单附件上传
  610. */
  611. public function upload()
  612. {
  613. $time = time();
  614. $year = date('Y', $time);
  615. $month = date('m', $time);
  616. $day = date('d', $time);
  617. $subpath = "/{$year}/{$month}{$day}/";
  618. $upload_path = getcwd() . '/static/upload' . $subpath;
  619. if (!file_exists($upload_path)) {
  620. mkdir($upload_path, 0777, true);
  621. }
  622. $config['upload_path'] = $upload_path;
  623. $config['allowed_types'] = 'gif|jpg|png|rar|zip|7z|doc|docx|xls|xlsx|pdf|crv'; //允许上传的文件类型
  624. $config['max_size'] = 5120; //设置上传文件大小 5M
  625. $config['file_name'] = date('YmdHis', $time) . mt_rand(100, 999);
  626. $this->load->library('upload', $config);
  627. if ($this->upload->do_upload('remark_file')) {
  628. $file = $this->upload->data();
  629. $this->response(array("code" => 1, "file" => $subpath . $file['orig_name']));
  630. } else {
  631. $error = array('code' => 0, 'error' => strip_tags($this->upload->display_errors()));
  632. $this->response($error);
  633. }
  634. }
  635. }