|
@@ -35,6 +35,8 @@ class ApproveService
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
+ $userids = $search && !is_numeric($search) ? User::where('name', 'like', '%' . $search . '%')->column('userid') : [];
|
|
|
+
|
|
|
$userid = $user['userid'];
|
|
|
$aliasName = 'approve.';
|
|
|
$jobName = 'approveInfo.';
|
|
@@ -53,64 +55,71 @@ class ApproveService
|
|
|
$query->where($aliasName . 'status', 'in', [CommonConstant::STATUS_3, CommonConstant::STATUS_4]);
|
|
|
}
|
|
|
})
|
|
|
- ->when($module, function ($query) use ($jobName, $module) {
|
|
|
- $query->where($jobName . 'module', 'in', $module);
|
|
|
- })
|
|
|
->where($aliasName . 'is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
->where($aliasName . 'approve_user', $userid)
|
|
|
->where($jobName . 'is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
- ->when(!empty($start_time) && !empty($end_time), function ($query) use ($aliasName,$start_time, $end_time) {
|
|
|
- $query->where($aliasName.'create_at', 'BETWEEN', [$start_time, $end_time]);
|
|
|
+ ->when($module, function ($query) use ($jobName, $module) {
|
|
|
+ $query->where($jobName . 'module', 'in', $module);
|
|
|
+ })
|
|
|
+ ->when(!empty($start_time) && !empty($end_time), function ($query) use ($aliasName, $start_time, $end_time) {
|
|
|
+ $query->where($aliasName . 'create_at', 'BETWEEN', [$start_time, $end_time]);
|
|
|
+ })
|
|
|
+ ->when($userids, function ($query) use ($jobName, $userids) {
|
|
|
+ $query->where($jobName . 'user_id', 'in', $userids);
|
|
|
})
|
|
|
- ->when($search, function ($query) use ($search) {
|
|
|
- if(!is_numeric($search)){
|
|
|
- $query->where('order_no|reason', 'like', '%' . $search . '%');
|
|
|
- } else{
|
|
|
- $query->where('order_no', 'like', '%' . $search . '%');
|
|
|
+ ->when($search, function ($query) use ($search, $userids) {
|
|
|
+ if (!$userids) {
|
|
|
+ if (!is_numeric($search)) {
|
|
|
+ $query->where('order_no|reason', 'like', '%' . $search . '%');
|
|
|
+ } else {
|
|
|
+ $query->where('order_no', 'like', '%' . $search . '%');
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
- ->join('__APPROVE_INFO__ approveInfo', 'approve.info_id = approveInfo.id', 'INNER')
|
|
|
- ->with(['approve_info_user' => function ($query) {
|
|
|
+ ->join('__APPROVE_INFO__ approveInfo', 'approve.info_id = approveInfo.id', 'INNER');
|
|
|
+ if ($status == 1) {
|
|
|
+ // 待处理 才关联 审批信息
|
|
|
+ $list->with(['approveInfoUser' => function ($query) {
|
|
|
+ $query->field('userid,name');
|
|
|
+ }, 'approveOne' => function ($query) {
|
|
|
+ $query->field('id,info_id,status,approve_user')
|
|
|
+ ->where('status', CommonConstant::STATUS_2)
|
|
|
+ ->with(['user' => function ($query) {
|
|
|
+ $query->field('userid,name');
|
|
|
+ }]);
|
|
|
+ }]);
|
|
|
+ } else {
|
|
|
+ $list->with(['approveInfoUser' => function ($query) {
|
|
|
$query->field('userid,name');
|
|
|
}]);
|
|
|
-// $list = self::get_with($list, $module, $status);
|
|
|
+ }
|
|
|
$list = $list->limit($offset, $length)
|
|
|
->order('id desc')
|
|
|
->select();
|
|
|
-// ->map(function($return){
|
|
|
-// if($return['status'] == CommonConstant::STATUS_1){
|
|
|
-// $return['approve_user'] = Approve::field('id,approve_user')
|
|
|
-// ->where('info_id',$return['info_id'])
|
|
|
-// ->where('status',CommonConstant::STATUS_2)
|
|
|
-// ->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
-// ->find();
|
|
|
-// }
|
|
|
-// return $return;
|
|
|
-// });
|
|
|
-// $array = [];
|
|
|
+
|
|
|
+// $info_ids = [];
|
|
|
// foreach ($list as $value){
|
|
|
-// $array[$value['info_id']] = $value['user_id'];
|
|
|
+// if($value['status'] == CommonConstant::STATUS_1) {
|
|
|
+// $info_ids[] = $value['info_id'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if($info_ids){
|
|
|
+// $approve_one_list = Approve::field('id,info_id,status,approve_user')
|
|
|
+// ->where('info_id','in',$info_ids)
|
|
|
+// ->where('status',CommonConstant::STATUS_2)
|
|
|
+// ->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
+// ->with(['user' => function ($query) {
|
|
|
+// $query->field('userid,name');
|
|
|
+// }])
|
|
|
+// ->select();
|
|
|
+// $approve_one_data = array_column($approve_one_list, null, 'info_id');
|
|
|
+// foreach ($list as $val){
|
|
|
+// if(array_key_exists($val['info_id'],$approve_one_data)){
|
|
|
+// $val['approve_one'] = $approve_one_data[$val['info_id']];
|
|
|
+// }
|
|
|
+// }
|
|
|
// }
|
|
|
-// p($array);exit;
|
|
|
-
|
|
|
- return $list;
|
|
|
- }
|
|
|
|
|
|
- public static function get_with($list, $module, $status)
|
|
|
- {
|
|
|
- switch ($module) {
|
|
|
- case CommonConstant::MODULE_5:
|
|
|
- $list = $list->with(['peer_user' => function ($query) {
|
|
|
- $query->field('id,info_id,name');
|
|
|
- }, 'approve_info' => function ($query) use ($status) {
|
|
|
- $query->field('id,info_id,status,approve_user')
|
|
|
- ->where('status', $status)
|
|
|
- ->with(['user' => function ($query) {
|
|
|
- $query->field('userid,name');
|
|
|
- }]);
|
|
|
- }]);
|
|
|
- break;
|
|
|
- }
|
|
|
return $list;
|
|
|
}
|
|
|
|