| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Services\Exam;
- use App\Models\ExamSubjectsModel;
- use App\Models\ActionLogModel;
- use App\Services\BaseService;
- /**
- * 课程管理-服务类
- * Class SubjectService
- */
- class SubjectService extends BaseService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new ExamSubjectsModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new SubjectService();
- }
- return self::$instance;
- }
- /**
- * 获取课程列表
- */
- public function customList($param, $pageSize = 15)
- {
- $query = $this->model->where('mark', operator: 1);
- if (!empty($param['type'])) {
- $query->where('type', $param['type']);
- }
- if (!empty($param['keyword'])) {
- $query->where(function ($q) use ($param) {
- $q->where('id', $param['keyword'])
- ->orWhere('subject_name', 'like', "%{$param['keyword']}%");
- });
- }
- $list = $query->orderBy('sort', 'desc')->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- return message("操作成功", true, $list);
- }
- /**
- * 获取课程详情
- */
- public function getInfo($id)
- {
- $data = $this->model->findOrFail($id);
- return message("操作成功", true, $data);
- }
- /**
- * 删除课程(逻辑删除)
- */
- public function remove($id)
- {
- $subject = $this->model->findOrFail($id);
- $subject->mark = 0;
- $subject->save();
- return message("删除成功", true);
- }
- /**
- * 启用/禁用课程
- */
- public function changeStatus($id, $status)
- {
- $subject = $this->model->findOrFail($id);
- $subject->status = $status;
- $subject->save();
- return message("状态更新成功", true, $subject);
- }
- /**
- * 用户选项
- * @return array
- */
- public function options()
- {
- // 获取参数
- $param = request()->all();
- // 用户ID
- $keyword = getter($param, "keyword");
- $sceneType = getter($param, "scene_type");
- $type = getter($param, "type");
- $datas = $this->model
- ->where('status', '=', 1)
- ->where('mark', '=', 1)
- ->where(function ($query) use ($keyword, $sceneType, $type) {
- if ($keyword) {
- $query->where('subject_name', 'like', "%{$keyword}%");
- }
- if ($type) {
- $query->where('type', '=', $type);
- }
- })
- ->select(['subject_name', 'id'])
- ->get();
- return $datas ? $datas->toArray() : [];
- }
- /**
- * 删除七天之前标记软删除的数据
- */
- public function delete()
- {
- // 设置日志标题
- ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除科目信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
- ActionLogModel::record();
- $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
- return parent::delete();
- }
- }
|