auth->id; //halt($user_id); $data = (new \app\admin\model\fastflow\flow\Bill())->field('bill_name,bill_table')->select(); $array = []; foreach ($data as $item){ $bill = $item['bill_table']; $canCheck_ids = []; $canCheckIndexRows_byUser = CancheckIndex::where(['bill' => $bill, 'worker_id' => $user_id])->where('scope', 'in', [1, 3])->select();//通过user_id获取待审批单据ids foreach ($canCheckIndexRows_byUser as $canCheckIndexRow_byUesr) { $canCheck_ids[] = $canCheckIndexRow_byUesr['bill_id']; } $group_ids = $this->getUserGroupIds($user_id); $canCheckIndexRows_byGroup = CancheckIndex::where(['bill' => $bill])->where('scope', 'in', [2, 4])->where('worker_id', 'in', $group_ids)->select();//通过group_id获取待审批单据ids foreach ($canCheckIndexRows_byGroup as $canCheckIndexRow_byGroup) { $canCheck_ids[] = $canCheckIndexRow_byGroup['bill_id']; } $array2['bill_ids'] = array_unique($canCheck_ids); $array2['bill_name'] = $item['bill_name']; $array2['bill_table'] = $item['bill_table']; if(!empty($array2['bill_ids'])){ $array[] = $array2; } } $list = []; foreach ($array as $k=>&$item){ $item['id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill_table'])->value('id'); $item['list'] = $this->cancheckIndexList(['type'=>$item['bill_table'],'bill_ids'=>$item['bill_ids']]); $list += array_merge($list,$item['list']); } foreach ($list as &$item){ $item['message_type'] = 'approval'; $item['message_time'] = $item['createtime']; } $where_list2 = []; $where_list3 = []; $where_list4 = []; if($name === null){ $list = []; }else{ $where_list2['business_name | business_city | company_name |contacts_name | contacts_mobile'] = ['LIKE','%'.$name.'%']; $where_list3['content'] = ['LIKE','%'.$name.'%']; $list4_ids = \addons\qingdong\model\Staff::where('name','LIKE','%'.$name.'%')->column('id'); $where_list4['id'] = ['in',$list4_ids]; } //halt($name !== null); //项目报备消息 $reportModel = new \addons\qingdong\model\Report(); $list2 = $reportModel->where($where_list2)->with('staff')->select(); foreach ($list2 as &$item){ $item['message_type'] = 'report'; $item['message_time'] = $item['createtime']; } $list2 = collection($list2)->toArray(); //crm提醒消息 $satff_ids = \addons\qingdong\model\Staff::getLowerStaffId2(4); $list3 = (new MessageModel)->where($where_list3)->where('from_staff_id','in',$satff_ids)->where('status',0)->order('createtime desc')->select(); foreach ($list3 as &$item){ $user = Staff::find($item['from_staff_id']); $item['nickname'] = $user['name']; //本级部门 $group_id = $user['group_ids']; $group = AuthGroup::where("find_in_set(id,'$group_id')")->column('name'); //上级部门 $upper_id = AuthGroup::where("find_in_set(id,'$group_id')")->value('pid'); $upper_name = AuthGroup::where('id',$upper_id)->value('name'); $item['upper_name'] = $upper_name; $item['group_name'] = implode(',',$group); $item['message_type'] = 'crm'; $item['message_time'] = $item['createtime']; } $list3 = collection($list3)->toArray(); //考勤消息 $list4 = AttendanceStatisc::with('staff')->where($where_list4)->where('clock_in','neq','null')->order('clock_in desc')->select(); foreach ($list4 as &$item){ $item['message_type'] = 'attendance'; $item['message_time'] = strtotime('clock_in'); } $list4 = collection($list4)->toArray(); // 合并所有列表 $allList = array_merge($list, $list2, $list3, $list4); // 根据 message_time 字段倒序排序 usort($allList, function($a, $b) { return $b['message_time'] <=> $a['message_time']; }); // 分页 $page = input('page/d', 1); $limit = input('limit/d', 10); $offset = ($page - 1) * $limit; $total = count($allList); $pagedList = array_slice($allList, $offset, $limit); // 返回分页结果 $result = [ 'total' => $total, 'page' => $page, 'limit' => $limit, 'data' => $pagedList, ]; $this->success('', $result); //$this->success('',$allList); } //消息中心 //public function messageCenter(){ // // //待审批消息 // $user_id = $this->auth->id; // //halt($user_id); // $data = (new \app\admin\model\fastflow\flow\Bill())->field('bill_name,bill_table')->select(); // $array = []; // foreach ($data as $item){ // $bill = $item['bill_table']; // $canCheck_ids = []; // $canCheckIndexRows_byUser = CancheckIndex::where(['bill' => $bill, 'worker_id' => $user_id])->where('scope', 'in', [1, 3])->select();//通过user_id获取待审批单据ids // foreach ($canCheckIndexRows_byUser as $canCheckIndexRow_byUesr) { // $canCheck_ids[] = $canCheckIndexRow_byUesr['bill_id']; // } // $group_ids = $this->getUserGroupIds($user_id); // // $canCheckIndexRows_byGroup = CancheckIndex::where(['bill' => $bill])->where('scope', 'in', [2, 4])->where('worker_id', 'in', $group_ids)->select();//通过group_id获取待审批单据ids // foreach ($canCheckIndexRows_byGroup as $canCheckIndexRow_byGroup) { // $canCheck_ids[] = $canCheckIndexRow_byGroup['bill_id']; // } // $array2['bill_ids'] = array_unique($canCheck_ids); // $array2['bill_name'] = $item['bill_name']; // $array2['bill_table'] = $item['bill_table']; // // if(!empty($array2['bill_ids'])){ // $array[] = $array2; // } // } // $list = []; // foreach ($array as $k=>&$item){ // $item['id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill_table'])->value('id'); // $item['list'] = $this->cancheckIndexList(['type'=>$item['bill_table'],'bill_ids'=>$item['bill_ids']]); // $list += array_merge($list,$item['list']); // } // foreach ($list as &$item){ // $item['message_type'] = 'approval'; // $item['message_time'] = $item['createtime']; // } // // //halt($list); // $limit = input("limit/d", 10); // // //项目报备消息 // $reportModel = new \addons\qingdong\model\Report(); // $list2 = $reportModel->with('staff')->paginate($limit); // $array2 = []; // foreach ($list2 as &$item){ // $item['message_type'] = 'report'; // $item['message_time'] = $item['createtime']; // $array2[] = $item; // } // $list2 = collection($array2)->toArray(); // //halt($array2); // //halt($list2); // // //crm提醒消息 // $satff_ids = \addons\qingdong\model\Staff::getLowerStaffId2(4); // $list3 = (new MessageModel)->where('from_staff_id','in',$satff_ids)->where('status',0)->order('createtime desc')->paginate($limit); // // $array3 = []; // foreach ($list3 as &$item){ // $user = Staff::find($item['from_staff_id']); // $item['nickname'] = $user['name']; // //本级部门 // $group_id = $user['group_ids']; // $group = AuthGroup::where("find_in_set(id,'$group_id')")->column('name'); // //上级部门 // $upper_id = AuthGroup::where("find_in_set(id,'$group_id')")->value('pid'); // $upper_name = AuthGroup::where('id',$upper_id)->value('name'); // $item['upper_name'] = $upper_name; // $item['group_name'] = implode(',',$group); // $item['message_type'] = 'crm'; // $item['message_time'] = $item['createtime']; // // $array3[] = $item; // } // $list3 = collection($array3)->toArray(); // // //考勤消息 // $list4 = AttendanceStatisc::with('staff')->where('clock_in','neq','null')->order('clock_in desc')->paginate($limit); // $array4 = []; // foreach ($list4 as &$item){ // $item['message_type'] = 'attendance'; // $item['message_time'] = strtotime('clock_in'); // $array4[] = $item; // } // $list4 = collection($array4)->toArray(); // // // // 合并所有列表 // $allList = array_merge($list, $list2, $list3, $list4); // // // 根据 message_time 字段倒序排序 // usort($allList, function($a, $b) { // return $b['message_time'] <=> $a['message_time']; // }); // // $this->success('',$allList); // //} public function getList(){ $param = $this->request->param(); $where = []; if(isset($param['relation_type']) && !empty($param['relation_type'])){ $where['relation_type'] = ['=',$param['relation_type']]; } $satff_ids = \addons\qingdong\model\Staff::getLowerStaffId2(4); $list = (new MessageModel)->where($where)->where('from_staff_id','in',$satff_ids)->where('status',0)->order('createtime desc')->select(); foreach ($list as &$item){ $user = Staff::find($item['from_staff_id']); $item['nickname'] = $user['name']; //本级部门 $group_id = $user['group_ids']; $group = AuthGroup::where("find_in_set(id,'$group_id')")->column('name'); //上级部门 $upper_id = AuthGroup::where("find_in_set(id,'$group_id')")->value('pid'); $upper_name = AuthGroup::where('id',$upper_id)->value('name'); $item['upper_name'] = $upper_name; $item['group_name'] = implode(',',$group); } $this->success('',$list); } public function readMessage(){ $param = $this->request->param(); \addons\qingdong\model\Message2::setRead($param['id']); $this->success('操作成功'); } public function object_array($array) { if (is_object($array)) { $array = (array) $array; } if (is_array($array)) { foreach ($array as $key => $value) { $array[$key] = $this->object_array($value); } } return $array; } //查看待审批要的方法(cancheckIndexList,getUserGroupIds) public function cancheckIndexList($param){ $bill_ids = $param['bill_ids']; $billModel = new \app\admin\model\fastflow\flow\Bill(); //采购设备 if($param['type'] == 'ats_xtuqll'){ $Model = new Xtuqll(); $Model->where('xtuqll.id in (' . implode(',',$bill_ids). ')'); $list = $Model->with('business')->order('createtime desc')->select(); //halt($list); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id',$item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id',$item['business_id'])->value('name'); $item['url'] = (new Amodel())->where('bill_id',$item['id'])->where('type','contract')->value('file'); } } //请假 elseif ($param['type'] == 'ats_hvuxhg'){ $Model = new Hvuxhg(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //出差 elseif ($param['type'] == 'ats_aysdrr'){ $Model = new Aysdrr(); $Model->where('aysdrr.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with('business')->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //转正 elseif ($param['type'] == 'ats_dudzeq'){ $Model = new Dudzeq(); $Model->where('dudzeq.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with('user')->order('createtime desc')->select(); $staffModel = new \addons\qingdong\model\Staff(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['admin_id'] = $staffModel->where('id', $item['admin_id'])->value('name'); } } //招聘 elseif ($param['type'] == 'ats_wbvnia'){ $Model = new Wbvnia(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //用车 elseif ($param['type'] == 'ats_nidsvn'){ $Model = new Nidsvn(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //用章 elseif ($param['type'] == 'ats_wduzfa'){ $Model = new Wduzfa(); $Model->where('wduzfa.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with(['business','customer'])->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //退换货单 elseif ($param['type'] == 'ats_xnsdti'){ $Model = new Xnsdti(); $Model->where('xnsdti.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with(['business','customer'])->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //借支款 elseif ($param['type'] == 'ats_mowpvu'){ $Model = new Mowpvu(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //离职申请 elseif ($param['type'] == 'ats_kmqpxi'){ $Model = new Kmqpxi(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); $staffModel = new \addons\qingdong\model\Staff(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['admin_id'] = $staffModel->where('id', $item['admin_id'])->value('name'); } } //业务费预申请 elseif ($param['type'] == 'ats_havols'){ $Model = new Havols(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //临时单次报销 elseif ($param['type'] == 'ats_jxbunq'){ $Model = new Jxbunq(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //产品样品借样 elseif ($param['type'] == 'ats_zaxsta'){ $Model = new Zaxsta(); $Model->where('zaxsta.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with(['business','customer'])->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //酒水申领 elseif ($param['type'] == 'ats_dbxovs'){ $Model = new Dbxovs(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //物品领用 elseif ($param['type'] == 'ats_yoirpj'){ $Model = new Yoirpj(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //设备赠送 elseif ($param['type'] == 'ats_zmqrbq'){ $Model = new Zmqrbq(); $Model->where('zmqrbq.id in (' . implode(',', $bill_ids) . ')'); $list = $Model->with(['business','customer'])->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //付款申请 elseif ($param['type'] == 'ats_kiahkj'){ $Model = new Kiahkj(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //报价申请 elseif ($param['type'] == 'ats_czgprz'){ $Model = new Czgprz(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //合同审批 elseif ($param['type'] == 'ats_bywnpk'){ $Model = new Bywnpk(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); $CzgprzModel = new Czgprz(); $customerModel = new \addons\qingdong\model\Customer(); $businessModel = new \addons\qingdong\model\Business(); foreach ($list as &$item) { $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); $item['bill_id'] = $CzgprzModel->where('id', $item['bill_id'])->value('name'); $item['customer_id'] = $customerModel->where('id', $item['customer_id'])->value('name'); $item['business_id'] = $businessModel->where('id', $item['business_id'])->value('name'); } } //采购申请 elseif ($param['type'] == 'ats_txdphj'){ $Model = new Txdphj(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //入库申请确认 elseif ($param['type'] == 'ats_jiopho'){ $Model = new Jiopho(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //调薪申请 elseif ($param['type'] == 'ats_hwgvrz'){ $Model = new Hwgvrz(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //外出申请 elseif ($param['type'] == 'ats_stwoae'){ $Model = new Stwoae(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } //补卡申请 elseif ($param['type'] == 'ats_asiitn'){ $Model = new Asiitn(); $Model->where('id in (' . implode(',', $bill_ids) . ')'); $list = $Model->order('createtime desc')->select(); foreach ($list as &$item){ $item['bill_rule_id'] = Db::name('fastflow_bill_rule')->where('bill_table',$item['bill'])->value('id'); $item['bill_name'] = $billModel->where('bill_table',$item['bill'])->value('bill_name'); } } else{ $list = []; } return $list; } public function getUserGroupIds($uid) { $group_ids = []; $group_access = workerAdapter::callFn('getGroupAccess', ['uid' => $uid]); if (!$group_access) { return false; } foreach ($group_access as $access) { $group_arr = explode(',', $access['group_id']); foreach ($group_arr as $group_id) { $group_ids[] = $group_id; } } return $group_ids; } }