UserInvoice.php
7.0 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
<?php
namespace app\api\controller;
use app\api\model\Area;
use app\api\model\UserAddress as UserAddressModel;
use app\common\controller\Api;
use think\Config;
use think\Db;
use app\api\model\User;
use think\Validate;
/**
* 用户发票接口
*/
class UserInvoice extends Api
{
protected $userModel;
public function _initialize()
{
parent::_initialize();
$this->userModel = new User();
}
/**
* @ApiTitle (添加用户发票)
* @ApiSummary (添加用户发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/addUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiParams (name=taitou, type=string, required=true, description="发票抬头")
* @ApiParams (name=duty_num, type=string, required=false, description="税号")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function addUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'type' => 'require',
'taitou' => 'require',
'is_default' => 'require',
]);
$validate->message([
'type' => '缺少参数 type!',
'taitou' => '缺少参数 taitou!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId,'type'=>$data['type']])->update(['is_default'=>2]);
}
$res = $model->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (编辑用户发票)
* @ApiSummary (编辑用户发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/editUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiParams (name=taitou, type=string, required=true, description="发票抬头")
* @ApiParams (name=duty_num, type=string, required=false, description="税号")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function editUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'id' => 'require',
'type' => 'require',
'taitou' => 'require',
'is_default' => 'require',
]);
$validate->message([
'id' => '缺少参数 id!',
'type' => '缺少参数 type!',
'taitou' => '缺少参数 taitou!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId,'type'=>$data['type']])->update(['is_default'=>2]);
}
$res = $model->update($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (删除用户发票)
* @ApiSummary (删除用户发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/delUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function delUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $id;
$res = $model->where($where)->delete();
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (用户发票详情)
* @ApiSummary (用户发票详情)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceInfo()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $id;
$data = $model->where($where)->find();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (用户发票列表)
* @ApiSummary (用户发票列表)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceIList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceIList()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$where['user_id'] = $userId;
$data = $model->where($where)->order('is_default')->select();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取用户默认发票)
* @ApiSummary (获取用户默认发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceDefault)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceDefault()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$type = $this->request->param('type');
if (empty($type)) $this->error('缺少参数 type!');
$data = $model->where(['user_id'=>$userId,'type'=>$type,'is_default'=>1])->find();
$this->success('SUCCESS',$data);
}
}