Order.php
5.7 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/7/10
* Time: 17:32
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 开通会员
*/
class Order extends Api
{
protected $noNeedLogin = [''];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (收款码图片)
* @ApiSummary (收款码图片)
* @ApiMethod (POST)
* @ApiRoute (/api/order/payimage)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="type", type="inter", required=true, description="类型1微信2支付")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"image": //图片地址
}
]
}
})
*/
public function payimage()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$user_id = $this->auth->id;
$type = $this->request->param('type');
if(empty($type)){
$this->error('缺少必要参数');
}
$data = Db::name('payimage')->where('id',1)->find();
if($type == 1){
$this->success('success',['image'=>$qiniu.$data['image']]);
}else{
$this->success('success',['image'=>$qiniu.$data['aliimage']]);
}
}
/**
* @ApiTitle (开通会员订单)
* @ApiSummary (开通会员订单)
* @ApiMethod (POST)
* @ApiRoute (/api/order/index)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="type", type="inter", required=true, description="支付方式1微信2支付宝")
* @ApiParams (name="order_num", type="inter", required=true, description="订单后四位")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"order_id"://订单id
}
]
}
})
*/
public function index()
{
$user_id = $this->auth->id;
$type = $this->request->param('type');
$order_num = $this->request->param('order_num');
if(empty($type) || empty($order_num)){
$this->error('缺少必要参数');
}
$vipdaynum = Db::name('vipdaynum')->where('id',1)->value('day_num');
$res['user_id'] = $user_id;
$res['order_num'] = $order_num;
$res['type'] = $type;
$res['daynum'] = $vipdaynum;
$res['createtime'] = time();
$res['updatetime'] = time();
$data = Db::name('viporder')->insertGetId($res);
if(empty($data)){
$this->error('开通失败');
}else{
$this->success('开通成功',['oder_id'=>$data]);
}
}
/**
* @ApiTitle (我的订阅)
* @ApiSummary (我的订阅)
* @ApiMethod (POST)
* @ApiRoute (/api/order/myattention)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://订阅ID
"user_id": //用户id,
"to_user_id"://订阅的用户id
"createtime"://创建时间
"username"://用户名
"avatar"://头像
"createtime"://创建时间
"updatetime"://修改时间
}
})
*/
public function myattention()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$user_id = $this->auth->id;
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data = Db::name('subscribe')
->alias('a')
->join('user b','a.to_user_id = b.id')
->where('a.user_id',$user_id)
->field('a.*,b.username,b.avatar')
->order('a.id desc')
->page($page,$pageNum)
->select();
foreach ($data as &$v){
$v['avatar'] = $qiniu.$v['avatar'];
}
$this->success('success',$data);
}
/**
* @ApiTitle (订阅/取消订阅)
* @ApiSummary (订阅/取消订阅)
* @ApiMethod (POST)
* @ApiRoute (/api/order/ding)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="to_user_id", type="inter", required=true, description="订阅人id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
}
})
*/
public function ding()
{
$user_id = $this->auth->id;
$to_user_id = $this->request->param('to_user_id');
if(empty($to_user_id)){
$this->error('缺少必要参数');
}
$data = Db::name('subscribe')->where('user_id',$user_id)->where('to_user_id',$to_user_id)->find();
if(empty($data)){
$res['user_id'] = $user_id;
$res['to_user_id'] = $to_user_id;
$res['createtime'] = time();
$res['updatetime'] = time();
$arr = Db::name('subscribe')->insertGetId($res);
if(empty($arr)){
$this->error('订阅失败');
}else{
$this->success('订阅成功');
}
}else{
$arr = Db::name('subscribe')->where('user_id',$user_id)->where('to_user_id',$to_user_id)->delete();
if(empty($arr)){
$this->error('取消订阅失败');
}else{
$this->success('取消订阅成功');
}
}
}
}