Repair.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. /**
  4. *
  5. */
  6. class Repair extends Base_Controller
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->model('Repair_model');
  12. $this->load->model('User_model');
  13. $this->load->model('Alarm_model');
  14. $this->load->model('Lamp_model');
  15. }
  16. // 维修记录列表
  17. public function repair_list(){
  18. $role = $this->get_user_info('role');
  19. $userid = $this->get_user_info('id');
  20. $companyid = $this->get_user_info('companyid');
  21. $projectid = $this->input->post('projectid',true);
  22. $page = $this->input->post('page',true);
  23. $count = $this->input->post('count',true);
  24. $page = empty($page) ? 1 : $page;
  25. $count = empty($count) ? 16 : $count;
  26. // 设置需要获取的字段
  27. $field = "P.projectname as project_name,
  28. N.networkname as network_name,
  29. L.number as lampid,
  30. R.repair_path,
  31. RU.id as userid,
  32. RU.name as name,
  33. R.repair_hitch,
  34. R.repair_solution,
  35. R.repair_time,
  36. R.id";
  37. $keyword = $this->input->post('keyword',true);
  38. // 获取维修列表数据
  39. $data = $this->Repair_model->get_list_by_role(array('keyword'=>$keyword),$role,$userid,$companyid,$projectid,$field,$page,$count);
  40. // 获取维修总数
  41. $total = $this->Repair_model->get_total_by_role(array('keyword'=>$keyword),$role,$userid,$companyid,$projectid);
  42. // 设置分页
  43. json_result('0000',$this->response['0000'],array('total'=>ceil($total/$count),'list'=>$data));
  44. }
  45. // 近期维修列表
  46. public function near_repair_list(){
  47. $role = $this->get_user_info('role');
  48. $userid = $this->get_user_info('id');
  49. $companyid = $this->get_user_info('companyid');
  50. // 设置需要获取的字段
  51. $field = "P.projectname as project_name,
  52. R.lampid,
  53. R.id,
  54. RU.name as repair_username,
  55. R.repair_hitch,
  56. R.repair_solution,
  57. R.created as createtime";
  58. // 获取维修列表数据
  59. $data = $this->Repair_model->get_list_by_role(array(),$role,$userid,$companyid,0,$field,1,10);
  60. // 获取维修人员总数
  61. $total = $this->Repair_model->get_repair_user_total(array('id'=>$userid,'role'=>$role));
  62. exit(json_result('0000',$this->response['0000'],array('repair_list'=>$data,'total'=>$total)));
  63. }
  64. // 维修人员列表
  65. public function repair_user_list(){
  66. $tag = $this->input->post('tag',true);
  67. $keyword = $this->input->post('keyword',true);
  68. $page = $this->input->post('page',true);
  69. $count = $this->input->post('count',true);
  70. $version = $this->session->userdata('version');;
  71. $page = empty($page) ? 1 : $page;
  72. $count = empty($count) ? 16 : $count;
  73. $filter = array();
  74. if (!empty($tag)) {
  75. $filter['tag'] = strtoupper($tag);
  76. }
  77. if (!empty($keyword)) {
  78. $filter['keyword'] = $keyword;
  79. }
  80. $filter['user_id'] = $this->get_user_info('id');
  81. $data = $this->User_model->get_repair_user_list($filter,$this->userinfo,$page,$count);
  82. $total = $this->User_model->get_repair_user_count($filter,$this->userinfo);
  83. foreach ($data as &$v) {
  84. if (empty($v['repair_path'])) {
  85. if (empty($version)) {
  86. $v['repair_path'] = '暂无近期维修信息';
  87. }else{
  88. $v['repair_path'] = 'No recent maintenance information is available';
  89. }
  90. }
  91. }
  92. exit(json_result('0000',$this->response['0000'],array('list'=>$data,'total'=>ceil($total/$count))));
  93. }
  94. // 维修人员下拉列表
  95. public function user_list(){
  96. $filter['user_id'] = $this->get_user_info('id');
  97. $data = $this->User_model->get_repair_user_list($filter,$this->userinfo,0,0,1);
  98. exit(json_result('0000',$this->response['0000'],array('list'=>$data)));
  99. }
  100. // 维修人员详情
  101. public function user_info(){
  102. $userid = $this->input->post('userid',true);
  103. $page = $this->input->post('page',true);
  104. $count = $this->input->post('count',true);
  105. $page = empty($page) ? 1 : $page;
  106. $count = empty($count) ? 10 : $count;
  107. if (empty($userid)) {
  108. exit(json_result('0007', $this->response['0007'], array()));
  109. }
  110. $field = 'id as userid,name,number as repair_id,owner_id,department,telephone as phone,email';
  111. $user_info = $this->User_model->get_one_repair_user($userid,$field);
  112. if (empty($user_info)) {
  113. exit(json_result('0601', $this->response['0601'], array()));
  114. }else{
  115. $res = $this->User_model->getOne($user_info['owner_id'],'username');
  116. $user_info['owner'] = $res['username'];
  117. // 获取维修信息列表
  118. $data = $this->Repair_model->getlist(array('userid'=>$userid),$page,$count);
  119. $user_info['repair_list']=$data;
  120. $total = $this->Repair_model->gettotal(array('userid'=>$userid));
  121. $user_info['total'] = ceil($total/$count);
  122. exit(json_result('0000', $this->response['0000'],$user_info));
  123. }
  124. }
  125. // 维修人
  126. public function repair_user(){
  127. $alarmid = $this->input->post('alarmid',true);
  128. if (empty($alarmid)) {
  129. exit(json_result('0007',$this->response['0007'],array()));
  130. }
  131. $page = $this->input->post('page',true);
  132. $count = $this->input->post('count',true);
  133. $page = empty($page) ? 1 : $page;
  134. $count = empty($count) ? 1 : $count;
  135. $alarmData = $this->Alarm_model->getOne($alarmid,'A.lampid,A.alarmtype');
  136. $data = $this->Repair_model->get_list_by_filter(array('lampid'=>$alarmData['lampid']),'repair_userid');
  137. $userid = array_unique(array_column($data, 'repair_userid'));
  138. $userList = $this->Repair_model->get_repair_user_by_filter(array('id'=>$userid,'page'=>$page,'count'=>$count));
  139. if (empty($userList)) {
  140. exit(json_result('0616',$this->response['0616'],array()));
  141. }
  142. // $user_info = $this->User_model->get_one_repair_user($userid);
  143. exit(json_result('0000',$this->response['0000'],array('list'=>$userList,'total'=>ceil(count($userid)/$count))));
  144. }
  145. // 编辑/添加维修人员
  146. public function save_repair_user(){
  147. $role = $this->get_user_info('role');
  148. // if ($role == COMPANY_CUSTOMER) {
  149. // exit(json_result('0011', $this->response['0011'], array()));
  150. // }
  151. $repair_userid = $this->input->post('userid',true);
  152. // 获取维修人员信息
  153. $data['number'] = intval($this->input->post('repair_id',true)); // 维修人员id
  154. $data['name'] = $this->input->post('name',true); // 维修人员名称
  155. $data['department'] = $this->input->post('department',true); // 部门
  156. $phone = $this->input->post('phone',true); // 手机
  157. $email = $this->input->post('email',true); // 邮箱
  158. if(empty($data['number']) || $data['number'] < 0 || $data['number'] > 999999) exit(json_result('0617',$this->response['0617'],array()));
  159. if(!isset($data['name'])) exit(json_result('0606',$this->response['0606'],array()));
  160. if(!isset($phone) || empty($phone)) exit(json_result('0607',$this->response['0607'],array()));
  161. $config = array();
  162. if(!empty($phone)){
  163. $config[] = array(
  164. 'field' => 'phone',
  165. 'label' => 'Phone',
  166. 'rules' => 'numeric|exact_length[11]',
  167. 'errors' => array(
  168. 'numeric' => '0718',
  169. 'exact_length' => '0718'
  170. )
  171. );
  172. $data['telephone'] = $phone;
  173. }
  174. if (!empty($email)) {
  175. $config[] = array(
  176. 'field' => 'email',
  177. 'label' => 'Email',
  178. 'rules' => 'valid_email',
  179. 'errors' => array(
  180. 'valid_email' => '0719',
  181. )
  182. );
  183. $data['email'] = $email;
  184. }
  185. if (!empty($config)) {
  186. $this->load->library('form_validation');
  187. $this->form_validation->set_rules($config);
  188. if ($this->form_validation->run() == FALSE){
  189. $errors = $this->form_validation->error_array();
  190. exit(json_result(current($errors),$this->response[current($errors)],array()));
  191. }
  192. }
  193. $data['tag'] = get_first_char($data['name']);
  194. if (empty($repair_userid)) { // 添加维修人员信息
  195. // 检查维修员工id是否已经存在
  196. // $res = $this->Repair_model->get_repair_user_id(array('number'=>$data['number']));
  197. if($this->Repair_model->get_repair_user_id(array('name'=>$data['name'],'telephone'=>$data['telephone']))){
  198. exit(json_result('0602',$this->response['0602'],array()));
  199. }
  200. $data['owner_id'] = $this->get_user_info('id');
  201. $userid = $this->User_model->add_repair_user($data);
  202. $this->add_operation_log('insert',"添加\"{$data['name']}\"维修人员",0);
  203. $this->add_operation_log('insert',"Add repair personnel.Name:\"{$data['name']}\"",0,1);
  204. }else{ // 编辑维修人员信息
  205. // 检查维修员工id是否已经存在
  206. if($this->Repair_model->get_repair_user_id(array('name'=>$data['name'],'telephone'=>$data['telephone']),$repair_userid)){
  207. exit(json_result('0602',$this->response['0602'],array()));
  208. }
  209. $this->User_model->update_repair_user($repair_userid,$data);
  210. $userid = $repair_userid;
  211. $this->add_operation_log('update',"修改\"{$data['name']}\"维修人员",0);
  212. $this->add_operation_log('update',"Update repair personnel.Name:\"{$data['name']}\"",0,1);
  213. }
  214. exit(json_result('0000',$this->response['0000'],array('userid'=>$userid)));
  215. }
  216. // 删除维修人员
  217. public function del_repair_user(){
  218. $userid = $this->input->post('userid',true);
  219. $role = $this->get_user_info('role');
  220. // 检查用户权限
  221. // if ($role == COMPANY_CUSTOMER) {
  222. // exit(json_result('0011',$this->response['0011'],array()));
  223. // }
  224. // 参数有误
  225. if (empty($userid)) {
  226. exit(json_result('0608',$this->response['0608'],array()));
  227. }
  228. $user_info = $this->User_model->get_one_repair_user($userid,'name');
  229. $this->add_operation_log('delete',"删除\"{$user_info['name']}\"维修人员",0);
  230. $this->add_operation_log('delete',"Delete repair personnel.Name:\"{$user_info['name']}\"",0,1);
  231. $this->User_model->delete_repair_user($userid);
  232. exit(json_result('0000',$this->response['0000'],array()));
  233. }
  234. // 删除维修记录
  235. public function del_repair_info(){
  236. $role = $this->get_user_info('role');
  237. // if ($role == COMPANY_CUSTOMER) {
  238. // exit(json_result('0011', $this->response['0011'], array()));
  239. // }
  240. $id = $this->input->post('id',true);
  241. if (empty($id)) {
  242. exit(json_result('0609',$this->response['0609'],array()));
  243. }
  244. $idsArr = explode(',', $id);
  245. foreach ($idsArr as $v) {
  246. $repairData = $this->Repair_model->getOne($v,'repair_userid');
  247. $this->Repair_model->minus_repaircount($repairData['repair_userid']);
  248. $this->Repair_model->delOne($v);
  249. $this->add_operation_log('delete','删除维修记录 id:'.$v,0);
  250. $this->add_operation_log('delete','Delete maintenance record.ID:'.$v,0,1);
  251. }
  252. exit(json_result('0000',$this->response['0000'],array()));
  253. }
  254. // 添加/修改维修调度信息
  255. public function update_dispatch(){
  256. $role = $this->get_user_info('role');
  257. // if ($role == COMPANY_CUSTOMER) {
  258. // exit(json_result('0011',$this->response['0011'],array()));
  259. // }
  260. $where['id'] = $this->input->post('id',true);
  261. $data['repair_userid'] = $this->input->post('repair_id',true); // 维修人员id
  262. $data['repair_path'] = $this->input->post('address',true); // 维修路段
  263. $data['projectid'] = $this->input->post('projectid',true); // 项目id
  264. $data['networkid'] = $this->input->post('networkid',true); // 网络id
  265. $data['starttime'] = $this->input->post('starttime',true); // 开始时间
  266. $data['plantime'] = $this->input->post('plantime',true); // 计划完成时间
  267. $finishtime = $this->input->post('finishtime',true); // 实际完成时间
  268. if(!empty($finishtime)) $data['finishtime'] = $finishtime;
  269. if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
  270. if(empty($data['projectid'])) exit(json_result('0308',$this->response['0308'],array()));
  271. if(empty($data['networkid'])) exit(json_result('0405',$this->response['0405'],array()));
  272. if(empty($data['plantime'])) exit(json_result('0611',$this->response['0611'],array()));
  273. if(empty($data['starttime'])) exit(json_result('0612',$this->response['0612'],array()));
  274. if (empty($where['id'])) { // 添加调度信息
  275. $id = $this->Repair_model->insertDispatch($data);
  276. $this->add_operation_log('insert','添加调度信息 id:'.$id,0);
  277. $this->add_operation_log('insert','Add scheduling information.ID:'.$id,0,1);
  278. }else{ // 编辑调度信息
  279. $this->Repair_model->updateDispatch($where,$data);
  280. $this->add_operation_log('update','修改调度信息 id:'.$where['id'],0);
  281. $this->add_operation_log('update','Update scheduling information.ID:'.$where['id'],0,1);
  282. $id = $where['id'];
  283. }
  284. exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
  285. }
  286. // 维修调度
  287. public function repair_dispatch(){
  288. $role = $this->get_user_info('role');
  289. // if ($role == COMPANY_CUSTOMER) {
  290. // exit(json_result('0011',$this->response['0011'],array()));
  291. // }
  292. $alarmid = $this->input->post('alarmid',true);
  293. $data['repair_userid'] = $this->input->post('userid',true);
  294. if(empty($alarmid)) exit(json_result('0613',$this->response['0613'],array()));
  295. if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
  296. // 获取维修调度信息
  297. $res1 = $this->Alarm_model->getOne($alarmid,'A.lampid');
  298. // $data['alarmid'] = $alarmid;
  299. $data['lampid'] = $res1['lampid'];
  300. // 判断调度时间是否过期
  301. // $repairData = $this->Repair_model->getDispatchData(array('lampid'=>$data['lampid']),'created');
  302. // if (!empty($repairData['created'])) {
  303. // if (time() <= strtotime($repairData['created'])+30*60) {
  304. // exit(json_result('0615',$this->response['0615'],array()));
  305. // }
  306. // }
  307. $res2 = $this->Lamp_model->getOne($data['lampid'],'L.projectid as projectid,L.networkid as networkid,N.section');
  308. $data['address'] = $res2['section'];
  309. $data['projectid'] = $res2['projectid'];
  310. $data['networkid'] = $res2['networkid'];
  311. $data['created'] = date('Y-m-d H:i:s',time());
  312. // 新增维修调度
  313. $id = $this->Repair_model->insertDispatch($data);
  314. // $this->Lamp_model->update(array('id'=>$res1['lampid']),array('isfaulted'=>0));
  315. // $this->Alarm_model->update(array('id'=>$alarmid),array('status'=>1));
  316. exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
  317. }
  318. // 编辑/添加维修信息
  319. public function save_repair_info(){
  320. $role = $this->get_user_info('role');
  321. // if ($role == COMPANY_CUSTOMER) {
  322. // exit(json_result('0011',$this->response['0011'],array()));
  323. // }
  324. $where['id'] = $this->input->post('id',true);
  325. $data['repair_userid'] = $this->input->post('repair_id',true); // 维系人员id
  326. $repair_hitch = $this->input->post('repair_hitch',true); // 故障信息
  327. $repair_path = $this->input->post('address',true); // 维修地址
  328. $data['projectid'] = $this->input->post('projectid',true); // 项目id
  329. $data['networkid'] = $this->input->post('networkid',true); // 网络id
  330. $repair_time = $this->input->post('repair_time',true); // 维修方案时间
  331. $repair_solution = $this->input->post('repair_solution',true); // 维修方案
  332. $data['lampid'] = $this->input->post('lampid',true); // 路灯id
  333. if(!empty($repair_hitch)) $data['repair_hitch'] = $repair_hitch;
  334. if(!empty($repair_path)) $data['repair_path'] = $repair_path;
  335. if(!empty($repair_time)) $data['repair_time'] = $repair_time;
  336. if(!empty($repair_solution)) $data['repair_solution'] = $repair_solution;
  337. if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
  338. if(empty($data['projectid'])) exit(json_result('0308',$this->response['0308'],array()));
  339. if(empty($data['networkid'])) exit(json_result('0405',$this->response['0405'],array()));
  340. if(empty($data['lampid'])) exit(json_result('0802',$this->response['0802'],array()));
  341. if (empty($where['id'])) { // 添加维修记录
  342. $data['created'] = date('Y-m-d H:i:s');
  343. $id = $this->Repair_model->insert($data);
  344. // 修改维修人员维修数量
  345. $this->Repair_model->add_repaircount($data['repair_userid']);
  346. }else{ // 编辑维修记录
  347. $this->Repair_model->update($where,$data);
  348. $res = $this->Repair_model->getOne($where['id'],'repair_userid');
  349. // 修改维修人员维修数量
  350. if ($res['repair_userid'] != $data['repair_userid']) {
  351. $this->Repair_model->add_repaircount($data['repair_userid']);
  352. $this->Repair_model->minus_repaircount($res['repair_userid']);
  353. }
  354. $id = $where['id'];
  355. }
  356. exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
  357. }
  358. // 维修信息
  359. public function repair_info(){
  360. $repairid = $this->input->post('repairid');
  361. if (empty($repairid)) {
  362. exit(json_result('0007',$this->response['0007'],array()));
  363. }
  364. $field = 'id,lampid,networkid,projectid,repair_hitch,repair_path as address,repair_solution,repair_time,repair_userid as repair_id';
  365. $repair_info = $this->Repair_model->getOne($repairid,$field);
  366. exit(json_result('0000',$this->response['0000'],$repair_info));
  367. }
  368. }
  369. ?>