Gifts.php
4.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
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 Gifts extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $user_id = '';//token存贮user_id
protected $normal = '';//商品正常状态,1:下架
public function _initialize()
{
parent::_initialize();
$this->normal = config('site.goods_status');
$this->user_id = $this->auth->getUserId();
}
/**
* @ApiTitle (礼品列表)
* @ApiSummary (礼品列表)
* @ApiMethod (GET)
* @ApiRoute (/api/gifts/getGiftsList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553836021",
"data": {
"my_score": 99,
"data": [
{
"id": 1,
"title": "礼品标题1",//礼品名称
"score": 100,//礼品积分
"images": "/uploads/20190319/74cf9cbb633386b889f15a9797169b7d.jpg,/uploads/20190319/4e98e7e8bb1fa28db4f7a49df3159938.jpg"
},
{
"id": 2,
"title": "礼品标题2",
"score": 100,
"images": "/uploads/20190319/74cf9cbb633386b889f15a9797169b7d.jpg,/uploads/20190319/4e98e7e8bb1fa28db4f7a49df3159938.jpg"
}
]
}
})
*/
public function getGiftsList(){
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());
}
$myScore = Db::table('gc_user')
->where(['id'=>$this->user_id,'status'=>'normal'])
->field('score')
->find();
$data = Db::table('gc_gift')
->where(['status'=>$this->normal])
->page($page,$limit)
->field('id,title,score,images')
->order('id desc')
->select();
$this->success('成功', ['my_score'=>$myScore['score'],'data'=>$data]);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (礼品详情)
* @ApiSummary (礼品详情)
* @ApiMethod (GET)
* @ApiRoute (/api/gifts/giftsDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="礼品id")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553777266",
"data":[
{
"id": 1,
"title": "礼品标题1",//礼品名称
"stock": 1000,//礼品库存
"score": 100,//礼品所需积分
"description": " ★注:各种废旧五金、电子、塑胶等",//礼品详情
"images": "/uploads/20190319/74cf9cbb633386b889f15a9797169b7d.jpg,/uploads/20190319/4e98e7e8bb1fa28db4f7a49df3159938.jpg"
}
]
})
*/
public function giftsDetail(){
if($this->request->isGet()){
$gifts_id = $this->request->get('id');//礼品id
$rule = config('site.goods');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$gifts_id])) {
$this->error($validate->getError());
}
$data = Db::table('gc_gift')
->where(['id'=>$gifts_id,'status'=>$this->normal])
->field('id,title,stock,score,description,images')
->select();
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
}