| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\model\api;
- use think\facade\Db;
- use think\Model;
- class CourseModel extends Model
- {
- protected $table = 'table_education_course';
- protected $pk = 'course_id';
- /**
- * 添加课程
- * @param $data
- * @return mixed
- */
- public function addCourse($data)
- {
- $result = Db::table($this->table)->insert($data);
- return $result;
- }
- /**
- * 获取课程列表
- *
- * @param string $course_topic
- * @param int $page
- * @param int $pagesize
- * @return mixed
- */
- public function getCourse($course_topic = '', $page = 1, $pagesize = 10)
- {
- $query = $this->order('course_id ASC');
- if (!empty($course_topic)) {
- $query->whereLike('course_topic', '%' . $course_topic . '%');
- }
- $list = $query->paginate([
- 'page' => $page,
- 'list_rows' => $pagesize,
- ]);
- return $list;
- }
- /**
- * 删除课程
- * @param $course_id
- * @return mixed
- */
- public function deleteCourse($course_id)
- {
- $result = Db::table($this->table)->where('course_id', $course_id)->delete();
- return $result;
- }
- /**
- * 查找课程
- * @param $keyword
- * @return mixed
- */
- public function searchCourse($keyword)
- {
- $result = Db::table($this->table)->where('title', 'like', '%' . $keyword . '%')->select();
- return $result;
- }
- /**
- * 获取课程详细信息
- * @param $courseId
- * @return array|Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getCourseDetail($courseId)
- {
- $courseDetail = Db::name('education_course')
- ->alias('c')
- ->join('education_gr g', 'c.gr_id=g.gr_id')
- ->where('c.course_id', $courseId)
- ->find();
- return $courseDetail;
- }
- /**
- * 修改课程状态
- * @param $course_id
- * @param $course_status
- * @return mixed
- */
- public function updateCourseStatus($course_id, $course_status)
- {
- $result = Db::table($this->table)->where('course_id', $course_id)->update(['status' => $course_status]);
- return $result;
- }
- /**
- * 更新编辑分组信息
- * @param int $course_id 课程ID
- * @param array $data 更新数据
- * @return bool 更新成功返回 true,否则返回 false
- */
- public function updateCourse($course_id, $data)
- {
- $course = CourseModel::where('course_id', $course_id)->find();
- if (!$course) {
- return false;
- }
- $result = $course->save($data);
- return $result !== false;
- }
- /**
- * 更新状态
- *
- * @param int $course_id 课程ID
- * @param array $data 数据
- * @return bool
- */
- public function updateAuditStatus($course_id, $data)
- {
- try {
- $this->where('course_id', $course_id)->update($data);
- return true;
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 修改课程信息
- * @param $course_id
- * @param $data
- * @return mixed
- */
- public function updateCourseInfo($course_id, $data)
- {
- $result = Db::table($this->table)->where('course_id', $course_id)->update($data);
- return $result;
- }
- }
|