TestPaper.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\topic;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\wap\model\topic\TestPaperCategory;
  15. /**
  16. * 试卷列表 Model
  17. * Class TestPaper
  18. */
  19. class TestPaper extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**
  23. * 设置专题显示条件
  24. * @param string $alias 别名
  25. * @param null $model model
  26. * @param bool $isAL 是否起别名,默认执行
  27. * @return $this
  28. */
  29. public static function PreExercisesWhere($alias = '', $model = null, $isAL = false)
  30. {
  31. if (is_null($model)) $model = new self();
  32. if ($alias) {
  33. $isAL || $model = $model->alias($alias);
  34. $alias .= '.';
  35. }
  36. return $model->where(["{$alias}is_del" => 0, "{$alias}is_show" => 1, "{$alias}status" => 1]);
  37. }
  38. /**练习试卷列表
  39. * @param int $page
  40. * @param int $limit
  41. * @param $tid
  42. * @return array
  43. */
  44. public static function getTestPaperExercisesList($type, $page, $limit, $pid, $tid, $search)
  45. {
  46. $model = self::PreExercisesWhere();
  47. if ($tid) {
  48. $model = $model->where(['tid' => $tid]);
  49. } else if ($pid && !$tid) {
  50. $tids = TestPaperCategory::where('pid', $pid)->column('id');
  51. $model = $model->where('tid', 'in', $tids);
  52. }
  53. if ($search) $model = $model->where('title', 'LIKE', "%$search%");
  54. $list = $model->where('type', $type)->order('sort desc,id desc')->page($page, $limit)->select();
  55. $list = count($list) ? $list->toArray() : [];
  56. return $list;
  57. }
  58. /**练习试卷列表
  59. * @param int $page
  60. * @param int $limit
  61. * @param $tid
  62. * @return array
  63. */
  64. public static function getMerTestPaperList($mer_id,$type, $page, $limit)
  65. {
  66. $list = [];
  67. if (!$mer_id) return $list;
  68. $model = self::PreExercisesWhere();
  69. $list = $model->where(['type'=>$type,'mer_id'=>$mer_id])->order('sort desc,id desc')->page($page, $limit)->select();
  70. $list = count($list) ? $list->toArray() : [];
  71. return $list;
  72. }
  73. }