Smessages.php
4.5 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 系统消息接口**
*/
class Smessages extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $user_id = '';//token存贮user_id
protected $read = 1;//是否已读 1:已读
public function _initialize()
{
parent::_initialize();
$this->user_id = $this->auth->getUserId();
}
/**
* @ApiTitle (系统消息列表)
* @ApiSummary (系统消息列表)
* @ApiMethod (GET)
* @ApiRoute (/api/smessages/getMessageList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553777266",
"data":{
"id": 1,
"title": "您有一个系统消息提示,请及时查看。",//提现系统消息标题
"type": 1,//类型 0:充值,1:提现
"is_read": 0 //系统消息是否已读 0:未读,1:已读
},
{
"id": 2,
"title": "您有一个系统消息提示,请及时查看。",//提现系统消息标题
"type": 1,//类型 0:充值,1:提现
"is_read": 0 //系统消息是否已读 0:未读,1:已读
},
})
*/
public function getMessageList(){
if($this->request->isGet()){
$page = $this->request->get('page');//分页页码
$limit = config('site.page_limit');//分页限制数量
$rule = config('site.gift_pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$withdrawal = config('site.withdrawal');
$data = Db::table('gc_message')
->alias('m')
->join('gc_account a','m.account_id = a.id','LEFT')
->where(['a.uid'=>$this->user_id,'a.type'=>$withdrawal])
->page($page,$limit)
->field('m.id,m.title,m.type,m.is_read')
->select();
$this->success('成功',$data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (系统消息详情)
* @ApiSummary (系统消息详情)
* @ApiMethod (GET)
* @ApiRoute (/api/smessages/messageDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1554262435",
"data": [
{
"id": 1,
"title": "您有一个系统消息提示,请及时查看。",
"type": 1,//类型 0:充值,1:提现
"money": 0.01,//充值或提现金额
"createtime": "2019-04-03 11:00:29"//时间
}
]
})
*/
public function messageDetail(){
if($this->request->isGet()){
$message_id = $this->request->get('id');//商品id
$rule = config('site.goods');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$message_id])) {
$this->error($validate->getError());
}
$withdrawal = config('site.withdrawal');
$data = Db::table('gc_message')
->alias('m')
->join('gc_account a','m.account_id = a.id','LEFT')
->where(['m.id'=>$message_id,'a.uid'=>$this->user_id,'a.type'=>$withdrawal])
->field('m.id,m.title,m.type,a.money,m.createtime')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
}
Db::table('gc_message')
->where(['id'=>$message_id])
->update(['is_read'=>$this->read,'readtime'=>time()]);
$this->success('成功',$data);
}else{
$this->error('请求方式错误');
}
}
}