master
cody 3 months ago
parent 0f0c9e5e60
commit 3c35914be0

@ -9,6 +9,7 @@ use App\Helpers\ResponseCode;
use App\Models\AccompanyOrder; use App\Models\AccompanyOrder;
use App\Models\AppointmentTotalLog; use App\Models\AppointmentTotalLog;
use App\Models\Calendar; use App\Models\Calendar;
use App\Models\Company;
use App\Models\Config; use App\Models\Config;
use App\Models\Course; use App\Models\Course;
use App\Models\CourseAppointmentTotal; use App\Models\CourseAppointmentTotal;
@ -124,10 +125,10 @@ class CourseController extends CommonController
]); ]);
} }
])->withCount([ ])->withCount([
'courseSigns as my_user' => function ($query) { 'courseSigns as my_user' => function ($query) {
$query->where('user_id', $this->getUserId()); $query->where('user_id', $this->getUserId());
} }
])->find($all['course_id']); ])->find($all['course_id']);
return $this->success($detail); return $this->success($detail);
} }
@ -266,6 +267,17 @@ class CourseController extends CommonController
return $this->fail([ResponseCode::ERROR_PARAMETER, '以下字段为必填项:' . implode('、', $missingFields)]); return $this->fail([ResponseCode::ERROR_PARAMETER, '以下字段为必填项:' . implode('、', $missingFields)]);
} }
} }
// 检测 company_name 字段是否包含特殊符号
if (isset($all['data']) && is_array($all['data'])) {
foreach ($all['data'] as $item) {
if (isset($item['field']) && $item['field'] === 'company_name' && !empty($item['value'])) {
$validation = Company::validateCompanyName($item['value']);
if (!$validation['valid']) {
return $this->fail([ResponseCode::ERROR_BUSINESS, $validation['message']]);
}
}
}
}
$result = CourseSign::create([ $result = CourseSign::create([
'is_change' => $all['is_change'] ?? 0, 'is_change' => $all['is_change'] ?? 0,
'course_id' => $all['course_id'], 'course_id' => $all['course_id'],
@ -803,54 +815,54 @@ class CourseController extends CommonController
$query->where('status', 1); $query->where('status', 1);
} }
})->with([ })->with([
'courseSigns' => function ($query) use ($all) { 'courseSigns' => function ($query) use ($all) {
$query->where('status', 1)->whereHas('course', function ($q) { $query->where('status', 1)->whereHas('course', function ($q) {
$q->where('is_fee', 1); $q->where('is_fee', 1);
})->with('course.teacher', 'course.typeDetail') })->with('course.teacher', 'course.typeDetail')
->orderByRaw("FIELD(fee_status, 1, 0, 2,3)"); ->orderByRaw("FIELD(fee_status, 1, 0, 2,3)");
if (isset($all['course_id'])) { if (isset($all['course_id'])) {
$query->where('course_id', $all['course_id']); $query->where('course_id', $all['course_id']);
} }
}
])->where(function ($query) use ($all) {
if ($all['type'] == 1) {
$query->where('is_schoolmate', 1);
}
if (isset($all['name'])) {
$query->where('name', 'like', '%' . $all['name'] . '%');
}
if (isset($all['company_business'])) {
$query->where('company_business', 'like', '%' . $all['company_business'] . '%');
}
if (isset($all['company_name'])) {
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');
}
if (isset($all['company_position'])) {
$query->where('company_position', $all['company_position']);
}
if (isset($all['company_area'])) {
$query->where('company_area', 'like', '%' . $all['company_area'] . '%');
}
if (isset($all['company_type'])) {
$company_type = explode(',', $all['company_type']);
$query->where(function ($q) use ($company_type) {
foreach ($company_type as $v) {
$q->orWhereRaw('FIND_IN_SET(?, company_type)', [$v]);
} }
}); ])->where(function ($query) use ($all) {
} if ($all['type'] == 1) {
if (isset($all['company_industry'])) { $query->where('is_schoolmate', 1);
$company_industry = explode(',', $all['company_industry']); }
$query->where(function ($q) use ($company_industry) { if (isset($all['name'])) {
foreach ($company_industry as $v) { $query->where('name', 'like', '%' . $all['name'] . '%');
$q->orWhereRaw('FIND_IN_SET(?, company_industry)', [$v]); }
if (isset($all['company_business'])) {
$query->where('company_business', 'like', '%' . $all['company_business'] . '%');
}
if (isset($all['company_name'])) {
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');
}
if (isset($all['company_position'])) {
$query->where('company_position', $all['company_position']);
}
if (isset($all['company_area'])) {
$query->where('company_area', 'like', '%' . $all['company_area'] . '%');
}
if (isset($all['company_type'])) {
$company_type = explode(',', $all['company_type']);
$query->where(function ($q) use ($company_type) {
foreach ($company_type as $v) {
$q->orWhereRaw('FIND_IN_SET(?, company_type)', [$v]);
}
});
}
if (isset($all['company_industry'])) {
$company_industry = explode(',', $all['company_industry']);
$query->where(function ($q) use ($company_industry) {
foreach ($company_industry as $v) {
$q->orWhereRaw('FIND_IN_SET(?, company_industry)', [$v]);
}
});
}
if (isset($all['letter'])) {
$query->where('letter', $all['letter']);
} }
}); });
}
if (isset($all['letter'])) {
$query->where('letter', $all['letter']);
}
});
if (isset($all['type']) && $all['type'] == 2) { if (isset($all['type']) && $all['type'] == 2) {
$list = $list->orderBy('letter')->paginate(10); $list = $list->orderBy('letter')->paginate(10);
} else { } else {

@ -10,6 +10,7 @@ use App\Helpers\StarterResponseCode;
use App\Jobs\SendAppointCar; use App\Jobs\SendAppointCar;
use App\Jobs\SendCourseCar; use App\Jobs\SendCourseCar;
use App\Models\Appointment; use App\Models\Appointment;
use App\Models\Company;
use App\Models\Config; use App\Models\Config;
use App\Models\CourseContentCheck; use App\Models\CourseContentCheck;
use App\Models\CourseSign; use App\Models\CourseSign;
@ -181,6 +182,13 @@ class UserController extends CommonController
if (isset($all['name']) && !empty($all['name'])) { if (isset($all['name']) && !empty($all['name'])) {
$all['letter'] = strtoupper(Pinyin::abbr(mb_substr($all['name'], 0, 1))[0]); $all['letter'] = strtoupper(Pinyin::abbr(mb_substr($all['name'], 0, 1))[0]);
} }
// 如果上传了company_name检测是否包含特殊符号
if (isset($all['company_name']) && !empty($all['company_name'])) {
$validation = Company::validateCompanyName($all['company_name']);
if (!$validation['valid']) {
return $this->fail([ResponseCode::ERROR_BUSINESS, $validation['message']]);
}
}
$model->fill($all); $model->fill($all);
$model->save(); $model->save();
// 如果有公司信息,就更新一下公司 // 如果有公司信息,就更新一下公司
@ -232,10 +240,10 @@ class UserController extends CommonController
{ {
$user = User::with('appointments') $user = User::with('appointments')
->withCount([ ->withCount([
'appointments as pass_appointments' => function ($query) { 'appointments as pass_appointments' => function ($query) {
$query->whereIn('status', [0, 1]); $query->whereIn('status', [0, 1]);
} }
])->with([ ])->with([
'courseSigns' => function ($query) { 'courseSigns' => function ($query) {
$query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1); $query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1);
} }

@ -331,4 +331,92 @@ class Company extends SoftDeletesModel
return false; return false;
} }
/**
* 验证公司名称是否包含特殊符号
* @param string $companyName 公司名称
* @return array 返回结果 ['valid' => bool, 'message' => string]
*/
public static function validateCompanyName($companyName)
{
if (empty($companyName)) {
return ['valid' => true, 'message' => ''];
}
// 定义不允许的特殊符号(包含中英文标点符号,键盘上能打出来的所有标点符号)
$forbiddenChars = [
// 英文标点符号
'/',
'\\',
'.',
',',
';',
':',
"'",
'"',
'?',
'!',
'@',
'#',
'$',
'%',
'^',
'&',
'*',
'(',
')',
'[',
']',
'{',
'}',
'|',
'`',
'~',
'-',
'_',
'+',
'=',
'<',
'>',
// 中文标点符号
'。',
'',
'、',
'',
'',
'',
'',
'…',
'—',
'·',
'',
'¥',
'',
'',
'【',
'】',
'《',
'》',
'〈',
'〉',
'「',
'」',
'『',
'』',
'',
'',
];
// 添加中文引号字符(使用十六进制编码避免语法错误)
$chineseQuotes = ["\xE2\x80\x9C", "\xE2\x80\x9D", "\xE2\x80\x98", "\xE2\x80\x99"]; // " " ' '
$forbiddenChars = array_merge($forbiddenChars, $chineseQuotes);
foreach ($forbiddenChars as $char) {
if (strpos($companyName, $char) !== false) {
return ['valid' => false, 'message' => '公司名称不能包含特殊符号'];
}
}
return ['valid' => true, 'message' => ''];
}
} }

Loading…
Cancel
Save