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'); } }