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="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="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\Response(
* response="200",
@ -51,55 +52,69 @@ class CourseContentController extends BaseController
$all = request()->all();
$list = $this->model->with($all['show_relation'] ?? [])
->withCount('courseKeeps')
->withCount(['courseKeeps as user_sign_total' => function ($query) {
$query->where('status', 1);
}])->withCount(['courseKeeps as user_lack_sign_total' => function ($query) {
$query->where('status', 0);
}])->where(function ($query) use ($all) {
if (isset($all['filter']) && !empty($all['filter'])) {
foreach ($all['filter'] as $condition) {
$key = $condition['key'] ?? null;
$op = $condition['op'] ?? null;
$value = $condition['value'] ?? null;
if (!isset($key) || !isset($op) || !isset($value)) {
continue;
}
// 等于
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)) {
->withCount([
'courseKeeps as user_sign_total' => function ($query) {
$query->where('status', 1);
}
])->withCount([
'courseKeeps as user_lack_sign_total' => function ($query) {
$query->where('status', 0);
}
])->where(function ($query) use ($all) {
// 课程方向筛选(支持多选,多个英文逗号分隔)
if (isset($all['direction']) && !empty($all['direction'])) {
$directions = explode(',', $all['direction']);
$query->where(function ($q) use ($directions) {
foreach ($directions as $direction) {
$q->orWhereRaw('FIND_IN_SET(?, direction)', [trim($direction)]);
}
});
}
if (isset($all['filter']) && !empty($all['filter'])) {
foreach ($all['filter'] as $condition) {
$key = $condition['key'] ?? null;
$op = $condition['op'] ?? null;
$value = $condition['value'] ?? null;
if (!isset($key) || !isset($op) || !isset($value)) {
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'])) {
// 导出文件名字
$list = $list->limit(5000)->get()->toArray();
@ -280,7 +295,7 @@ class CourseContentController extends BaseController
if (!in_array('日期', $keyList)) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '日期字段不存在']);
}
// if (!in_array('时间', $keyList)) {
// if (!in_array('时间', $keyList)) {
// return $this->fail([ResponseCode::ERROR_BUSINESS, '时间字段不存在']);
// }
if (!in_array('授课老师', $keyList)) {
@ -292,7 +307,7 @@ class CourseContentController extends BaseController
if (!in_array('课程主题', $keyList)) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '课程主题字段不存在']);
}
// if (!in_array('主题方向', $keyList)) {
// if (!in_array('主题方向', $keyList)) {
// return $this->fail([ResponseCode::ERROR_BUSINESS, '主题方向字段不存在']);
// }
// if (!in_array('上课地点', $keyList)) {

Loading…
Cancel
Save