You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.4 KiB
97 lines
3.4 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\web\model\topic;
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
use app\web\model\topic\TestPaperCategory;
|
|
|
|
/**
|
|
* 试卷列表 Model
|
|
* Class TestPaper
|
|
*/
|
|
class TestPaper extends ModelBasic
|
|
{
|
|
use ModelTrait;
|
|
|
|
/**
|
|
* 设置专题显示条件
|
|
* @param string $alias 别名
|
|
* @param null $model model
|
|
* @param bool $isAL 是否起别名,默认执行
|
|
* @return $this
|
|
*/
|
|
public static function PreExercisesWhere($alias = '', $model = null, $isAL = false)
|
|
{
|
|
if (is_null($model)) $model = new self();
|
|
if ($alias) {
|
|
$isAL || $model = $model->alias($alias);
|
|
$alias .= '.';
|
|
}
|
|
return $model->where(["{$alias}is_del" => 0, "{$alias}is_show" => 1, "{$alias}status" => 1]);
|
|
}
|
|
|
|
/**条件处理
|
|
* @param $type
|
|
* @param $pid
|
|
* @param $tid
|
|
* @param $search
|
|
* @return TestPaper
|
|
*/
|
|
public static function setWhere($type,$pid, $tid, $search)
|
|
{
|
|
$model = self::PreExercisesWhere();
|
|
if ($tid) {
|
|
$model = $model->where(['tid' => $tid]);
|
|
} else if ($pid && !$tid) {
|
|
$tids = TestPaperCategory::where('pid', $pid)->column('id');
|
|
$model = $model->where('tid', 'in', $tids);
|
|
}
|
|
if ($search) $model = $model->where('title', 'LIKE', "%$search%");
|
|
return $model->where('type', $type);
|
|
}
|
|
|
|
/**练习试卷列表
|
|
* @param int $page
|
|
* @param int $limit
|
|
* @param $tid
|
|
* @return array
|
|
*/
|
|
public static function getTestPaperExercisesList($type, $page, $limit, $pid, $tid, $search)
|
|
{
|
|
$model=self::setWhere($type,$pid, $tid, $search);
|
|
$data = $model->order('sort desc,id desc')->page($page, $limit)->select();
|
|
$data = count($data) ? $data->toArray() : [];
|
|
foreach($data as &$item){
|
|
$item['answer'] = $item['fake_sales'] + $item['answer'];
|
|
}
|
|
$count = self::setWhere($type,$pid, $tid, $search)->count();
|
|
return compact('data', 'count');
|
|
}
|
|
/**练习试卷列表
|
|
* @param int $page
|
|
* @param int $limit
|
|
* @param $tid
|
|
* @return array
|
|
*/
|
|
public static function getMerTestPaperList($mer_id,$type, $page, $limit)
|
|
{
|
|
$data = [];
|
|
$count = 0;
|
|
if (!$mer_id) return compact('data', 'count');
|
|
$model = self::PreExercisesWhere();
|
|
$data = $model->where(['type'=>$type,'mer_id'=>$mer_id])->order('sort desc,id desc')->page($page, $limit)->select();
|
|
$data = count($data) ? $data->toArray() : [];
|
|
$count = self::PreExercisesWhere()->where(['type'=>$type,'mer_id'=>$mer_id])->count();
|
|
return compact('data', 'count');
|
|
}
|
|
}
|
|
|