Workorder.php 27 KB

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