User.php
6.8 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Validate;
use think\Db;
/**
* 用户接口
*/
class User extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (用户接口-基本信息)
* @ApiSummary (基本信息)
* @ApiMethod (POST)
* @ApiRoute (/api/User/EssentialInformation)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
"data": [
{
"con": [
{
"username": "用户名",
"mobile": "手机号",
"email": "邮箱"
}
]
},
{
"team": [
{
"company_name": "公司名",
"credit": "公司信用代码",
"company_address": "公司地址",
"address_con": "公司详细地址",
"invoice_address": "开票地址",
"bank_name": "银行名称",
"bank_num": "银行账号",
"company_tel": "公司电话",
"type": "类型",
"industry": "行业"
}
]
}
]
})
*/
public function EssentialInformation()
{
$user_id = $this->is_token($this->request->header());
$user_con = Db::name('user')->where(['id' => $user_id])->find();
$is_team = Db::name('team')->where(['user_id' => $user_id])->find();
$return['con'] = [
'username' => $user_con['username'],
'mobile' => $user_con['mobile'],
'email' => $user_con['email']
];
if (!empty($is_team)) {
$team = \db('company')
->alias('a')
->join('type b', 'b.id=a.type_id')
->join('industry c', 'c.id=a.industry_id')
->field('a.company_name,a.credit,a.company_address,a.address_con,a.invoice_address,a.bank_name,a.bank_num,a.company_tel,b.type,c.industry')
->where(['a.id' => $is_team['company_id']])
->find();
$return['team'] = [
'company_name' => $team['company_name'],
'credit' => $team['credit'],
'company_address' => $team['company_address'],
'address_con' => $team['address_con'],
'invoice_address' => $team['invoice_address'],
'bank_name' => $team['bank_name'],
'bank_num' => $team['bank_num'],
'company_tel' => $team['company_tel'],
'type' => $team['type'],
'industry' => $team['industry'],
];
} else {
$is_company = Db::name('company')->where(['company_holder' => $user_id])->find();
$team = \db('company')
->alias('a')
->join('type b', 'b.id=a.type_id')
->join('industry c', 'c.id=a.industry_id')
->field('a.company_name,a.credit,a.company_address,a.address_con,a.invoice_address,a.bank_name,a.bank_num,a.company_tel,b.type,c.industry')
->where(['a.id' => $is_company['id']])
->find();
$return['team'] = [
'company_name' => $team['company_name'],
'credit' => $team['credit'],
'company_address' => $team['company_address'],
'address_con' => $team['address_con'],
'invoice_address' => $team['invoice_address'],
'bank_name' => $team['bank_name'],
'bank_num' => $team['bank_num'],
'company_tel' => $team['company_tel'],
'type' => $team['type'],
'industry' => $team['industry'],
];
}
$this->success('成功', $return);
}
/**
* @ApiTitle (用户接口-基本信息修改)
* @ApiSummary (基本信息)
* @ApiMethod (POST)
* @ApiRoute (/api/User/UpdateEssentialInformation)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="mobile", type="integer", required=true, description="手机号")
* @ApiParams (name="username", type="integer", required=true, description="用户名")
* @ApiParams (name="email", type="string", required=true, description="邮箱")
* @ApiParams (name="code", type="string", required=true, description="验证码")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
"data": "1"
})
*/
public function UpdateEssentialInformation()
{
$param = $this->request->param();
$user_id = $this->is_token($this->request->header());
$this->CheckCode($param['mobile'], $param['code']);
$is_matching = Db::name('user')->where(['mobile' => $param['mobile']])->find();
if (!($is_matching['id'] == $user_id)) {
$this->error('修改失败,请联系后台管理员', 0);
}
$res = Db::name('user')->where(['id' => $user_id])->update(['username' => $param['username'], 'email' => $param['email']]);
if ($res) {
$this->success('修改成功', 1);
} else {
$this->error('修改成功', 0);
}
}
/**
* @ApiTitle (用户接口-修改密码)
* @ApiSummary (修改密码)
* @ApiMethod (POST)
* @ApiRoute (/api/User/UpdatePassword)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="old_password", type="string", required=true, description="原密码")
* @ApiParams (name="password", type="string", required=true, description="密码")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
"data": "1"
})
*/
public function UpdatePassword()
{
$param = $this->request->param();
$user_id = $this->is_token($this->request->header());
$password = Db::name('user')->where(['id' => $user_id])->find();
if (!($param['old_password'] == $password['password'])) {
$this->error('原密码错误', 0);
}
$res = Db::name('user')->where(['id' => $user_id])->update(['password' => $param['password']]);
if ($res) {
$this->success('修改成功', 1);
} else {
$this->error('修改失败', 0);
}
}
}