list_type = $list_type; } /** * @notes 设置搜索条件 * @return \string[][] * @author likeadmin * @date 2024/02/01 11:26 */ public function setSearch(): array { return [ '=' => ['check_status'] ]; } /** * @notes 获取日常审批列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/02/01 11:26 */ public function lists(): array { $where = []; switch ($this->list_type){ case 1: //我发起的 $where[] = ['create_user','=',$this->adminId]; break; case 2: //我处理的 $approve_ids = FlowStep::whereFindInSet('flow_user',$this->adminId)->column('approve_id'); $where[] = ['id','in',$approve_ids]; break; case 3: //抄送我的 $flow_ids = Flow::whereFindInSet('copy_uids',$this->adminId)->column('id'); $where[] = ['flow_id','in',$flow_ids]; break; } return FlowApprove::where($this->searchWhere)->where($where) ->field(['id', 'title', 'flow_type_id', 'flow_id', 'create_user', 'check_status', 'create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($data){ //获取审批类型 $flow_type = FlowType::field('title')->where('id',$data['flow_type_id'])->findOrEmpty(); //获取审批流程信息 $flow = Flow::field('name,copy_uids')->where('id',$data['flow_id'])->findOrEmpty(); //获取创建人信息 $create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty(); //获取抄送人信息 $copy = Admin::where('id','in',$flow['copy_uids'])->column('name'); //当前审核人 $current_check_user = ''; //获取审核步骤 FlowStep::field('flow_step,flow_user,is_active')->where('approve_id',$data['id'])->order('sort asc')->select()->each(function($item)use(&$current_check_user){ if($item['is_active'] == 1){ if($item['flow_step'] == 0){ $current_check_user = ''; }else{ $flow_user = Admin::where('id','in',$item['flow_user'])->column('name'); $current_check_user = implode(',',$flow_user); } } })->toArray(); $data['flow_type_name'] = $flow_type['title']; $data['flow_name'] = $flow['name']; $data['check_status'] = $data->check_status_text; $data['current_check_user'] = $current_check_user; $data['create_user'] = $create_user['name']; $data['copy_user'] = implode(',',$copy); unset($data['flow_type_id'],$data['flow_id']); }) ->toArray(); } /** * @notes 获取日常审批数量 * @return int * @author likeadmin * @date 2024/02/01 11:26 */ public function count(): int { $where = []; switch ($this->list_type){ case 1: //我发起的 $where[] = ['create_user','=',$this->adminId]; break; case 2: //我处理的 $approve_ids = FlowStep::whereFindInSet('flow_user',$this->adminId)->column('approve_id'); $where[] = ['id','in',$approve_ids]; break; case 3: //抄送我的 $flow_ids = Flow::whereFindInSet('copy_uids',$this->adminId)->column('id'); $where[] = ['flow_id','in',$flow_ids]; break; } return FlowApprove::where($this->searchWhere)->where($where)->count(); } }