LikeUniversity.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace app\api\model;
use think\Model;
class LikeUniversity extends Model
{
protected $name = 'like_university';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 获取用户关注的大学
public function listByUserId($userId, $page, $size)
{
return $this
->alias('a')
->field('a.university_id, a.user_id, b.*')
->join('university b', 'a.university_id = b.id')
->where(['a.user_id' => ['=', $userId], 'b.show_switch' => ['=', 1], 'b.deletetime' => null])
->useSoftDelete('a.'.$this->deleteTime)
->order('a.'.$this->createTime, 'desc')
->page($page, $size)
->select();
}
// 获取是否关注
public function infoById($userId, $universityId)
{
return $this->where(['university_id' => ['=', $universityId], 'user_id' => ['=', $userId]])->useSoftDelete($this->deleteTime)->find();
}
// 修改一条数据
public function updateOne($id, $data)
{
return $this->where(['id' => ['=', $id]])->update($data);
}
// 添加一条数据
public function addOne($data)
{
return $this->insert($data);
}
}