123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace app\api\controller;
- use app\common\model\DeliveryAddress;
- use think\Db;
- /**
- * @title 地址管理
- * @controller Address
- * @group base
- */
- class Address extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * @title 设置收货地址(新增或修改)
- * @desc 设置收货地址(新增或修改)
- * @author qc
- * @url /api/Address/setDeliveryAddress
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int : default:0 desc:收货地址记录id(不传值是添加)
- * @param name:pro_name type:string require:1 default:-- desc:省名
- * @param name:city_name type:string require:1 default:-- desc:市名
- * @param name:county_name type:string require:1 default:-- desc:县区名
- * @param name:detail type:string require:1 default:-- desc:详细地址
- * @param name:phone type:string require:1 default:-- desc:联系电话
- * @param name:name type:string require:1 default:-- desc:联系人
- * @param name:is_mr type:int require:0 default:0 desc:是否是默认(0不默认,1默认)
- */
- public function setDeliveryAddress()
- {
- $pro_name = input('post.pro_name');// 省
- $city_name = input('post.city_name');// 市
- $county_name = input('post.county_name');// 县区
- $street_name = input('post.street_name','' );
- $pro_id = Db::name('store_area')->where('name',$pro_name)->value('id');
- $city_id = Db::name('store_area')->where('name',$city_name)->value('id');
- $county_id = Db::name('store_area')->where('name',$county_name)->value('id');
- $detail = input('post.detail');// 详细地址
- $phone = input('post.phone');
- $name = input('post.name');
- $id = input('post.id');
- $is_mr = input('post.is_mr',0);
- $set_data = compact(['pro_id','city_id','county_id','detail','phone','name','is_mr']);
- $set_data['user_id'] = $this->user_id;
- $set_data['pro_name'] = $pro_name;
- $set_data['city_name'] = $city_name;
- $set_data['county_name']= $county_name;
- $set_data['street_name']= $street_name;
- $set_data['mer_name']=$pro_name . $city_name. $county_name;
- if($id) {
- Db::name('delivery_address')->where(['id'=>$id])->update($set_data);
- }else{
- Db::name('delivery_address')->insert($set_data);
- $id = Db::getLastInsID();
- }
- if($is_mr) Db::name('delivery_address')->where('user_id','=',$this->user_id)->where('id','<>',$id)->where('is_mr','=',1)->update(['is_mr'=>0]);
- $this->success('编辑成功');
- }
- /**
- * @title 修改默认收货地址
- * @desc 修改默认收货地址
- * @author qc
- * @url /api/Address/changeApproveDelivery
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:收货地址记录id
- * @param name:is_mr type:int default:1 desc:是否是默认(0不默认,1默认)
- */
- public function changeApproveDelivery()
- {
- $id = input('post.id');
- $is_mr = input('post.is_mr',1);
- if($is_mr) {
- Db::name('delivery_address')
- ->where('user_id','=',$this->user_id)
- ->where('is_mr','=',1)
- ->update(['is_mr'=>0]);
- Db::name('delivery_address')
- ->where('user_id','=',$this->user_id)
- ->where('id','=',$id)
- ->update(['is_mr'=>1]);
- }else{
- Db::name('delivery_address')
- ->where('user_id','=',$this->user_id)
- ->where('id','=',$id)
- ->update(['is_mr'=>0]);
- }
- $this->success('修改成功');
- }
- /**
- * @title 删除收货地址
- * @desc 删除收货地址
- * @author qc
- * @url /api/Address/delDeliveryAddress
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:1 desc:收货地址记录id
- */
- public function delDeliveryAddress()
- {
- $id = input('post.id');
- if(!$id)$this->error('请选择要删除的收货地址');
- Db::name('delivery_address')->where(['user_id'=>$this->user_id,'id'=>$id])->update(['is_deleted'=>1,'is_mr'=>0]);
- $this->success('删除成功!');
- }
- /**
- * @title 获取收货地址列表
- * @desc 获取收货地址列表
- * @author qc
- * @url /api/Address/getDeliveryAddressList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:pro_id type:int default:-- desc:省id
- * @return name:city_id type:int default:-- desc:市id
- * @return name:county_id type:int default:-- desc:县区id
- * @return name:pro_name type:string default:-- desc:省名
- * @return name:city_name type:string default:-- desc:市名
- * @return name:county_name type:string default:-- desc:县区名
- * @return name:detail type:string default:-- desc:详细地址
- * @return name:phone type:string default:-- desc:联系电话
- * @return name:name type:string default:-- desc:联系人
- * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
- */
- public function getDeliveryAddressList()
- {
- $list = DeliveryAddress::where(['user_id'=>$this->user_id,'is_deleted'=>0])
- ->order('is_mr desc ,id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取收货地址详情
- * @desc 获取收货地址详情
- * @author qc
- * @url /api/Address/getDeliveryAddressDetail
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:收货地址记录id
- * @return name:pro_id type:int default:-- desc:省id
- * @return name:city_id type:int default:-- desc:市id
- * @return name:county_id type:int default:-- desc:县区id
- * @return name:pro_name type:string default:-- desc:省名
- * @return name:city_name type:string default:-- desc:市名
- * @return name:county_name type:string default:-- desc:县区名
- * @return name:detail type:string default:-- desc:详细地址
- * @return name:phone type:string default:-- desc:联系电话
- * @return name:name type:string default:-- desc:联系人
- * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
- */
- public function getDeliveryAddressDetail()
- {
- $detail = Db::name('delivery_address')->find(input('id'));
- $this->success('ok',$detail);
- }
- /**
- * @title 获取默认收货地址详情
- * @desc 获取默认收货地址详情
- * @author qc
- * @url /api/Address/getDefaultAddress
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:pro_id type:int default:-- desc:省id
- * @return name:city_id type:int default:-- desc:市id
- * @return name:county_id type:int default:-- desc:县区id
- * @return name:pro_name type:string default:-- desc:省名
- * @return name:city_name type:string default:-- desc:市名
- * @return name:county_name type:string default:-- desc:县区名
- * @return name:detail type:string default:-- desc:详细地址
- * @return name:phone type:string default:-- desc:联系电话
- * @return name:name type:string default:-- desc:联系人
- * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
- */
- public function getDefaultAddress()
- {
- $default = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
- $detail = $default ? $default->toArray() : '';
- $this->success('ok',$detail);
- }
- }
|