123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/Base_Controller.php');
- /**
- *
- */
- class Repair extends Base_Controller
- {
-
- public function __construct()
- {
- parent::__construct();
- $this->load->model('Repair_model');
- $this->load->model('User_model');
- $this->load->model('Alarm_model');
- $this->load->model('Lamp_model');
- }
- // 维修记录列表
- public function repair_list(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- $companyid = $this->get_user_info('companyid');
- $projectid = $this->input->post('projectid',true);
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 16 : $count;
- // 设置需要获取的字段
- $field = "P.projectname as project_name,
- N.networkname as network_name,
- L.number as lampid,
- R.repair_path,
- RU.id as userid,
- RU.name as name,
- R.repair_hitch,
- R.repair_solution,
- R.repair_time,
- R.id";
- $keyword = $this->input->post('keyword',true);
- // 获取维修列表数据
- $data = $this->Repair_model->get_list_by_role(array('keyword'=>$keyword),$role,$userid,$companyid,$projectid,$field,$page,$count);
- // 获取维修总数
- $total = $this->Repair_model->get_total_by_role(array('keyword'=>$keyword),$role,$userid,$companyid,$projectid);
- // 设置分页
- json_result('0000',$this->response['0000'],array('total'=>ceil($total/$count),'list'=>$data));
- }
- // 近期维修列表
- public function near_repair_list(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- $companyid = $this->get_user_info('companyid');
- // 设置需要获取的字段
- $field = "P.projectname as project_name,
- R.lampid,
- R.id,
- RU.name as repair_username,
- R.repair_hitch,
- R.repair_solution,
- R.created as createtime";
- // 获取维修列表数据
- $data = $this->Repair_model->get_list_by_role(array(),$role,$userid,$companyid,0,$field,1,10);
- // 获取维修人员总数
- $total = $this->Repair_model->get_repair_user_total(array('id'=>$userid,'role'=>$role));
- exit(json_result('0000',$this->response['0000'],array('repair_list'=>$data,'total'=>$total)));
- }
- // 维修人员列表
- public function repair_user_list(){
- $tag = $this->input->post('tag',true);
- $keyword = $this->input->post('keyword',true);
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $version = $this->session->userdata('version');;
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 16 : $count;
- $filter = array();
- if (!empty($tag)) {
- $filter['tag'] = strtoupper($tag);
- }
- if (!empty($keyword)) {
- $filter['keyword'] = $keyword;
- }
- $filter['user_id'] = $this->get_user_info('id');
- $data = $this->User_model->get_repair_user_list($filter,$this->userinfo,$page,$count);
- $total = $this->User_model->get_repair_user_count($filter,$this->userinfo);
- foreach ($data as &$v) {
- if (empty($v['repair_path'])) {
- if (empty($version)) {
- $v['repair_path'] = '暂无近期维修信息';
- }else{
- $v['repair_path'] = 'No recent maintenance information is available';
- }
- }
- }
- exit(json_result('0000',$this->response['0000'],array('list'=>$data,'total'=>ceil($total/$count))));
- }
- // 维修人员下拉列表
- public function user_list(){
- $filter['user_id'] = $this->get_user_info('id');
- $data = $this->User_model->get_repair_user_list($filter,$this->userinfo,0,0,1);
- exit(json_result('0000',$this->response['0000'],array('list'=>$data)));
- }
- // 维修人员详情
- public function user_info(){
-
- $userid = $this->input->post('userid',true);
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 10 : $count;
- if (empty($userid)) {
- exit(json_result('0007', $this->response['0007'], array()));
- }
- $field = 'id as userid,name,number as repair_id,owner_id,department,telephone as phone,email';
- $user_info = $this->User_model->get_one_repair_user($userid,$field);
- if (empty($user_info)) {
- exit(json_result('0601', $this->response['0601'], array()));
- }else{
- $res = $this->User_model->getOne($user_info['owner_id'],'username');
- $user_info['owner'] = $res['username'];
- // 获取维修信息列表
- $data = $this->Repair_model->getlist(array('userid'=>$userid),$page,$count);
- $user_info['repair_list']=$data;
- $total = $this->Repair_model->gettotal(array('userid'=>$userid));
- $user_info['total'] = ceil($total/$count);
- exit(json_result('0000', $this->response['0000'],$user_info));
- }
- }
- // 维修人
- public function repair_user(){
- $alarmid = $this->input->post('alarmid',true);
- if (empty($alarmid)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 1 : $count;
- $alarmData = $this->Alarm_model->getOne($alarmid,'A.lampid,A.alarmtype');
- $data = $this->Repair_model->get_list_by_filter(array('lampid'=>$alarmData['lampid']),'repair_userid');
- $userid = array_unique(array_column($data, 'repair_userid'));
- $userList = $this->Repair_model->get_repair_user_by_filter(array('id'=>$userid,'page'=>$page,'count'=>$count));
- if (empty($userList)) {
- exit(json_result('0616',$this->response['0616'],array()));
- }
- // $user_info = $this->User_model->get_one_repair_user($userid);
- exit(json_result('0000',$this->response['0000'],array('list'=>$userList,'total'=>ceil(count($userid)/$count))));
- }
- // 编辑/添加维修人员
- public function save_repair_user(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011', $this->response['0011'], array()));
- // }
- $repair_userid = $this->input->post('userid',true);
- // 获取维修人员信息
- $data['number'] = intval($this->input->post('repair_id',true)); // 维修人员id
- $data['name'] = $this->input->post('name',true); // 维修人员名称
- $data['department'] = $this->input->post('department',true); // 部门
- $phone = $this->input->post('phone',true); // 手机
- $email = $this->input->post('email',true); // 邮箱
- if(empty($data['number']) || $data['number'] < 0 || $data['number'] > 999999) exit(json_result('0617',$this->response['0617'],array()));
- if(!isset($data['name'])) exit(json_result('0606',$this->response['0606'],array()));
- if(!isset($phone) || empty($phone)) exit(json_result('0607',$this->response['0607'],array()));
- $config = array();
- if(!empty($phone)){
- $config[] = array(
- 'field' => 'phone',
- 'label' => 'Phone',
- 'rules' => 'numeric|exact_length[11]',
- 'errors' => array(
- 'numeric' => '0718',
- 'exact_length' => '0718'
- )
- );
- $data['telephone'] = $phone;
- }
- if (!empty($email)) {
- $config[] = array(
- 'field' => 'email',
- 'label' => 'Email',
- 'rules' => 'valid_email',
- 'errors' => array(
- 'valid_email' => '0719',
- )
- );
- $data['email'] = $email;
- }
- if (!empty($config)) {
- $this->load->library('form_validation');
- $this->form_validation->set_rules($config);
- if ($this->form_validation->run() == FALSE){
- $errors = $this->form_validation->error_array();
- exit(json_result(current($errors),$this->response[current($errors)],array()));
- }
- }
- $data['tag'] = get_first_char($data['name']);
- if (empty($repair_userid)) { // 添加维修人员信息
- // 检查维修员工id是否已经存在
- // $res = $this->Repair_model->get_repair_user_id(array('number'=>$data['number']));
- if($this->Repair_model->get_repair_user_id(array('name'=>$data['name'],'telephone'=>$data['telephone']))){
- exit(json_result('0602',$this->response['0602'],array()));
- }
- $data['owner_id'] = $this->get_user_info('id');
- $userid = $this->User_model->add_repair_user($data);
- $this->add_operation_log('insert',"添加\"{$data['name']}\"维修人员",0);
- $this->add_operation_log('insert',"Add repair personnel.Name:\"{$data['name']}\"",0,1);
- }else{ // 编辑维修人员信息
- // 检查维修员工id是否已经存在
- if($this->Repair_model->get_repair_user_id(array('name'=>$data['name'],'telephone'=>$data['telephone']),$repair_userid)){
- exit(json_result('0602',$this->response['0602'],array()));
- }
- $this->User_model->update_repair_user($repair_userid,$data);
- $userid = $repair_userid;
- $this->add_operation_log('update',"修改\"{$data['name']}\"维修人员",0);
- $this->add_operation_log('update',"Update repair personnel.Name:\"{$data['name']}\"",0,1);
- }
- exit(json_result('0000',$this->response['0000'],array('userid'=>$userid)));
- }
- // 删除维修人员
- public function del_repair_user(){
- $userid = $this->input->post('userid',true);
- $role = $this->get_user_info('role');
- // 检查用户权限
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011',$this->response['0011'],array()));
- // }
- // 参数有误
- if (empty($userid)) {
- exit(json_result('0608',$this->response['0608'],array()));
- }
- $user_info = $this->User_model->get_one_repair_user($userid,'name');
- $this->add_operation_log('delete',"删除\"{$user_info['name']}\"维修人员",0);
- $this->add_operation_log('delete',"Delete repair personnel.Name:\"{$user_info['name']}\"",0,1);
- $this->User_model->delete_repair_user($userid);
-
- exit(json_result('0000',$this->response['0000'],array()));
- }
- // 删除维修记录
- public function del_repair_info(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011', $this->response['0011'], array()));
- // }
- $id = $this->input->post('id',true);
- if (empty($id)) {
- exit(json_result('0609',$this->response['0609'],array()));
- }
- $idsArr = explode(',', $id);
- foreach ($idsArr as $v) {
- $repairData = $this->Repair_model->getOne($v,'repair_userid');
- $this->Repair_model->minus_repaircount($repairData['repair_userid']);
- $this->Repair_model->delOne($v);
- $this->add_operation_log('delete','删除维修记录 id:'.$v,0);
- $this->add_operation_log('delete','Delete maintenance record.ID:'.$v,0,1);
- }
-
- exit(json_result('0000',$this->response['0000'],array()));
- }
- // 添加/修改维修调度信息
- public function update_dispatch(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011',$this->response['0011'],array()));
- // }
- $where['id'] = $this->input->post('id',true);
- $data['repair_userid'] = $this->input->post('repair_id',true); // 维修人员id
- $data['repair_path'] = $this->input->post('address',true); // 维修路段
- $data['projectid'] = $this->input->post('projectid',true); // 项目id
- $data['networkid'] = $this->input->post('networkid',true); // 网络id
- $data['starttime'] = $this->input->post('starttime',true); // 开始时间
- $data['plantime'] = $this->input->post('plantime',true); // 计划完成时间
- $finishtime = $this->input->post('finishtime',true); // 实际完成时间
- if(!empty($finishtime)) $data['finishtime'] = $finishtime;
- if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
- if(empty($data['projectid'])) exit(json_result('0308',$this->response['0308'],array()));
- if(empty($data['networkid'])) exit(json_result('0405',$this->response['0405'],array()));
- if(empty($data['plantime'])) exit(json_result('0611',$this->response['0611'],array()));
- if(empty($data['starttime'])) exit(json_result('0612',$this->response['0612'],array()));
- if (empty($where['id'])) { // 添加调度信息
-
- $id = $this->Repair_model->insertDispatch($data);
- $this->add_operation_log('insert','添加调度信息 id:'.$id,0);
- $this->add_operation_log('insert','Add scheduling information.ID:'.$id,0,1);
- }else{ // 编辑调度信息
- $this->Repair_model->updateDispatch($where,$data);
- $this->add_operation_log('update','修改调度信息 id:'.$where['id'],0);
- $this->add_operation_log('update','Update scheduling information.ID:'.$where['id'],0,1);
- $id = $where['id'];
- }
- exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
- }
- // 维修调度
- public function repair_dispatch(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011',$this->response['0011'],array()));
- // }
- $alarmid = $this->input->post('alarmid',true);
- $data['repair_userid'] = $this->input->post('userid',true);
- if(empty($alarmid)) exit(json_result('0613',$this->response['0613'],array()));
- if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
- // 获取维修调度信息
- $res1 = $this->Alarm_model->getOne($alarmid,'A.lampid');
- // $data['alarmid'] = $alarmid;
- $data['lampid'] = $res1['lampid'];
- // 判断调度时间是否过期
- // $repairData = $this->Repair_model->getDispatchData(array('lampid'=>$data['lampid']),'created');
- // if (!empty($repairData['created'])) {
- // if (time() <= strtotime($repairData['created'])+30*60) {
- // exit(json_result('0615',$this->response['0615'],array()));
- // }
- // }
- $res2 = $this->Lamp_model->getOne($data['lampid'],'L.projectid as projectid,L.networkid as networkid,N.section');
- $data['address'] = $res2['section'];
- $data['projectid'] = $res2['projectid'];
- $data['networkid'] = $res2['networkid'];
- $data['created'] = date('Y-m-d H:i:s',time());
- // 新增维修调度
- $id = $this->Repair_model->insertDispatch($data);
- // $this->Lamp_model->update(array('id'=>$res1['lampid']),array('isfaulted'=>0));
- // $this->Alarm_model->update(array('id'=>$alarmid),array('status'=>1));
- exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
- }
- // 编辑/添加维修信息
- public function save_repair_info(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011',$this->response['0011'],array()));
- // }
- $where['id'] = $this->input->post('id',true);
- $data['repair_userid'] = $this->input->post('repair_id',true); // 维系人员id
- $repair_hitch = $this->input->post('repair_hitch',true); // 故障信息
- $repair_path = $this->input->post('address',true); // 维修地址
- $data['projectid'] = $this->input->post('projectid',true); // 项目id
- $data['networkid'] = $this->input->post('networkid',true); // 网络id
- $repair_time = $this->input->post('repair_time',true); // 维修方案时间
- $repair_solution = $this->input->post('repair_solution',true); // 维修方案
- $data['lampid'] = $this->input->post('lampid',true); // 路灯id
- if(!empty($repair_hitch)) $data['repair_hitch'] = $repair_hitch;
- if(!empty($repair_path)) $data['repair_path'] = $repair_path;
- if(!empty($repair_time)) $data['repair_time'] = $repair_time;
- if(!empty($repair_solution)) $data['repair_solution'] = $repair_solution;
- if(empty($data['repair_userid'])) exit(json_result('0610',$this->response['0610'],array()));
- if(empty($data['projectid'])) exit(json_result('0308',$this->response['0308'],array()));
- if(empty($data['networkid'])) exit(json_result('0405',$this->response['0405'],array()));
- if(empty($data['lampid'])) exit(json_result('0802',$this->response['0802'],array()));
- if (empty($where['id'])) { // 添加维修记录
- $data['created'] = date('Y-m-d H:i:s');
- $id = $this->Repair_model->insert($data);
- // 修改维修人员维修数量
- $this->Repair_model->add_repaircount($data['repair_userid']);
- }else{ // 编辑维修记录
- $this->Repair_model->update($where,$data);
- $res = $this->Repair_model->getOne($where['id'],'repair_userid');
- // 修改维修人员维修数量
- if ($res['repair_userid'] != $data['repair_userid']) {
- $this->Repair_model->add_repaircount($data['repair_userid']);
- $this->Repair_model->minus_repaircount($res['repair_userid']);
- }
- $id = $where['id'];
- }
- exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
- }
- // 维修信息
- public function repair_info(){
- $repairid = $this->input->post('repairid');
- if (empty($repairid)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- $field = 'id,lampid,networkid,projectid,repair_hitch,repair_path as address,repair_solution,repair_time,repair_userid as repair_id';
- $repair_info = $this->Repair_model->getOne($repairid,$field);
- exit(json_result('0000',$this->response['0000'],$repair_info));
- }
- }
- ?>
|