|
@@ -3,12 +3,100 @@ |
|
@@ -3,12 +3,100 @@ |
3
|
|
3
|
|
4
|
namespace app\api\controller;
|
4
|
namespace app\api\controller;
|
5
|
|
5
|
|
|
|
6
|
+use think\Db;
|
|
|
7
|
+use think\Exception;
|
|
|
8
|
+
|
6
|
/**
|
9
|
/**
|
7
|
* 消息相关
|
10
|
* 消息相关
|
8
|
* @package app\api\controller
|
11
|
* @package app\api\controller
|
9
|
*/
|
12
|
*/
|
10
|
class Message extends BaseApi
|
13
|
class Message extends BaseApi
|
11
|
{
|
14
|
{
|
12
|
-
|
15
|
+ protected $noNeedLogin = '';
|
|
|
16
|
+ protected $noNeedRight = '*';
|
|
|
17
|
+
|
|
|
18
|
+ /**
|
|
|
19
|
+ * 获取用户总的未读消息
|
|
|
20
|
+ * @ApiTitle (获取用户总的未读消息)
|
|
|
21
|
+ * @ApiMethod (POST)
|
|
|
22
|
+ * @ApiRoute (/api/message/getIsReadNum)
|
|
|
23
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
24
|
+ * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
25
|
+ * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
26
|
+ * @ApiReturn ({
|
|
|
27
|
+ "code": 1,
|
|
|
28
|
+ "msg": "请求数量成功",
|
|
|
29
|
+ "time": "1609323269",
|
|
|
30
|
+ "data": "获取用户总的未读消息"
|
|
|
31
|
+ })
|
|
|
32
|
+ */
|
|
|
33
|
+ public function getIsReadNum(){
|
|
|
34
|
+ $count = model('message')->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
35
|
+ $this->success('请求数量成功',$count);
|
|
|
36
|
+ }
|
|
|
37
|
+ /**
|
|
|
38
|
+ * 分类获取用户的未读消息
|
|
|
39
|
+ * @ApiTitle (分类获取用户的未读消息)
|
|
|
40
|
+ * @ApiMethod (POST)
|
|
|
41
|
+ * @ApiRoute (/api/message/getTypeIsReadNum)
|
|
|
42
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
43
|
+ * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
44
|
+ * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
45
|
+ * @ApiReturn ({
|
|
|
46
|
+ "code": 1,
|
|
|
47
|
+ "msg": "请求数量成功",
|
|
|
48
|
+ "time": "1609323546",
|
|
|
49
|
+ "data": {
|
|
|
50
|
+ "one": "收藏消息",
|
|
|
51
|
+ "two": "动态消息",
|
|
|
52
|
+ "three": "礼物消息",
|
|
|
53
|
+ "four": "通知消息"
|
|
|
54
|
+ }
|
|
|
55
|
+ })
|
|
|
56
|
+ */
|
|
|
57
|
+ public function getTypeIsReadNum(){
|
|
|
58
|
+ $data = [];
|
|
|
59
|
+ $data['one'] = model('message')->where('status',1)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
60
|
+ $data['two'] = model('message')->where('status',2)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
61
|
+ $data['three'] = model('message')->where('status',3)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
62
|
+ $data['four'] = model('message')->where('status',4)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
63
|
+ $this->success('请求数量成功',$data);
|
|
|
64
|
+ }
|
|
|
65
|
+ /**
|
|
|
66
|
+ * 获取列表消息
|
|
|
67
|
+ * @ApiTitle (获取列表消息)
|
|
|
68
|
+ * @ApiMethod (POST)
|
|
|
69
|
+ * @ApiRoute (/api/message/getMessageList)
|
|
|
70
|
+ * @ApiParams (name="status", type="string", required=true, description="1=收藏2=动态3=礼物4=通知")
|
|
|
71
|
+ * @ApiParams (name="page", type="integer", required=true, description="分页次数")
|
|
|
72
|
+ * @ApiParams (name="num", type="integer", required=true, description="分页数量")
|
|
|
73
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
74
|
+ * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
75
|
+ * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
76
|
+ * @ApiReturn ()
|
|
|
77
|
+ */
|
|
|
78
|
+ public function getMessageList(){
|
|
|
79
|
+ //1.获取状态
|
|
|
80
|
+ $data = $this->get_data_array([
|
|
|
81
|
+ ['status','状态不能为空'],
|
|
|
82
|
+ ['page','分页次数不能为空'],
|
|
|
83
|
+ ['num','分页数量不能为空'],
|
|
|
84
|
+ ]);
|
|
|
85
|
+ //2.查询数据
|
|
|
86
|
+ $res = model('message')
|
|
|
87
|
+ ->where('status',$data['status'])
|
|
|
88
|
+ ->where('user_id',$this->auth->id)
|
|
|
89
|
+ ->where('is_read',0)
|
|
|
90
|
+ ->order('createtime','desc')
|
|
|
91
|
+ ->page($data['page'],$data['num'])
|
|
|
92
|
+ ->select();
|
|
|
93
|
+ //3.将数据变为已读
|
|
|
94
|
+ model('message')
|
|
|
95
|
+ ->where('status',$data['status'])
|
|
|
96
|
+ ->where('user_id',$this->auth->id)
|
|
|
97
|
+ ->where('is_read',0)
|
|
|
98
|
+ ->update(['is_read'=>1]);
|
|
|
99
|
+ $this->success('请求数据成功',$res);
|
|
|
100
|
+ }
|
13
|
|
101
|
|
14
|
} |
102
|
} |