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); } }