正在显示
1 个修改的文件
包含
104 行增加
和
6 行删除
@@ -115,7 +115,58 @@ class Address extends Api | @@ -115,7 +115,58 @@ class Address extends Api | ||
115 | * @ApiParams (name="token", type="string", required=true, description="token") | 115 | * @ApiParams (name="token", type="string", required=true, description="token") |
116 | * @ApiParams (name="address", type="string", required=true, description="地址信息") | 116 | * @ApiParams (name="address", type="string", required=true, description="地址信息") |
117 | * @ApiParams (name="address_con", type="int", required=true, description="详细地址") | 117 | * @ApiParams (name="address_con", type="int", required=true, description="详细地址") |
118 | - * @ApiParams (name="name", type="int", required=true, description="姓名") | 118 | + * @ApiParams (name="name", type="int", required=true, description="收货人姓名") |
119 | + * @ApiParams (name="mobile", type="int", required=true, description="手机号") | ||
120 | + * @ApiParams (name="type", type="int", required=true, description="是否设置为默认[1=是,0=否]") | ||
121 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
122 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
123 | + * @ApiReturn ({ | ||
124 | + 'code':'1', | ||
125 | + 'msg':'返回成功' | ||
126 | + "data": { | ||
127 | + } | ||
128 | + }) | ||
129 | + */ | ||
130 | + public function NewAddress() | ||
131 | + { | ||
132 | + $user_id = $this->is_token($this->request->header()); | ||
133 | + $param = $this->request->param(); | ||
134 | + //判断是否有默认地址 | ||
135 | + if ($param['type'] == 1) { | ||
136 | + $is_TypeAdress = Db::name('address')->where(['user_id' => $user_id])->where(['status' => 1])->find(); | ||
137 | + if ($is_TypeAdress) { | ||
138 | + Db::name('address')->where(['id' => $is_TypeAdress['id']])->update(['status' => 0]); | ||
139 | + } | ||
140 | + } | ||
141 | + $data = [ | ||
142 | + 'user_id' => $user_id, | ||
143 | + 'address' => $param['address'], | ||
144 | + 'address_con' => $param['address_con'], | ||
145 | + 'name' => $param['name'], | ||
146 | + 'mobile' => $param['mobile'], | ||
147 | + 'status' => $param['type'], | ||
148 | + 'createtime' => time(), | ||
149 | + 'updatetime' => time(), | ||
150 | + ]; | ||
151 | + $res = Db::name('address')->insert($data); | ||
152 | + if ($res) { | ||
153 | + $this->success('成功', 1); | ||
154 | + } else { | ||
155 | + $this->error('失败', 0); | ||
156 | + } | ||
157 | + } | ||
158 | + | ||
159 | + | ||
160 | + /** | ||
161 | + * @ApiTitle (地址接口-修改地址) | ||
162 | + * @ApiSummary (修改地址) | ||
163 | + * @ApiMethod (POST) | ||
164 | + * @ApiRoute (/api/address/ChangeAddress) | ||
165 | + * @ApiParams (name="token", type="string", required=true, description="token") | ||
166 | + * @ApiParams (name="address", type="string", required=true, description="地址信息") | ||
167 | + * @ApiParams (name="address_con", type="int", required=true, description="详细地址") | ||
168 | + * @ApiParams (name="name", type="int", required=true, description="收货人姓名") | ||
169 | + * @ApiParams (name="mobile", type="int", required=true, description="手机号") | ||
119 | * @ApiParams (name="id", type="int", required=true, description="地址ID") | 170 | * @ApiParams (name="id", type="int", required=true, description="地址ID") |
120 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | 171 | * @ApiReturnParams (name="code", type="integer", required=true, sample="0") |
121 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | 172 | * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") |
@@ -123,12 +174,59 @@ class Address extends Api | @@ -123,12 +174,59 @@ class Address extends Api | ||
123 | 'code':'1', | 174 | 'code':'1', |
124 | 'msg':'返回成功' | 175 | 'msg':'返回成功' |
125 | "data": { | 176 | "data": { |
126 | - "name": "王二蛋", | ||
127 | - "address": "天津市", | ||
128 | - "address_con": "天津市西青区", | ||
129 | - "mobile": "13223332122", | ||
130 | - "id": 1 | ||
131 | } | 177 | } |
132 | }) | 178 | }) |
133 | */ | 179 | */ |
180 | + public function ChangeAddress() | ||
181 | + { | ||
182 | + $user_id = $this->is_token($this->request->header()); | ||
183 | + $param = $this->request->param(); | ||
184 | + $res = Db::name('address')->where(['user_id' => $user_id])->where(['id' => $param['id']]) | ||
185 | + ->update([ | ||
186 | + 'address' => $param['address'], | ||
187 | + 'address_con' => $param['address_con'], | ||
188 | + 'name' => $param['name'], | ||
189 | + 'mobile' => $param['mobile'], | ||
190 | + 'updatetime' => time() | ||
191 | + ]); | ||
192 | + if ($res) { | ||
193 | + $this->success('修改成功', 1); | ||
194 | + } else { | ||
195 | + $this->error('修改失败', 0); | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + | ||
200 | + /** | ||
201 | + * @ApiTitle (地址接口-设为默认地址) | ||
202 | + * @ApiSummary (设为默认地址) | ||
203 | + * @ApiMethod (POST) | ||
204 | + * @ApiRoute (/api/address/SetAsDefaultAddress) | ||
205 | + * @ApiParams (name="token", type="string", required=true, description="token") | ||
206 | + * @ApiParams (name="id", type="int", required=true, description="地址ID") | ||
207 | + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") | ||
208 | + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") | ||
209 | + * @ApiReturn ({ | ||
210 | + 'code':'1', | ||
211 | + 'msg':'返回成功' | ||
212 | + "data": { | ||
213 | + } | ||
214 | + }) | ||
215 | + */ | ||
216 | + public function SetAsDefaultAddress() | ||
217 | + { | ||
218 | + $user_id = $this->is_token($this->request->header()); | ||
219 | + $id = input('id'); | ||
220 | + //检查是否已有默认地址 | ||
221 | + $is_TypeAdress = Db::name('address')->where(['user_id' => $user_id])->where(['status' => 1])->find(); | ||
222 | + if ($is_TypeAdress) { | ||
223 | + Db::name('address')->where(['id' => $is_TypeAdress['id']])->update(['status' => 0]); | ||
224 | + } | ||
225 | + $res = Db::name('address')->where(['id' => $id])->where(['user_id' => $user_id])->update(['status' => 1]); | ||
226 | + if ($res) { | ||
227 | + $this->success('成功', 1); | ||
228 | + } else { | ||
229 | + $this->error('失败', 0); | ||
230 | + } | ||
231 | + } | ||
134 | } | 232 | } |
-
请 注册 或 登录 后发表评论