master
cody 3 months ago
parent 766b66e188
commit 0c3ab1cd18

@ -39,6 +39,7 @@ class CourseContentController extends BaseController
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"), * @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"), * @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"), * @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
* @OA\Parameter(name="direction", in="query", @OA\Schema(type="string"), required=false, description="课程方向多个英文逗号分隔"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response( * @OA\Response(
* response="200", * response="200",
@ -51,55 +52,69 @@ class CourseContentController extends BaseController
$all = request()->all(); $all = request()->all();
$list = $this->model->with($all['show_relation'] ?? []) $list = $this->model->with($all['show_relation'] ?? [])
->withCount('courseKeeps') ->withCount('courseKeeps')
->withCount(['courseKeeps as user_sign_total' => function ($query) { ->withCount([
$query->where('status', 1); 'courseKeeps as user_sign_total' => function ($query) {
}])->withCount(['courseKeeps as user_lack_sign_total' => function ($query) { $query->where('status', 1);
$query->where('status', 0); }
}])->where(function ($query) use ($all) { ])->withCount([
if (isset($all['filter']) && !empty($all['filter'])) { 'courseKeeps as user_lack_sign_total' => function ($query) {
foreach ($all['filter'] as $condition) { $query->where('status', 0);
$key = $condition['key'] ?? null; }
$op = $condition['op'] ?? null; ])->where(function ($query) use ($all) {
$value = $condition['value'] ?? null; // 课程方向筛选(支持多选,多个英文逗号分隔)
if (!isset($key) || !isset($op) || !isset($value)) { if (isset($all['direction']) && !empty($all['direction'])) {
continue; $directions = explode(',', $all['direction']);
} $query->where(function ($q) use ($directions) {
// 等于 foreach ($directions as $direction) {
if ($op == 'eq') { $q->orWhereRaw('FIND_IN_SET(?, direction)', [trim($direction)]);
$query->where($key, $value); }
} });
// 不等于 }
if ($op == 'neq') {
$query->where($key, '!=', $value); if (isset($all['filter']) && !empty($all['filter'])) {
} foreach ($all['filter'] as $condition) {
// 模糊搜索 $key = $condition['key'] ?? null;
if ($op == 'like') { $op = $condition['op'] ?? null;
$query->where($key, 'like', '%' . $value . '%'); $value = $condition['value'] ?? null;
} if (!isset($key) || !isset($op) || !isset($value)) {
// 否定模糊搜索
if ($op == 'notlike') {
$query->where($key, 'not like', '%' . $value . '%');
}
// null搜索
if ($op == 'null') {
$query->whereNull($key)->orWhereRaw("json_length($key) = 0");
}
// notnull搜索
if ($op == 'notnull') {
// 不是null并且不是空json这个是一个json字段
$query->whereNotNull($key)->whereRaw("json_length($key) > 0");
}
// 范围搜索
if ($op == 'range') {
list($from, $to) = explode(',', $value);
if (empty($from) || empty($to)) {
continue; continue;
} }
$query->whereBetween($key, [$from, $to]); // 等于
if ($op == 'eq') {
$query->where($key, $value);
}
// 不等于
if ($op == 'neq') {
$query->where($key, '!=', $value);
}
// 模糊搜索
if ($op == 'like') {
$query->where($key, 'like', '%' . $value . '%');
}
// 否定模糊搜索
if ($op == 'notlike') {
$query->where($key, 'not like', '%' . $value . '%');
}
// null搜索
if ($op == 'null') {
$query->whereNull($key)->orWhereRaw("json_length($key) = 0");
}
// notnull搜索
if ($op == 'notnull') {
// 不是null并且不是空json这个是一个json字段
$query->whereNotNull($key)->whereRaw("json_length($key) > 0");
}
// 范围搜索
if ($op == 'range') {
list($from, $to) = explode(',', $value);
if (empty($from) || empty($to)) {
continue;
}
$query->whereBetween($key, [$from, $to]);
}
} }
} }
} })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
if (isset($all['is_export']) && !empty($all['is_export'])) { if (isset($all['is_export']) && !empty($all['is_export'])) {
// 导出文件名字 // 导出文件名字
$list = $list->limit(5000)->get()->toArray(); $list = $list->limit(5000)->get()->toArray();
@ -280,7 +295,7 @@ class CourseContentController extends BaseController
if (!in_array('日期', $keyList)) { if (!in_array('日期', $keyList)) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '日期字段不存在']); return $this->fail([ResponseCode::ERROR_BUSINESS, '日期字段不存在']);
} }
// if (!in_array('时间', $keyList)) { // if (!in_array('时间', $keyList)) {
// return $this->fail([ResponseCode::ERROR_BUSINESS, '时间字段不存在']); // return $this->fail([ResponseCode::ERROR_BUSINESS, '时间字段不存在']);
// } // }
if (!in_array('授课老师', $keyList)) { if (!in_array('授课老师', $keyList)) {
@ -292,7 +307,7 @@ class CourseContentController extends BaseController
if (!in_array('课程主题', $keyList)) { if (!in_array('课程主题', $keyList)) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '课程主题字段不存在']); return $this->fail([ResponseCode::ERROR_BUSINESS, '课程主题字段不存在']);
} }
// if (!in_array('主题方向', $keyList)) { // if (!in_array('主题方向', $keyList)) {
// return $this->fail([ResponseCode::ERROR_BUSINESS, '主题方向字段不存在']); // return $this->fail([ResponseCode::ERROR_BUSINESS, '主题方向字段不存在']);
// } // }
// if (!in_array('上课地点', $keyList)) { // if (!in_array('上课地点', $keyList)) {

Loading…
Cancel
Save