作者 zhl

处理数据重复问题

... ... @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Ai\AiBlog;
use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\Industry\ProjectIndustryRelated;
use App\Models\Inquiry\InquiryRelateDomain;
use App\Models\Manage\ManageHr;
use App\Models\News\News;
... ... @@ -47,12 +48,12 @@ class PrivateController extends BaseController
public function optimizeProjectList(Request $request)
{
$page_size = $request->input('page_size', 20);
$field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain', 'b.special', 'f.industry_name', 'gl_project.from_order_id'];
$field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain', 'b.special', 'gl_project.from_order_id'];// 'f.industry_name',
$result = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
->leftJoin('gl_project_industry_related as e', 'gl_project.id', '=', 'e.project_id')
->leftJoin('gl_project_industry as f', 'e.industry_id', '=', 'f.id')
// ->leftJoin('gl_project_industry_related as e', 'gl_project.id', '=', 'e.project_id')
// ->leftJoin('gl_project_industry as f', 'e.industry_id', '=', 'f.id')
->where('gl_project.type', Project::TYPE_TWO)
->where('gl_project.project_type',Project::TYPE_ZERO)
->where('gl_project.extend_type', 0) // 是否续费是由extend_type字段控制
... ... @@ -62,6 +63,14 @@ class PrivateController extends BaseController
})
->paginate($page_size)
->toArray();
// 直接关联查询, 会出现数据错误
$project_ids = array_column($result['list'], 'id');
$industry = ProjectIndustryRelated::leftJoin('gl_project_industry', 'gl_project_industry_related.industry_id', '=', 'gl_project_industry.id')->whereIn('project_id', $project_ids)->pluck('industry_name', 'project_id')->toArray();
foreach ($result['list'] as &$val) {
$val['industry_name'] = FALSE == empty($industry[$val['id']]) ? $industry[$val['id']] : '';
}
return $this->success($result);
}
... ...