标签:
<?php if (!defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘); require_once ‘base.php‘; //建立自己的程序库,假如没有包含的话,显示错误:没有直接的脚本访问 //require_once 与require 的区别就是假如已经有了需要引入的文件,require_once就不引入了,没有就因引入。而require 是始终都引入 class F extends Base { var $userid = Null; var $appUrl; function __construct() { parent::__construct(); $this->appUrl = ‘http://‘.$_SERVER[‘HTTP_HOST‘]; //读取网站指定的域名 # Check session $code = $this->input->get(‘code‘);//get是输入类的函数,用来读取code $this->load->model(‘User_model‘); if ($this->User_model->is_login()){ log_message(‘info‘, "session:".$this->User_model->userdata(‘id‘));//log_message是用来打印log 信息,这里的作用是输出session 的信息 $this->userid = $this->User_model->userdata(‘id‘);//从User的数据模型中根据id读取出用户的信息并用 $this->userid 来存储起来 }else if ($code) { $this->userid = $this->User_model->login($code); } $this->userinfo = $this->User_model->info(); } public function application($action)//判断action的动作:是add,是edit,还是del? { log_message(‘info‘,‘application: ‘.$action);//用log中info 的方式来输出当前的action try { $method = "_application_".$action; $this->$method(); } catch (Exception $e) { } } private function _application_overtime() { $this->set_html_title("加班单", True); //设置页面的标题 $this->set_body(‘f/application_overtime‘);//设置页面的view视图 body部分 $this->html(‘f/base‘);//设置输出母版页 } private function _application_leave() { $this->set_html_title("请假条", True); $this->set_body(‘f/application_leave‘); $this->html(‘f/base‘); } /** * 员工列表 */ public function _application_user_list(){ $output = new ApiOut(); //new 一个输出函数,里面是用json格式来输出,包含网页的状态码和data数据 try { //当前人员所在的部门 /*$user = $this->User_model->get(array(‘userid‘=>$this->userid)); echo $user[0]->department;*/ //人员列表 $userlist = $this->User_model->get_list();//得到所有人员的列表 $output->data = $userlist;//输出数据 } catch (Exception $e) { $output->msg = $e->getMessage();//假如有错误的话,输出捕获到的错误信息 $output->status = $e->getCode();//还有错误的网页状态码 } $output->json(); } /** * 部门列表 * */ public function _application_department(){ $output = new ApiOut(); try { //部门列表 $this->load->model(‘Department_model‘);//加载部门的数据模型 $data = $this->Department_model->get_list();//输出部门列表 /*foreach($data as $key =>$val){ $departmentr[$val->id]=$val; }*/ $output->data = $data; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 处理用户浏览的个人信息相关页面 * @param [type] $action [description] * @return [type] [description] */ public function employee($action) { # code... try { $method = "_employee_".$action;//处理用户浏览的个人信息相关页面 $this->$method(); } catch (Exception $e) { } } /** * 请假申请 * @param type $action * */ public function leave($action) { $this->load->model(‘Leaveapply_model‘); if ($action) { $method_name = "_".__FUNCTION__."_".$action; if ((method_exists($this, $method_name))) {//method_exists函数是的参数是一个对象和一个方法名,假如给定方法在对象的类中存在,则返回true call_user_func(array($this, $method_name));//返回一个自定义用户函数给出的第一个参数 } } } /** * 员工请假申请 * * @param $post * @return [result] */ public function _leave_apply(){ $output = new ApiOut(); try { $postdata = $this->input->post(); //得到post传过来的数据 if (empty($postdata)) { //假如post传过来的数据为空的话,报错 throw new Exception("哦,出错了,抱歉申请失败...", 400); } $postdata[‘uid‘]=$this->userid; //读取传过来的userid $this->load->model(‘Leaveapply_model‘); //加载请假的数据模型 $insertdata = array( //重新建立一个符合要求的数组 ‘userid‘=>trim($postdata[‘uid‘]), //把存过来的uid 中首尾的空格去掉 ‘start_time‘=>date(‘Y-m-d H:i:s‘,strtotime($postdata[‘start_datetime‘])),//按照 Y-m-d H:i:s的格式把传过来的时间格式处理一下,strtotime 是时间戳函数,用来把日期变成时间戳 ‘end_time‘=>date(‘Y-m-d H:i:s‘,strtotime($postdata[‘end_datetime‘])), ‘approve_uid‘=>$postdata[‘approve_uid‘], ‘event_type‘=>$postdata[‘event_type‘], ‘description‘=>$postdata[‘description‘] ); $this->Leaveapply_model->insert($insertdata);//插入数据到leaveapply 数据模型中 //这是审批人的用户名 $approvalname=$this->User_model->get($postdata[‘uid‘])[0]->name; //获取审批人的名字 //执行发送消息 $content = $approvalname.‘申请‘.$postdata[‘event_type‘].‘等待您的审批‘; //原来是$postdata[‘uid‘] //执行发送消息,先用对象把消息封装起来 $link = $this->appUrl."/f/leave/approve"; //封装输出的url $msg = array( ‘touser‘=>$postdata[‘approve_uid‘],//touser指的是指定的用户 ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content.$this->link_wrapper($link)//把输出的url封装成符合微信要求的url ) ); $ret = $this->User_model->send_msg($msg); } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 员工请假申请历史记录查询 */ public function _leave_list(){ $output = new ApiOut(); try { if (empty(trim($this->userid))) {//先判断当前用户的信息,假如没有的话,没有必要执行下面的操作 throw new Exception("未发现当前所属员工id", 400); } $status = array( //用一维数组的方法把几个状态封装起来 ‘0‘=>‘已作废‘, ‘1‘=>‘正在审核‘, ‘2‘=>‘通过‘, ‘3‘=>‘未通过‘, ‘‘=>‘‘ ); $this->load->model(‘Leaveapply_model‘); $listdata = $this->Leaveapply_model->get(array(‘userid‘=>$this->userid)); //根据userid来得到需要的信息 if($listdata[0]!=‘‘){ //假如返回的信息不为空,就重新把数据变成自己想要的键值对的方式 foreach($listdata as $key =>$val){ $result[$key] = array( ‘start_time‘=>$val->start_time, ‘end_time‘=>$val->end_time, ‘countdays‘=>floor((strtotime($val->end_time) - strtotime($val->start_time))/864)/100, ‘status‘=>$status[$val->status] ); } $output->data = $result; }else{ $output->status = 200; } } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 员工请假审批 * */ public function _leave_approve(){ $this->set_html_title("审批", True); $this->set_body(‘f/application_approve‘); $this->html(‘f/base‘); } /** * 微信 修改绑定后台后的信息 * */ public function bindedit(){ $uid = $this->input->post(‘id‘); $output=new ApiOut(); try{ $this->load->model(‘User_model‘); /*if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } */ $postdata = $this->input->post(); $user_data = array( ‘userid‘=>$this->userid, //注意 ‘user‘=>$postdata[‘user‘], ‘pass‘=>$postdata[‘pass‘], ‘nickname‘=>$this->userid, ‘role‘=>$postdata[‘role‘], ); if (0 === intval($uid)) { //返回变量的整数值,可以理解为数据类型强制转换 $user_data[‘created‘] = date(‘Y-m-d H:i:s‘); $this->load->model(‘Admin_model‘); //$id = $this->Admin_model->create($user_data); $id = $this->Admin_model->update($user_data, array(‘userid‘=>$this->userid));//update的方式,第一个是对应的字段名,第二个是要修改的参数 if ($id === False){ throw new Exception("修改用户失败", 500); }else{ $user_data[‘id‘] = $id; } }else{ $this->Admin_model->update($user_data, array(‘id‘=>$uid)); $user_data[‘id‘] = $uid; } $output->data =& $user_data; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 微信 绑定后台 * */ public function bindadd(){ $uid = $this->input->post(‘id‘); $output=new ApiOut(); try{ $this->load->model(‘User_model‘); /*if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } */ $postdata = $this->input->post(); $user_data = array( ‘userid‘=>$this->userid, //注意 ‘user‘=>$postdata[‘user‘], ‘pass‘=>$postdata[‘pass‘], ‘nickname‘=>$this->userid, ‘role‘=>$postdata[‘role‘], ); if (0 === intval($uid)) { $user_data[‘created‘] = date(‘Y-m-d H:i:s‘); $this->load->model(‘Admin_model‘); $id = $this->Admin_model->create($user_data); //当用户绑定之后,同时向后台发送一条消息。把后台的权限改为一 $this->db->query("INSERT INTO `db_oa`.`qx` (`userid`, `houtai`) VALUES ( ‘$this->userid‘,‘1‘)"); // 上面是新增的 if ($id === False){ throw new Exception("创建用户失败", 500); }else{ $user_data[‘id‘] = $id; } }else{ $this->Admin_model->update($user_data, array(‘id‘=>$uid)); $user_data[‘id‘] = $uid; } $output->data =& $user_data; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 微信前台 绑定后台 * @param type $action * */ public function bind($action=‘‘) { $this->load->model(‘Admin_model‘); $userdata=$this->Admin_model->get(array(‘userid‘=> $this->userid));//从数据库查到的id if($userdata!=null){ //有数据,说明之前已经绑定过了后台,就进入修改或者重置密码的界面。 //log_message(‘info‘,‘进入了bind里面的第二个功能‘); $this->set_html_title("修改绑定后台的用户信息",true); $this->set_body(‘f/bindedit‘); $this->html(‘f/base‘); }else{ //第一次的时候,会进入绑定后台的页面 $this->set_html_title("绑定后台",true); $this->set_body(‘f/bind‘); $this->html(‘f/base‘); } } /* * 功能:获得当前要修改绑定id的用户名 * * */ public function bindgetname(){ $userid = $this->userid; $output=new ApiOut(); try{ $this->load->model(‘User_model‘); // $result= $this->db->query("SELECT `user` FROM `admin_user` WHERE `userid` = ‘$userid‘")->result_array(); $result = $this->db->get_where("admin_user",array(‘userid‘=>$userid))->result_array();//result_array()执行成功的时候返回的是记录集当作关联数组返回,失败是返回空数组 //var_dump($result[0]); $output->data =$result[0]; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /* * 读取所有的已经存在的user * */ public function bindgetalluser(){ $output=new ApiOut(); try{ $result = $this->db->get_where("admin_user")->result_array();//result_array()把结果集当关联数组来返回 //var_dump($result[0]); foreach ($result as $key => $value) { $newarray[$key]=$value[‘user‘]; } $output->data =$newarray; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 列出与当前用户审批有关的申请 * */ public function _leave_approve_list(){ $output = new ApiOut(); try { if (empty(trim($this->userid))) { throw new Exception("未发现当前所属员工id", 400); } $status = array( ‘0‘=>‘已作废‘, ‘1‘=>‘正在审核‘, ‘2‘=>‘通过‘, ‘3‘=>‘未通过‘, ‘‘=>‘‘ ); $this->load->model(‘Leaveapply_model‘); $this->load->model(‘User_model‘); $listdata = $this->Leaveapply_model->get(array(‘approve_uid‘=>$this->userid)); if($listdata[0]!=‘‘){ foreach($listdata as $key =>$val){ if($val->status == ‘1‘){ //ing 代表的是等待审批 $result[‘ing‘][$key] = array( ‘id‘=>$val->id, ‘userid‘=>$val->userid, ‘username‘=>$this->User_model->get($val->userid)[0]->name, //注意:这是新增的 ‘start_time‘=>$val->start_time, ‘end_time‘=>$val->end_time, ‘countdays‘=>floor((strtotime($val->end_time) - strtotime($val->start_time))/864)/100, ‘event_type‘=>$val->event_type, ‘description‘=>$val->description, ‘approve_description‘=>$val->approve_description ); }else{ //history 代表的是审批历史 $result[‘history‘][$key] = array( ‘userid‘=>$val->userid, ‘start_time‘=>$val->start_time, ‘username‘=>$this->User_model->get($val->userid)[0]->name, ‘end_time‘=>$val->end_time, ‘countdays‘=>floor((strtotime($val->end_time) - strtotime($val->start_time))/864)/100, ‘status‘=>$status[$val->status], ‘event_type‘=>$val->event_type, ‘approve_description‘=>$val->approve_description ); } } $output->data = $result; }else{ $output->status = 200; } } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 执行请假审批操作 * */ public function _leave_approve_apply(){ $output = new ApiOut(); try { $postdata = $this->input->post(); if (empty($postdata)) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } if ($postdata[‘type‘] == ‘y‘){ //判断传过来的种类,假如是y是批准 $jieguo=‘批准‘; $postdata[‘status‘] = ‘2‘; }else{ $jieguo=‘未批准‘; $postdata[‘status‘] = ‘3‘; } $this->load->model(‘Leaveapply_model‘); $this->Leaveapply_model->update(array(‘approve_time‘ => date(‘Y-m-d H:i:s‘, time()), ‘approve_uid‘ => $this->userid, ‘approve_description‘ => $postdata[‘approve_description‘], ‘status‘ => $postdata[‘status‘]), array(‘id‘ => intval($postdata[‘id‘]))); $msg = array( ‘touser‘=>$postdata[‘userid‘], //touser是指定接收人的id ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>‘您的‘.$postdata[‘event_type‘].‘申请得到审批,审批结果是:[‘.$jieguo.‘];‘.$postdata[‘approve_description‘] ) ); $ret = $this->User_model->send_msg($msg); } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 列出员工打卡历史 * @return [type] [description] */ private function _employee_logs() { $this->set_html_title("打卡历史纪录", True); $this->load->model(‘Employeelog_model‘); $where = array(‘userid‘=>$this->userid); $data = $this->Employeelog_model->get($where); $this->set_body(‘f/employee_logs‘, $data); $this->html(‘f/base‘); } /** * 通讯录 * @return [type] [description] */ public function contacts(){ $this->set_body(‘f/contacts‘); $this->html(‘f/base‘); } /** * 通讯录常用联系人处理 * */ public function _application_contacts_common(){ $output = new ApiOut(); try { $postdata = $this->input->post(); if (empty($postdata)) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } if($postdata[‘type‘]==‘y‘) $this->User_model->set_fav_contacts($postdata[‘userid‘]); else $this->User_model->del_fav_contact($postdata[‘userid‘]); } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 通讯录常用联系人 * */ public function _application_contacts_commonlist(){ $output = new ApiOut(); try { $data = $this->User_model->get_fav_contacts(); $userlist = $this->User_model->get_list(); foreach($userlist as $ukey =>$uval){ $userdata[$uval->userid]=$uval; } foreach($data as $key =>$val){ $listdata[] = $userdata[$val]; } $output->data = $listdata; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 待办事项 * @return [type] [description] */ public function todo($action=null) { if ($this->User_model->is_login() == False) { # TODO: 提示授权失败,重新进入应用。 } $data = array(); $data[‘user‘] = $this->User_model->info(); $this->set_html_title(sprintf("%s的待办事项", $data[‘user‘][‘name‘]), True); $this->set_body(‘f/todo_list‘, $data); $this->html(‘f/base‘); } /** * 获取 todo list * 输出 JSON 格式内容 */ public function todos($action="") { $this->load->model(‘Todo_model‘); $this->load->model(‘User_model‘); if ($action) { $method_name = "_".__FUNCTION__."_".$action; if ((method_exists($this, $method_name))) { call_user_func(array($this, $method_name)); } } $output = new ApiOut(); try { if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } # 只显示当前用户自己的todo 内容 //$result = $this->Todo_model->get(array(‘userid‘=>$this->userid)); //显示和当前用户相关的内容 $result = $this->db->query("select * from todo_list where `userid` = ‘$this->userid‘ or `assignment_userid` = ‘$this->userid‘ order by `id` desc")->result_array(); /*foreach ($result as $row) { $row->completed = $row->completed == 1; } */ foreach ($result as $key => $val) { $newresult[$key]=array( ‘id‘=>$val[‘id‘], ‘userid‘=>$val[‘userid‘], ‘username‘=>$this->User_model->get($val[‘userid‘])[0]->name, ‘description‘=>$val[‘description‘], ‘assignment_userid‘=>$val[‘assignment_userid‘], ‘assignment_username‘=>$this->User_model->get($val[‘assignment_userid‘])[0]->name, ‘priority‘=>$val[‘priority‘], ‘due_date‘=>$val[‘due_date‘], ‘update_at‘=>$val[‘update_at‘], ); } $output->data = $newresult; $output->userid = $this->userid; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 创建新的todo * 输出 JSON 格式内容 */ private function _todos_create() { $output = new ApiOut(); try { if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } $postdata = $this->input->post(); if (empty(trim($postdata[‘description‘]))) { throw new Exception("请先输入待办事项的内容", 400); } $insertdata = array( ‘userid‘=>$this->userid, ‘description‘=>$postdata[‘description‘], ‘created‘=>date(‘Y-m-d H:i:s‘), ‘assignment_userid‘=>$postdata[‘assignment_userid‘], ‘due_date‘=>date(‘Y-m-d H:i:s‘,strtotime($postdata[‘due_date‘])), ‘priority‘=>$postdata[‘priority‘], ‘remind‘=>$postdata[‘remind‘] ); $this->Todo_model->insert($insertdata); //这是审批人的用户名 $approvalname=$this->User_model->get($this->userid)[0]->name; //有选择发送的则进行发送提醒 if($postdata[‘issend‘]!=‘‘&&$postdata[‘issend‘]==‘true‘){ $content = $approvalname.‘给您分配了任务,请查看‘; //原来是$this->userid $link = $this->appUrl."/f/task"; $msg = array( ‘touser‘=>$postdata[‘assignment_userid‘], ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content.$this->link_wrapper($link) ) ); $ret = $this->User_model->send_msg($msg); } // # TODO: 只显示当前用户自己的todo 内容 $output->data = $this->Todo_model->get(array(‘userid‘=>$this->userid)); } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 修改 todo * 适用于修改完成状态 */ private function _todos_completed() { $output = new ApiOut(); try { if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } $completed = $this->input->post(‘completed‘); $completed = $completed==‘true‘; $id = $this->input->post(‘id‘); # 只能修改自己的内容 $this->Todo_model->update(array(‘completed‘=>$completed), array(‘id‘=>$id, ‘userid‘=>$this->userid)); } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /* * 任务管理 * * @desc 指派任务,查看任务 * */ public function task($action=‘‘){ if ($action) { $method_name = "_".__FUNCTION__."_".$action; if ((method_exists($this, $method_name))) { call_user_func(array($this, $method_name)); } }else{ $this->set_html_title("任务管理", True); $this->set_body(‘f/task‘); $this->html(‘f/base‘); } } /** * 任务列表 * * @desc 所有任务 */ public function _task_list(){ $output = new ApiOut(); try { $data = array(); $data[‘user‘] = $this->User_model->info(); $output->data = $data; }catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 事务处理(自定义流程) * */ public function apply($action=""){ if ($action) { $method_name = "_".__FUNCTION__."_".$action; //__FUNCTION__ 是一个魔术常量,返回函数名称,__METHOD__ 是返回类的方法名 $this->load->model(‘Approval_model‘); if ((method_exists($this, $method_name))) { call_user_func(array($this, $method_name)); } }else{ $this->set_html_title("事务申请", True); $this->set_body(‘f/apply‘); $this->html(‘f/base‘); } } /** * 读取流程内容 * */ public function _apply_inf(){ $output = new ApiOut(); try { $getData = $this->input->get(); if(!empty($getData)){ $data = $this->Approval_model->get(array(‘id‘=>$getData[‘id‘],‘act‘=>‘1‘)); $datas = $data[0]; }else{ $datas = $this->Approval_model->get(array(‘act‘=>‘1‘)); } $output->data = $datas; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 读取事务申请列表 * 根据用户id读取用户申请的历史列表 * */ public function _apply_list(){ $uid = $this->userid; $output = new ApiOut(); try { $this->load->model("Affairs_base_value");//固定数据 $this->load->model("Affairs_form_value");//自定义数据 $data_form = $this->Affairs_form_value->get(); $data_base = $this->Affairs_base_value->get(); $data = ‘‘; $output->data = $data; } catch (Exception $ex) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 执行事务申请提交 * @desc 同时操作两个数据表,一个是固定存储表,一个是自定义流程存储表 * @author weixing */ public function _apply_do(){ $uid = $this->userid; $userdata = $this->userinfo; $output = new ApiOut(); try { $postdata = $this->input->post(); if (empty($postdata)) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } /*$data = $this->Approval_model->get(array(‘id‘=>$postdata[‘affairsid‘][‘id‘])); $output->data = $data[0]->approve_userid;*/ $base = array( ‘form_id‘=>$postdata[‘affairsid‘][‘id‘], ‘apply_userid‘=>$uid, ‘apply_bm‘=>$postdata[‘apply_bm‘], ‘apply_time‘=>date(‘Y-m-d H:i:s‘,time()), ‘apply_reason‘=> $postdata[‘apply_reason‘], ‘cc‘=>$postdata[‘cc‘][‘userid‘] ); $this->load->model("Affairs_base_value");//固定数据 $this->load->model("Affairs_form_value");//自定义数据 $baseid = $this->Affairs_base_value->insert($base); //自定义表单的数据处理 foreach($postdata[‘contents‘] as $key =>$val){ unset($form);//unset()函数是用来销毁变量,假如内存中已经有这个函数的话,不销毁的话,可能会导致下面程序的执行出错、 if(is_array($val[‘data‘])) $val[‘data‘] = $val[‘data‘][‘name‘]; //is_array函数是用来判断变量类型是否为数组类型 $form = array( ‘base_id‘=>$baseid, ‘sys_formid‘=>$postdata[‘affairsid‘][‘id‘], ‘sys_typename‘=>$val[‘type_name‘], ‘sys_name‘=>$val[‘name‘], ‘value‘=>$val[‘data‘], ‘applyid‘=>$uid ); $this->Affairs_form_value->insert($form); } //获取审核状态,读取下级审核人 //发送审核请求信息 if($approve_userid = $this->_apply_getuserid($postdata[‘affairsid‘][‘id‘],1)){ $content = $userdata[‘name‘].‘申请‘.$postdata[‘affairsid‘][‘name‘].‘等待您的审批‘; $link = $this->appUrl."/f/apply/approve"; $msg = array( ‘touser‘=>$approve_userid, ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content.$this->link_wrapper($link) ) ); $ret = $this->User_model->send_msg($msg); //执行数据库记录 $this->load->model("Affairs_approve_log"); $insertdata = array( ‘base_id‘=>$baseid, ‘approve_userid‘=>$approve_userid ); $this->Affairs_approve_log->insert($insertdata); } } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 获取需要发送的人的userid * @var $affairsid 流程id * @var $step 第几级审批 * @author weixing */ private function _apply_getuserid($affairsid,$step){ $data = $this->Approval_model->get(array(‘id‘=>$affairsid)); $approvedata = json_decode($data[0]->approve_userid); if(count($approvedata)< $step){ //count函数计算数组中的单元数目或对象中的属性个数 return false; }else{ $step = $step - 1; switch($approvedata[$step]->level){ case ‘1‘: //直接上级 //调用直接上级的userid $approve_userid = ‘‘; break; case ‘2‘: //间接上级 //调用间接上级的userid $approve_userid = ‘‘; break; case ‘3‘: //指定联系人 $approve_userid = $approvedata[$step]->approve_userid; break; default: //指定联系人 $approve_userid = ‘‘; break; } return $approve_userid; } } /** * 事务申请记录 * */ public function _apply_history(){ $uid = $this->userid; $this->load->model(‘Affairs_base_value‘); $this->load->model(‘Department_model‘); $output = new ApiOut(); try { if (empty($uid)) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } $this->load->model("Affairs_base_value");//固定数据 $data = $this->Affairs_base_value->get(array(‘apply_userid‘=>$uid)); //下面的是修改过的数据: foreach ($data as $key => $val) { //将得到的数据再根据需求重新组装起来 $result[$key]= array( ‘id‘=>$val->id, ‘apply_userid‘=>$this->User_model->get($val->apply_userid)[0]->name,//比如这个id就变成对应id的名字 ‘apply_time‘ => $val->apply_time, ‘apply_bm‘ => $this->Department_model->get($val->apply_bm)[0]->name, ‘apply_reason‘ => $val->apply_reason, ‘apply_status‘=>$val->apply_status, ); }; //上面是修改过的数据: $output->data = $result; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 执行事务审批操作 * 判断审批层级,决定是否发送下级审批 * 审批完成后,作为审批人会收到信息提醒 * 读取审批记录,判断进行到第几步 * */ public function _apply_approve(){ $uid = $this->userid; $postdata = $this->input->post(); if(empty($postdata)){ //审批内容展示 $this->set_html_title("事务申请", True); $this->set_body(‘f/apply_approve‘); $this->html(‘f/base‘); }else{ //审批执行操作 $output = new ApiOut(); try { if (empty($postdata[‘logid‘])) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } $this->load->model("Approval_model"); if($postdata[‘type‘]==‘y‘)$act=‘1‘;//假如传过来的类型为y的话,激活的状态改为1,否则的话激活的状态改为2 else $act=‘2‘; $this->load->model("Affairs_approve_log"); $this->Affairs_approve_log->update(array(‘act‘=>$act,‘approve_reason‘=>$postdata[‘approve_reason‘]),array(‘id‘=>$postdata[‘logid‘])); if($postdata[‘type‘]==‘y‘){ //验证是否还需要下级审核,如果存在进行下级审核,不存在下级审核,执行发送消息提醒至发起人 $form = $this->Affairs_approve_log->get(array(‘base_id‘=>$postdata[‘base_id‘])); $step = count($form) + 1; if($approve_userid = $this->_apply_getuserid($postdata[‘form_id‘],$step)){//判断是否存在下级审批人,假如存在的话,就给下级审批人发送,假如不存在的话 就给本人发送,审批完成 //给下级审批人发送 $content = ‘有新的申请等待您的审批‘; $link = $this->appUrl."/f/apply/approve"; $msg = array( ‘touser‘=>$approve_userid, ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content.$this->link_wrapper($link) ) ); $ret = $this->User_model->send_msg($msg); //执行数据库记录 $this->load->model("Affairs_approve_log"); $insertdata = array( ‘base_id‘=>$postdata[‘base_id‘], ‘approve_userid‘=>$approve_userid ); $this->Affairs_approve_log->insert($insertdata); }else{ //给本人发送 $content = ‘您的事务申请完成审批,审批结果是审批通过‘; $msg = array( ‘touser‘=>$postdata[‘apply_userid‘], ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content ) ); $ret = $this->User_model->send_msg($msg); $baseinf = $this->db->query("select *,user.name as username,affairs_form.name as affairsname from affairs_base_value left join affairs_form on affairs_form.id = affairs_base_value.form_id left join user on user.id = affairs_base_value.apply_userid where affairs_base_value.id=$postdata[base_id]")->result_array(); //给指定的消息接受人发送消息 $contents =$baseinf[0][‘username‘].‘的‘.$baseinf[0][‘affairsname‘].‘申请审批完成‘; $msgs = array( ‘touser‘=>$baseinf[0][‘cc‘], ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$contents ) ); $rets = $this->User_model->send_msg($msgs); //同时更新事务状态 } }else{ $this->load->model("Affairs_base_value");//固定数据 $this->Affairs_base_value->update(array(‘apply_status‘=>‘0‘),array(‘id‘=>$postdata[‘base_id‘])); //给本人发送 $content = ‘您的事务申请完成审批,审批结果是审批未通过,原因是‘.$postdata[‘approve_reason‘]; $msg = array( ‘touser‘=>$postdata[‘apply_userid‘], ‘safe‘=>‘0‘, ‘agentid‘=>‘001‘, ‘msgtype‘=>‘text‘, ‘text‘=>array( ‘content‘=>$content ) ); $ret = $this->User_model->send_msg($msg); } } catch (Exception $ex) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } } /** * 待审批事务列表 * 已审批和未审批列表 * */ public function _apply_approvelist(){ $uid = $this->userid; $output = new ApiOut(); try { if (empty($uid)) { throw new Exception("哦,出错了,参数传递过程丢失...", 400); } //$this->load->model("Affairs_approve_log"); //$data = $this->Affairs_approve_log->get(array(‘approve_userid‘=>$uid)); $base_id=‘‘; $data = $this->db->query("select `base`.*,`log`.*,`user`.name,log.id as `logid`,`department`.name as `bm` from `affairs_base_value` as `base` left join `affairs_approve_log` as `log` on base.id=log.base_id left join `user` on user.userid=base.apply_userid left join `department` on `department`.id=base.apply_bm where log.approve_userid=‘$uid‘ ")->result(); foreach($data as $key =>$val){ if($base_id!=‘‘) $base_id.=‘,‘; $base_id .= $val->base_id; } //mysql语句左连接,左连接的意思是显示left join 前面的所有数据和符合leftjoin的符合的数据 if($base_id!=‘‘){ $where = " base_id in ( $base_id) "; $wherelog = " and `log`.base_id in ( $base_id) "; } $loglist = $this->db->query(" select * from `affairs_approve_log` as `log` left join `user` on `user`.userid = log.approve_userid where 1 and `act`!=‘0‘")->result_array(); //$this->load->model("Affairs_form_value"); //$formvalue = $this->Affairs_form_value->get($where); $formvalue = $this->db->query("select * from `affairs_form_value` where $where")->result_array(); $output->formvalue = $formvalue; $output->data = $data; $output->approvelogs = $loglist; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 公司通知 * @author weixing */ public function notice($action=""){ $this->load->model(‘Employee_notice‘); if ($action) { $method_name = "_".__FUNCTION__."_".$action;// 这里的action 应该是理解为该控制器的 里面不同的方法名 if ((method_exists($this, $method_name))) { call_user_func(array($this, $method_name)); } }else{ $this->set_html_title("公司通知", True); $this->set_body(‘f/notice‘); $this->html(‘f/base‘); } } /** * 公司通知列表 * @author weixing */ public function _notice_list(){ $output = new ApiOut(); try { /*if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); }*/ $this->load->model(‘Employee_notice‘); $data = $this->Employee_notice->get(array(‘act‘=>‘1‘)); $output->data = $data; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /** * 公司通知详情 * */ public function _notice_info(){ $output = new ApiOut(); try{ /*if ($this->User_model->is_login() == False) { throw new Exception("授权失败", 403); } */ $id = $this->input->get(‘id‘); if(empty($id)){ throw new Exception("参数传递过程中发生错误", 404); } $this->load->model(‘Employee_notice‘); $data = $this->Employee_notice->get(array(‘id‘=>$id)); $output->data = $data[0]; } catch (Exception $e) { $output->msg = $e->getMessage(); $output->status = $e->getCode(); } $output->json(); } /*公司通知 发送消息给审核人 * * */ public function _notice_verifies(){ //功能:发送消息给审核人 (原来没有) $this->set_body(‘f/notice_verifies‘); $this->html(); } }
标签:
原文地址:http://www.cnblogs.com/leong/p/4250006.html