|
|
@@ -2771,7 +2771,7 @@ class ItemService extends Service
|
|
|
return [true, $customer];
|
|
|
}
|
|
|
|
|
|
- public function itemMissionProgressListCommon($data,$user, $field = []){
|
|
|
+ public function itemMissionProgressListCommon($data, $user, $field = []){
|
|
|
$item_id = $data['item_id'] ?? 0;
|
|
|
$item_node_id = $data['item_node_id'] ?? 0;
|
|
|
$item_node_mission_id = $data['item_node_mission_id'] ?? 0;
|
|
|
@@ -2779,20 +2779,34 @@ class ItemService extends Service
|
|
|
|
|
|
$model = ItemNodeMission::from('item_node_mission as i');
|
|
|
$model = $model->TopAndEmployeeClear($user, $data)
|
|
|
- ->leftJoin('item_node_mission_content as e', 'i.id', '=', 'e.item_node_mission_id')
|
|
|
- ->where('i.del_time', 0)
|
|
|
+ // 2. 优化重点:把报告可见性逻辑直接作为 JOIN 条件绑定
|
|
|
+ ->leftJoin('item_node_mission_content as e', function($join) use ($user) {
|
|
|
+ $join->on('i.id', '=', 'e.item_node_mission_id')
|
|
|
+ ->where('e.del_time', 0)
|
|
|
+ ->where(function($q) use ($user) {
|
|
|
+ // 或者是当前登录人自己写的报告
|
|
|
+ $q->where('e.data_id', $user['id'])
|
|
|
+ // 或者当前登录人是这笔任务的负责人(利用已铺平的负责人表,精准到任务 i.id)
|
|
|
+ ->orWhereExists(function ($subQuery) use ($user) {
|
|
|
+ $subQuery->from('item_node_mission_employee')
|
|
|
+ ->whereColumn('item_node_mission_employee.item_node_mission_id', 'i.id')
|
|
|
+ ->where('item_node_mission_employee.data_id', $user['id'])
|
|
|
+ ->where('item_node_mission_employee.del_time', 0);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ })
|
|
|
->where('e.del_time', 0)
|
|
|
- ->when(! empty($item_id),function ($query) use($item_id){
|
|
|
- return $query->where('item_id', $item_id);
|
|
|
+ ->when(! empty($item_id), function ($query) use($item_id){
|
|
|
+ return $query->where('i.item_id', $item_id);
|
|
|
})
|
|
|
- ->when(! empty($item_node_id),function ($query) use($item_node_id){
|
|
|
- return $query->where('item_node_id', $item_node_id);
|
|
|
+ ->when(! empty($item_node_id), function ($query) use($item_node_id){
|
|
|
+ return $query->where('i.item_node_id', $item_node_id);
|
|
|
})
|
|
|
- ->when(! empty($item_node_mission_id),function ($query) use($item_node_mission_id){
|
|
|
- return $query->where('item_node_mission_id', $item_node_mission_id);
|
|
|
+ ->when(! empty($item_node_mission_id), function ($query) use($item_node_mission_id){
|
|
|
+ return $query->where('i.item_node_mission_id', $item_node_mission_id);
|
|
|
})
|
|
|
- ->when(! empty($employee_id),function ($query) use($employee_id){
|
|
|
- return $query->where('data_id', $employee_id);
|
|
|
+ ->when(! empty($employee_id), function ($query) use($employee_id){
|
|
|
+ return $query->where('i.data_id', $employee_id);
|
|
|
})
|
|
|
->select('e.*')
|
|
|
->orderby('e.id', 'desc');
|