Repair.php 17 KB

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