123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace app\store\controller\api\member;
- use app\store\controller\api\Member;
- use think\Db;
- class Address extends Member
- {
-
- public function gets()
- {
- $this->success('获取会员收货地址成功!', [
- 'list' => Db::name('StoreMemberAddress')
- ->where(['mid' => $this->member['id']])
- ->order('is_default desc,id desc')
- ->select(),
- ]);
- }
-
- public function set()
- {
- $data = $this->_input([
- 'mid' => $this->request->post('mid'),
- 'openid' => $this->request->post('openid'),
- 'name' => $this->request->post('name'),
- 'phone' => $this->request->post('phone'),
- 'province' => $this->request->post('province'),
- 'city' => $this->request->post('city'),
- 'area' => $this->request->post('area'),
- 'address' => $this->request->post('address'),
- 'is_default' => $this->request->post('is_default'),
- ], [
- 'name' => 'require',
- 'phone' => 'require|mobile',
- 'province' => 'require',
- 'city' => 'require',
- 'area' => 'require',
- 'address' => 'require',
- ], [
- 'name.require' => '收货人姓名不能为空!',
- 'phone.require' => '收货人联系手机不能为空!',
- 'phone.mobile' => '收货人联系手机格式不对!',
- 'province.require' => '收货地址省份不能为空!',
- 'city.require' => '收货地址城市不能为空!',
- 'area.require' => '收货地址区域不能为空!',
- 'address.require' => '收货详情地址不能为空!',
- ]);
- if (!empty($data['is_default'])) {
- Db::name('StoreMemberAddress')->where(['mid' => $this->member['id']])->setField('is_default', '0');
- }
- if ($this->request->has('id', 'post', true)) {
- $data['id'] = $this->request->post('id');
- }
- if (data_save('StoreMemberAddress', $data, 'id')) {
- $this->success('收货地址更新成功!');
- }
- $this->error('收货地址更新失败,请稍候再试!');
- }
-
- public function del()
- {
- $id = $this->request->post('address_id');
- if (empty($id)) $this->error('待处理的收货地址ID不能为空!');
- $where = ['id' => $id, 'mid' => $this->member['id']];
- if (Db::name('StoreMemberAddress')->where($where)->delete() !== false) {
- $this->success('删除收货地址成功!');
- }
- $this->error('删除收货地址失败,请稍候再试!');
- }
-
- public function setDefault()
- {
- $id = $this->request->post('address_id');
- if (empty($id)) $this->error('待处理的收货地址ID不存在!');
- $where = ['id' => $id, 'mid' => $this->member['id']];
- $address = Db::name('StoreMemberAddress')->where($where)->find();
- if (empty($address)) $this->error('待处理的收货地址获取失败,请稍候再试!');
- Db::name('StoreMemberAddress')->where(['mid' => $this->member['id']])->update(['is_default' => '0']);
- if (Db::name('StoreMemberAddress')->where($where)->update(['is_default' => '1']) !== false) {
- $this->success('设置默认收货地址成功!');
- }
- $this->error('设置默认收货地址失败!');
- }
- }
|