作者 杨育虎

ok

... ... @@ -76,8 +76,10 @@ class Article extends Api
public function getArticleList()
{
$myId = $this->auth->id;
$myId = 25;
$universityId = $this->request->param('university_id', 0, 'int');
$universityId = 892;
$collegeId = $this->request->param('college_id', 0, 'int');
... ... @@ -97,22 +99,18 @@ class Article extends Api
$type = bcadd($studentInfo['vip_level'], 1, 0);
$schoolIds = [];
// 获取学长
if($type = 1) {
if($type == 1) {
$schoolIds = [$studentInfo['school_id']];
} elseif ($type = 2) {
} elseif ($type == 2) {
$school = new School();
$schoolInfo = $school->infoById($studentInfo['school_id']);
$schoolIds = $school->listByCityId($schoolInfo['city_id']);
} elseif ($type = 3) {
} elseif ($type == 3) {
$school = new School();
$schoolInfo = $school->infoById($studentInfo['school_id']);
$schoolIds = $school->listByProvinceId($schoolInfo['province_id']);
}
if($schoolIds) {
$where['b.school_id'] = ['in', $schoolIds];
}
if($universityId) {
$where['b.university_id'] = ['=', $universityId];
}
... ... @@ -129,9 +127,11 @@ class Article extends Api
$where['a.user_id'] = ['=', $userId];
}
$where['a.deletetime'] = null;
// 获取文章
$article = new ArticleModel();
$articleList = $article->listByWhere($where, $page, $size, $studentInfo['school_id']);
$articleList = $article->listByWhere($where, $page, $size, $schoolIds);
if(!$articleList) {
$this->success('获取大学或学院的文章成功', $articleList);
}
... ...
... ... @@ -17,18 +17,17 @@ class Article extends Model
// 根据条件获取文章
public function listByWhere($where, $page, $size, $schoolId)
public function listByWhere($where, $page, $size, $schoolIds)
{
$schoolIds = implode(',', $schoolIds);
$data = $this
->alias('a')
->field('a.*, b.user_id, b.level, b.nickname, b.head_image, b.school_id, b.subject_ids, b.up_id, b.college_id, b.university_id, b.graduated_id, b.starttime, b.endtime, b.show_switch, b.email, b.vip_level, b.vip_endtime')
->join('student b', 'a.user_id = b.user_id')
->where(function ($query) use ($schoolId) {
$query
->where(' (a.show_type = 1 and b.school_id = '.$schoolId.') or a.show_type = 2');
})
->where($where)
->useSoftDelete('a.'.$this->deleteTime)
->where(' (b.school_id in ('.$schoolIds.') and a.show_type = 1) or a.show_type = 2 ')
// ->where(['b.school_id' => ['in', $schoolIds], 'a.show_type' => ['=', 1]])
// ->whereor('1=1')
->order('a.createtime', 'desc')
->page($page, $size)
->select();
... ...