LookArticle.php
1.6 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
51
52
53
54
55
<?php
namespace app\api\model;
use think\Model;
class LookArticle extends Model
{
protected $name = 'look_article';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 是否查看文章
public function infoById($userId, $articleId)
{
return $this->where(['user_id' => ['=', $userId], 'article_id' => ['=', $articleId]])->useSoftDelete($this->deleteTime)->find();
}
// 修改一个数据
public function updateOne($id, $data)
{
return $this->where(['id' => ['=', $id]])->update($data);
}
// 添加一个数据
public function addOne($data)
{
return $this->insert($data);
}
// 修改一些数据
public function updateSomeByUserId($userId, $data)
{
return $this->where(['user_id' => ['=', $userId]])->update($data);
}
// 获取用户的浏览历史
public function listById($userId, $page, $size)
{
return $this
->alias('a')
->field('a.article_id, a.user_id, 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, c.*')
->join('student b', 'a.user_id = b.user_id')
->join('article c', 'a.article_id = c.id')
->where(['a.user_id' => ['=', $userId]])
->useSoftDelete('a.'.$this->deleteTime)
->page($page, $size)
->order('a.'.$this->createTime, 'desc')
->select();
}
}