Message.php
4.8 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace app\api\controller;
use think\Db;
use think\Exception;
/**
* 消息相关
* @package app\api\controller
*/
class Message extends BaseApi
{
protected $noNeedLogin = '';
protected $noNeedRight = '*';
/**
* 获取用户总的未读消息
* @ApiTitle (获取用户总的未读消息)
* @ApiMethod (POST)
* @ApiRoute (/api/message/getIsReadNum)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "请求数量成功",
"time": "1609323269",
"data": "获取用户总的未读消息"
})
*/
public function getIsReadNum(){
$count = model('message')->where('user_id',$this->auth->id)->where('is_read',0)->count();
$this->success('请求数量成功',$count);
}
/**
* 分类获取用户的未读消息
* @ApiTitle (分类获取用户的未读消息)
* @ApiMethod (POST)
* @ApiRoute (/api/message/getTypeIsReadNum)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "请求数量成功",
"time": "1609323546",
"data": {
"one": "收藏消息",
"two": "动态消息",
"three": "礼物消息",
"four": "通知消息"
}
})
*/
public function getTypeIsReadNum(){
$data = [];
$data['one'] = model('message')->where('status',1)->where('user_id',$this->auth->id)->where('is_read',0)->count();
$data['two'] = model('message')->where('status',2)->where('user_id',$this->auth->id)->where('is_read',0)->count();
$data['three'] = model('message')->where('status',3)->where('user_id',$this->auth->id)->where('is_read',0)->count();
$data['four'] = model('message')->where('status',4)->where('user_id',$this->auth->id)->where('is_read',0)->count();
$this->success('请求数量成功',$data);
}
/**
* 获取列表消息
* @ApiTitle (获取列表消息)
* @ApiMethod (POST)
* @ApiRoute (/api/message/getMessageList)
* @ApiParams (name="status", type="string", required=true, description="1=收藏2=动态3=礼物4=通知")
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "请求数据成功",
"time": "1609324842",
"data": [
{
"id": 4,
"user_id": "收到消息用户ID",
"in_user_id": "用户ID",
"avatar": "头像",
"nickname": "署名",
"title": "消息标题",
"brief": "消息简介",
"content": "消息内容",
"price": "价格",
"is_read": "是否已读:0=未读,1=已读",
"status": "类别:1=收藏,2=动态,3=礼物,4=通知",
"is_stu": "样式:1=动态,2=作品,3=墨宝档案,4=展览",
"key_id": "被动主键ID",
"createtime": "2020-12-30 18:39:32",
"updatetime": "2020-12-30 18:39:32"
}
]
})
*/
public function getMessageList(){
//1.获取状态
$data = $this->get_data_array([
['status','状态不能为空'],
['page','分页次数不能为空'],
['num','分页数量不能为空'],
]);
//2.查询数据
$res = model('message')
->where('status',$data['status'])
->where('user_id',$this->auth->id)
->where('is_read',0)
->order('createtime','desc')
->page($data['page'],$data['num'])
->select();
//3.将数据变为已读
model('message')
->where('status',$data['status'])
->where('user_id',$this->auth->id)
->where('is_read',0)
->update(['is_read'=>1]);
$this->success('请求数据成功',$res);
}
}