Workorder.php 27 KB

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