0, 'relationship' => $relationship, 'relationship_id' => $relationship_id]); } public static function getSpecialJion($relationship_id, $relationship) { return self::alias('r')->join('Special s', 'r.relation_id=s.id') ->where(['r.is_del' => 0, 's.is_show' => 1, 's.is_del' => 0, 'r.relationship' => $relationship, 'r.relationship_id' => $relationship_id]) ->field('s.type,s.title,s.is_light,s.light_type,s.image,s.id,r.sort,r.id as rid,r.relationship,r.relationship_id'); } /**获取试题关联的专题 * @param $id */ public static function getQuestionsRelationSpecial($relationship_id, $relationship) { $data = self::getSpecialJion($relationship_id, $relationship)->order('r.sort DESC,rid DESC')->select(); $data = count($data) > 0 ? $data->toArray() : []; $count = self::getSpecialJion($relationship_id, $relationship)->count(); return compact('data', 'count'); } /**关联 * @param $id * @param $special_ids * @param $relationship */ public static function setRelations($id, $ids, $relationship) { $ids = explode(',', $ids); if (count($ids) <= 0) return false; foreach ($ids as $key => $value) { $data['relationship'] = $relationship; $data['relationship_id'] = $id; $data['relation_id'] = $value; if (self::be($data)) continue; $data['add_time'] = time(); self::set($data); } return true; } /**修改排序 * @param $id * @param $special_id * @param $value */ public static function updateRelationSort($id, $special_id, $relationship, $value) { return self::where(['is_del' => 0, 'relationship' => $relationship, 'relationship_id' => $id, 'relation_id' => $special_id])->update(['sort' => $value]); } /** * @param $id * @param $special_id * @param $relationship */ public static function delRelation($id, $special_id, $relationship) { return self::where(['is_del' => 0, 'relationship' => $relationship, 'relationship_id' => $id, 'relation_id' => $special_id])->delete(); } public static function getTestPaperJion($relationship_id, $relationship) { return self::alias('r')->join('TestPaper t', 'r.relation_id=t.id') ->where(['r.is_del' => 0, 't.is_show' => 1, 't.is_del' => 0, 'r.relationship' => $relationship, 'r.relationship_id' => $relationship_id]) ->field('t.type,t.title,t.id,r.sort,r.id as rid,r.relationship,r.relationship_id'); } /**获取专题关联的考试或练习 * @param $id * @param $relationship */ public static function getRelationTestPaper($id, $relationship, $page, $limit) { $data = self::getTestPaperJion($id, $relationship)->page($page, $limit)->order('r.sort DESC,rid DESC')->select(); $data = count($data) > 0 ? $data->toArray() : []; foreach ($data as $key => &$value) { if ($value['type'] == 1) { $value['types'] = '练习'; } else { $value['types'] = '考试'; } } $count = self::getTestPaperJion($id, $relationship)->count(); return compact('data', 'count'); } public static function getDataDownloadJion($relationship_id, $relationship) { return self::alias('r')->join('DataDownload d', 'r.relation_id=d.id') ->where(['r.is_del' => 0, 'd.is_show' => 1, 'd.is_del' => 0, 'r.relationship' => $relationship, 'r.relationship_id' => $relationship_id]) ->field('d.title,d.id,r.sort,r.id as rid,r.relationship,r.relationship_id'); } /**获取专题关联的资料 * @param $id * @param $relationship */ public static function getRelationDataDownload($id, $relationship, $page, $limit) { $data = self::getDataDownloadJion($id, $relationship)->page($page, $limit)->order('r.sort DESC,rid DESC')->select(); $data = count($data) > 0 ? $data->toArray() : []; $count = self::getDataDownloadJion($id, $relationship)->count(); return compact('data', 'count'); } }