SpecialCourse.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * Class SpecialCourse 专题课程
  16. * @package app\admin\model\special
  17. */
  18. class SpecialCourse extends ModelBasic
  19. {
  20. use ModelTrait;
  21. public static function getAddTimeAttr($value)
  22. {
  23. return $value ? date('Y-m-d H:i:s', $value) : '';
  24. }
  25. public static function setWhere($where, $alias = '', $model = null)
  26. {
  27. if ($model === null) $model = new self();
  28. if ($alias) $model = $model->alias($alias);
  29. $alias = $alias ? $alias . '.' : '';
  30. if ($where['is_show'] !== '') $model = $model->where("{$alias}is_show", $where['is_show']);
  31. if ($where['special_id']) $model = $model->where("{$alias}special_id", $where['special_id']);
  32. if ($where['course_name']) $model = $model->where("{$alias}course_name", 'LIKE', "%$where[course_name]%");
  33. return $model;
  34. }
  35. public static function getCourseList($where)
  36. {
  37. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  38. foreach ($data as &$item) {
  39. $item['special_name'] = Special::where('id', $item['special_id'])->value('title');
  40. $item['number'] = SpecialTask::where(['coures_id' => $item['id'], 'is_show' => 1])->count();
  41. }
  42. $count = self::setWhere($where)->count();
  43. return compact('data', 'count');
  44. }
  45. public static function DelCourse($id)
  46. {
  47. $coures = self::get($id);
  48. if (!$coures) return false;
  49. if (SpecialTask::where('coures_id', $id)->count()) return self::setErrorInfo('请先删除此课程下的任务再尝试删除');
  50. return $coures->delete();
  51. }
  52. }