Person.php
10.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\admin\model\Bank;
use app\admin\model\off\Line;
use think\Db;
use think\Validate;
/**
* 个人信息接口**
*/
class Person extends Api
{
protected $noNeedLogin = ['getScore'];
protected $noNeedRight = ['getScore'];
protected $person = 0;//个人
protected $company = 1;//企业
protected $user_id = '';//token存贮user_id
public function _initialize()
{
parent::_initialize();
$this->user_id = $this->auth->getUserId();
}
/**
* @ApiTitle (获取会员信息)
* @ApiSummary (获取会员信息)
* @ApiMethod (GET)
* @ApiRoute (/api/person/getUserInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553838039",
"data": {
"id": 26,
"username": "风起时呀",//用户名
"mobile": "",//联系方式
"type": 0,//类型 0:个人 1:企业
"address": "", //上门地址
"id_num": "",//身份证号
"id_img": "",//身份证件
"company_name": "",//公司名字
"license_num": "",//公司编码
"license_img": ""//公司营业执照
"money":100//账户余额
}
})
*/
public function getUserInfo(){
if($this->request->isGet()){
$data = Db::table('gc_user')
->where(['id'=>$this->user_id])
->field('id,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money')
->find();
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (修改会员信息)
* @ApiSummary (修改会员信息)
* @ApiMethod (POST)
* @ApiRoute (/api/person/updateInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="username", type="string", required=true, description="用户名(姓名)")
* @ApiParams (name="mobile", type="string", required=true, description="联系电话")
* @ApiParams (name="address", type="string", required=true, description="上门地址")
* @ApiParams (name="type", type="integer", required=true, description="用户类型(0:个人,1企业)")
* @ApiParams (name="id_num", type="string", required=true, description="身份证号(个人必须)")
* @ApiParams (name="id_img", type="string", required=true, description="身份证件(个人必须)")
* @ApiParams (name="company_name", type="string", required=true, description="公司名称(企业必须)")
* @ApiParams (name="license_num", type="string", required=true, description="公司编号(企业必须)")
* @ApiParams (name="license_img", type="string", required=true, description="公司营业执照(企业必须)")
* @ApiReturn({
"code": 1,
"msg": "保存成功",
"time": "1553838137",
"data": null
})
*/
public function updateInfo(){
if ($this->request->isPost()) {
$raw_data = $this->request->post();
if(empty($raw_data['type'])){
$this->error('请选择用户类型');
}
$type = $raw_data['type'];
if($type == $this->person){
//验证类型为个人的数据
$rule = config('site.person');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($raw_data)) {
$this->error($validate->getError());
}
}else if($type == $this->company){
//验证类型为企业的数据
$company_rule = config('site.company');
$company_validate = new Validate($company_rule['rule'],$company_rule['msg']);
if (!$company_validate->check($raw_data)) {
$this->error($company_validate->getError());
}
}else{
$this->error('用户类型不合法');
}
$user = new \app\admin\model\User();
$data = $user->where(['id'=>$this->user_id])->update($raw_data);
if($data){
$this->success('保存成功');
}else{
$this->error('保存失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (上传文件)
* @ApiSummary (上传文件)
* @ApiMethod (POST)
* @ApiRoute (/api/person/upload)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="image", type="file", required=true, description="上传文件(图片)")
* @ApiReturn ({
"code": 1,
"msg": "上传成功",
"time": "1553777266",
"data":[
{
"/uploads/20190328/0179b6b111307ef8be3c832ef808e1c1.jpg,/uploads/20190328/42bbc2f2692023d43957c3ee0b580443.jpg"
}
]
})
*/
public function upload(){
// 获取表单上传文件
$files = request()->file('images');
if (empty($files)) {
$this->error('未检出文件上传');
}
$countFile = count($files);
if($countFile > 9){
$this->error('最多上传9张图片');
}
$date = date('Ymd',time());
$images = '';
foreach($files as $file){
//移动到框架应用根目录/public/uploads/ 目录下
//允许文件大小200k
$info = $file->validate(['size'=>204800,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
if($info){
$images .= '/uploads/'.$date.'/'.$info->getFilename().',';
}else{
// 上传失败获取错误信息
$this->error($file->getError());
}
}
$this->success('上传成功',rtrim($images,','));
}
/**
* @ApiTitle (账单明细)
* @ApiSummary (账单明细)
* @ApiMethod (POST)
* @ApiRoute (/api/person/accountDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1554270371",
"data": [
{
"id": 1,
"type": 0,//类型 0:充值 1:提现
"money": 0.01,//充值或提现金额
"createtime": "2019-04-03 13:03:57"//时间
}
]
})
*/
public function accountDetail(){
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());
}
$data = Db::table('gc_account')
->where(['uid'=>$this->user_id])
->page($page,$limit)
->field('id,type,money,createtime')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
}
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (绑定银行卡)
* @ApiSummary (绑定银行卡)
* @ApiMethod (POST)
* @ApiRoute (/api/person/bindBank)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="bank_num", type="integer", required=true, description="银行卡号")
* @ApiParams (name="open_bank", type="string", required=true, description="开会行")
* @ApiReturn ({
"code": 1,
"msg": "保存成功",
"time": "1554270371",
"data": null
})
*/
public function bindBank(){
if($this->request->isPost()) {
$bank_num = $this->request->post('bank_num');//银行卡号
$open_bank = $this->request->post('open_bank');//开户行
$rule = config('site.bank');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['bank_num'=>$bank_num,'open_bank'=>$open_bank])) {
$this->error($validate->getError());
}
$bank = new Bank();
$data = $bank->where(['uid'=>$this->user_id,'bank_num'=>$bank_num])->find();
if($data){
$this->error('不能重复绑定');
}
$data = $bank::create(['uid'=>$this->user_id,'bank_num'=>$bank_num,'open_bank'=>$open_bank]);
if($data){
$this->success('保存成功');
}else{
$this->error('保存失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* 根据规则增加积分
* @param $share_uid
* @param $type
* @return bool
*/
public function getScore($share_uid,$type){
$score = config('site.'.$type);
$offlineModel = new Line();
//此处判断不能相互成为下线(你成为我的下线,我就不能成为你的下线)
$offlineModel->where(['off_uid'=>$share_uid,'uid'=>$this->user_id])->find();
//分享人是自己无效
if($share_uid != $this->user_id){
if(!$offlineModel){
//给分享用户增加积分
$userModel = new \app\admin\model\User();
$userModel->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score);
//成为分享用户的下线
$offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id]);
}
}
}
}