|
|
|
@ -20,7 +20,8 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
$keyword = trim((string) $request->input('keyword', ''));
|
|
|
|
$keyword = trim((string) $request->input('keyword', ''));
|
|
|
|
$status = $request->input('status');
|
|
|
|
$status = $request->input('status');
|
|
|
|
$pageSize = min(max((int) $request->input('page_size', 20), 1), 100);
|
|
|
|
$pageSize = min(max((int) $request->input('page_size', 20), 1), 100);
|
|
|
|
$query = Company::query()->select('id', 'company_name', 'credit_code', 'updated_at')->with('qccAccount');
|
|
|
|
$query = Company::query()->select('id', 'company_name', 'credit_code', 'updated_at')->with('qccAccount')
|
|
|
|
|
|
|
|
->whereHas('users', fn ($user) => $user->where('is_schoolmate', 1));
|
|
|
|
if ($keyword !== '') {
|
|
|
|
if ($keyword !== '') {
|
|
|
|
$query->where(function ($subQuery) use ($keyword) {
|
|
|
|
$query->where(function ($subQuery) use ($keyword) {
|
|
|
|
$subQuery->where('company_name', 'like', '%' . $keyword . '%')
|
|
|
|
$subQuery->where('company_name', 'like', '%' . $keyword . '%')
|
|
|
|
@ -31,7 +32,7 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
$query->with(['users' => $this->studentRelation()]);
|
|
|
|
$query->with(['users' => $this->studentRelation()]);
|
|
|
|
if ($status === 'none') {
|
|
|
|
if ($status === 'none') {
|
|
|
|
$query->doesntHave('qccAccount');
|
|
|
|
$query->doesntHave('qccAccount');
|
|
|
|
} elseif (in_array($status, [CompanyQccAccount::STATUS_SELECTED, CompanyQccAccount::STATUS_OCCUPIED, CompanyQccAccount::STATUS_UNKNOWN], true)) {
|
|
|
|
} elseif (in_array($status, [CompanyQccAccount::STATUS_SELECTED, CompanyQccAccount::STATUS_OCCUPIED, CompanyQccAccount::STATUS_UNKNOWN, CompanyQccAccount::STATUS_NON_OCCUPYING], true)) {
|
|
|
|
$query->whereHas('qccAccount', fn($relation) => $relation->where('status', $status));
|
|
|
|
$query->whereHas('qccAccount', fn($relation) => $relation->where('status', $status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->studentResponse($query->orderByDesc('id')->paginate($pageSize));
|
|
|
|
return $this->studentResponse($query->orderByDesc('id')->paginate($pageSize));
|
|
|
|
@ -48,7 +49,7 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
if ($keyword !== '') $company->where(fn ($q) => $q->where('company_name', 'like', '%'.$keyword.'%')->orWhere('credit_code', 'like', '%'.$keyword.'%'));
|
|
|
|
if ($keyword !== '') $company->where(fn ($q) => $q->where('company_name', 'like', '%'.$keyword.'%')->orWhere('credit_code', 'like', '%'.$keyword.'%'));
|
|
|
|
$this->applyStudentFilters($company, $request);
|
|
|
|
$this->applyStudentFilters($company, $request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (in_array($status, [CompanyQccAccount::STATUS_SELECTED, CompanyQccAccount::STATUS_OCCUPIED, CompanyQccAccount::STATUS_UNKNOWN], true)) {
|
|
|
|
if (in_array($status, [CompanyQccAccount::STATUS_SELECTED, CompanyQccAccount::STATUS_OCCUPIED, CompanyQccAccount::STATUS_UNKNOWN, CompanyQccAccount::STATUS_NON_OCCUPYING], true)) {
|
|
|
|
$query->where('status', $status);
|
|
|
|
$query->where('status', $status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->studentResponse($query->orderByDesc('id')->paginate($pageSize));
|
|
|
|
return $this->studentResponse($query->orderByDesc('id')->paginate($pageSize));
|
|
|
|
@ -112,6 +113,16 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function select(Request $request)
|
|
|
|
public function select(Request $request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->enroll($request, CompanyQccAccount::STATUS_SELECTED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function selectNonOccupying(Request $request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->enroll($request, CompanyQccAccount::STATUS_NON_OCCUPYING);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function enroll(Request $request, string $status)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$validator = Validator::make($request->all(), ['company_ids' => 'required|array|min:1', 'company_ids.*' => 'integer|distinct']);
|
|
|
|
$validator = Validator::make($request->all(), ['company_ids' => 'required|array|min:1', 'company_ids.*' => 'integer|distinct']);
|
|
|
|
if ($validator->fails()) {
|
|
|
|
if ($validator->fails()) {
|
|
|
|
@ -127,7 +138,7 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DB::transaction(function () use ($companyIds) {
|
|
|
|
DB::transaction(function () use ($companyIds, $status) {
|
|
|
|
$existingCompanyIds = CompanyQccAccount::query()->whereIn('company_id', $companyIds)->lockForUpdate()->pluck('company_id');
|
|
|
|
$existingCompanyIds = CompanyQccAccount::query()->whereIn('company_id', $companyIds)->lockForUpdate()->pluck('company_id');
|
|
|
|
if ($existingCompanyIds->isNotEmpty()) {
|
|
|
|
if ($existingCompanyIds->isNotEmpty()) {
|
|
|
|
throw new RuntimeException('存在已纳入企业户标注的企业');
|
|
|
|
throw new RuntimeException('存在已纳入企业户标注的企业');
|
|
|
|
@ -135,7 +146,7 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
foreach ($companyIds as $companyId) {
|
|
|
|
foreach ($companyIds as $companyId) {
|
|
|
|
CompanyQccAccount::query()->create([
|
|
|
|
CompanyQccAccount::query()->create([
|
|
|
|
'company_id' => $companyId,
|
|
|
|
'company_id' => $companyId,
|
|
|
|
'status' => CompanyQccAccount::STATUS_SELECTED,
|
|
|
|
'status' => $status,
|
|
|
|
'selected_by' => $this->getUserId(),
|
|
|
|
'selected_by' => $this->getUserId(),
|
|
|
|
'selected_at' => now(),
|
|
|
|
'selected_at' => now(),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
@ -144,8 +155,9 @@ class QccEnterpriseAccountController extends CommonController
|
|
|
|
} catch (RuntimeException|QueryException $exception) {
|
|
|
|
} catch (RuntimeException|QueryException $exception) {
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, $exception->getMessage()]);
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, $exception->getMessage()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->log('纳入企查查企业户候选池', implode(',', $companyIds));
|
|
|
|
$label = $status === CompanyQccAccount::STATUS_NON_OCCUPYING ? '不占额企业' : '候选池';
|
|
|
|
return $this->success('已纳入候选池');
|
|
|
|
$this->log('纳入企查查企业户'.$label, implode(',', $companyIds));
|
|
|
|
|
|
|
|
return $this->success('已纳入'.$label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function cancel(Request $request)
|
|
|
|
public function cancel(Request $request)
|
|
|
|
|