2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
|
<?php
namespace app\api\controller\kuerp\order;
use app\common\controller\Api;
use app\api\library\kuerp\Auth;
use app\api\model\kuerp\UserAddress as Addresss;
use app\api\model\kuerp\Areas;
class Address extends Api
{
protected $noNeedRight = '*';
protected $noNeedLogin = '*';
protected $auth_s;
public function _initialize()
{
parent::_initialize();
$this->auth_s = new Auth();
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
$this->auth_s->init($token);
}
/**
* 获取发货地址
* @ApiMethod (POST)
* @param int $page 页码
* @param int $limit 每页条数
* @param string $name 发货地址名称
*/
public function getlist()
{
if ($this->request->isPost()) {
$page = $this->request->post('page');
$page = empty($page)?1:$page;
$limit = $this->request->post('limit');
$limit = empty($limit)?config('app_limit'):$limit;
$name = $this->request->post('name');
$where = [];
if(!empty($name)){
$where['connect_name'] = ['like','%'.$name.'%'];
}
$phone = $this->request->post('phone');
if(!empty($phone)){
$where['connect_mobile'] = ['like','%'.$phone.'%'];
}
$user = $this->auth_s->getUserinfo();
if(!isset($user['id'])){
$this->error('请先登陆','',250);
}
$result = Addresss::getList($where,$page,$limit,$user['id']);
if(isset($result['list']) && isset($result['count'])){
$this->success('查询成功',$result,200);
}else{
$this->error('查询失败','',406);
}
}else{
$this->error('请求方式错误','',250);
}
}
/**
* 获取发货地址详情
* @ApiMethod (POST)
* @param int $id 发货地址ID
*/
public function getdetail()
{
if ($this->request->isPost()) {
$id = $this->request->post('id');
if(empty($id)){
$this->error('请输入查询参数','',500);
}
$user = $this->auth_s->getUserinfo();
if(!isset($user['id'])){
$this->error('请先登陆','',250);
}
$result = Addresss::getDetail($id,$user['id']);
if($result['status']!=200){
$this->error($result['msg'],'',$result['status']);
}
$this->success('查询成功',$result['msg'],200);
}else{
$this->error('请求方式错误','',250);
}
}
/**
* 添加发货地址
* @ApiMethod (POST)
* @param array $detail 发货地址数据
*/
public function adddetail()
{
if ($this->request->isPost()) {
$data = $this->request->post();
foreach ($data as $k=>$v){
$data[$k] = is_array($v)?$v:html_entity_decode($v);
}
$user = $this->auth_s->getUserinfo();
if(!isset($user['id'])){
$this->error('请先登陆','',250);
}
$ret = Addresss::addDetail($data,$user['id']);
if($ret['status']==200){
$this->success('添加成功',$ret['msg'],200);
}else{
$this->error($ret['msg'],'',$ret['status']);
}
}else{
$this->error('请求方式错误','',250);
}
}
/**
* 更新发货地址
* @ApiMethod (POST)
* @param array $detail 发货地址数据
*/
public function editdetail()
{
if ($this->request->isPost()) {
$data = $this->request->post();
foreach ($data as $k=>$v){
$data[$k] = is_array($v)?$v:html_entity_decode($v);
}
$user = $this->auth_s->getUserinfo();
if(!isset($user['id'])){
$this->error('请先登陆','',250);
}
$ret = Addresss::editDetail($data,$user['id']);
if($ret['status']==200){
$this->success('更新成功','',200);
}else{
$this->error($ret['msg'],'',$ret['status']);
}
}else{
$this->error('请求方式错误','',250);
}
}
/**
* 删除发货地址
* @ApiMethod (POST)
* @param int $id 发货地址id
*/
public function deldetail()
{
if ($this->request->isPost()) {
$id = $this->request->post('id');
$user = $this->auth_s->getUserinfo();
if(!isset($user['id'])){
$this->error('请先登陆','',250);
}
$ret = Addresss::delDetail($id,$user['id']);
if($ret['status']==200){
$this->success('删除成功',$ret['msg'],200);
}else{
$this->error($ret['msg'],'',$ret['status']);
}
}else{
$this->error('请求方式错误','',250);
}
}
/**
* 读取省市区数据,联动列表
*/
public function area()
{
if ($this->request->isPost()) {
$province = $this->request->post('province', '');
$city = $this->request->post('city', '');
$adcode = $this->request->post('adcode', '');
if(!empty($adcode)){
$area = (new Areas())->where(['adcode'=>$adcode])->find();
if($area){
if($area['level']==1){
$province = $area['id'];
}elseif ($area['level']==2){
$city = $area['id'];
}
}
}
$where = ['pid' => 0, 'level' => 1];
$provincelist = null;
if ($province !== '') {
$where['pid'] = $province;
$where['level'] = 2;
if ($city !== '') {
$where['pid'] = $city;
$where['level'] = 3;
}
}
$provincelist = (new Areas())->where($where)->field('id as value,name,adcode')->select();
$this->success('查询成功', $provincelist, 200);
}else{
$this->error('请求方式错误','',250);
}
}
}
|