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/User_manage/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/User_manage/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/User_manage/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:street_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/User_manage/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:street_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/User_manage/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:street_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); } /** * @title 绑定推荐人 * @desc 绑定推荐人 * @author qc * @url /api/User_manage/bindParent * @method POST * @header name:Authorization require:1 desc:Token * @param name:invite_code type:string default:-- desc:推荐码 */ public function bindParent() { $invite_code = input('post.invite_code',''); $user_info = $this->userInfo(); if($user_info['pid']) $this->error('已绑定推荐人'); $invite_info = User::where(['invite_code'=>$invite_code])->find(); if(!$invite_info) $this->error('推荐码错误'); if(!$invite_info->id > $this->user_id) $this->error('无法绑定改会员为推荐人!'); User::update(['pid'=>$invite_info->id],['id'=>$this->user_id]); InviteInfo::create(['user_id'=>$this->user_id,'pid'=>$invite_info->id,'create_at'=>date('Y-m-d H:i:s'),'type'=>2]); $this->success('用户绑定成功'); } /** * @title 获取推荐人信息 * @desc 获取推荐人信息 * @author qc * @url /api/User_manage/getParentInfo * @method GET * @header name:Authorization require:1 desc:Token * @return name:name type:string default:-- desc:昵称 * @return name:headimg type:string default:-- desc:头像 * @return name:create_at type:string default:-- desc:注册时间 */ public function getParentInfo() { $pid = User::where('id',$this->user_id)->value('pid'); $parent_info = []; if($pid) $parent_info= User::field('id,name,headimg,create_at')->where('id',$this->user_id)->find()->toArray(); $this->success('ok',$parent_info); } /** * @title 通过邀请码获取用户信息(绑定推荐人可用) * @desc 通过邀请码获取用户信息(绑定推荐人可用) * @author qc * @url /api/User_manage/getParentInfo * @method GET * @header name:Authorization require:1 desc:Token * @param name:invite_code type:string default:-- desc:邀请码 * @return name:name type:string default:-- desc:名称 * @return name:headimg type:string default:-- desc:头像 * @return name:create_at type:string default:-- desc:注册时间 */ public function getUserInfoByCode() { $invite_code = input('get.invite_code'); $detail = User::field('id,name,headimg')->where(['invite_code'=>$invite_code])->find(); if(!$detail) $this->error('没有找到用户'); $this->success('ok',['detail'=>$detail->toArray()]); } /** * @title 获取我邀请的会员列表(我的粉丝) * @desc 获取我邀请的会员列表 * @author qc * @url /api/User_manage/getMyInviteList * @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:name type:string default:-- desc:昵称 * @return name:headimg type:string default:-- desc:头像 * @return name:create_at type:string default:-- desc:注册时间 */ public function getMyInviteList() { $list =User::field('id,name,headimg,create_at')->where(['pid'=>$this->user_id]) ->order('id desc') ->limit($this->page,$this->page_num) ->select(); $this->success('ok',['list'=>$list ? $list->toArray():[]]); } /** * @title 用户反馈 * @desc 用户反馈 * @author qc * @url /api/User_manage/leaveFeedback * @method POST * @header name:Authorization require:1 desc:Token * @param name:phone type:string require:1 default:-- desc:电话 * @param name:content type:string require:1 default:-- desc:反馈内容 * @param name:images type:string require:0 default:-- desc:反馈图片(逗号隔开,没有不传) */ public function leaveFeedback() { $insert_data = [ 'user_id'=>$this->user_id, 'content'=>input('content'), 'phone'=>input('phone'), 'images'=>input('images'), 'create_at'=>date('Y-m-d H:i:s') ]; Db::name('user_feedback')->insert($insert_data); $this->success('反馈成功',Db::getLastInsID()); } /** * @title 获取会员等级设置 * @desc 获取我邀请的会员列表 * @author qc * @url /api/User_manage/getUserLevelSet * @method GET * @header name:Authorization require:1 desc:Token * @return name:id type:int default:-- desc:等级id * @return name:name type:string default:-- desc:名称 * @return name:desc type:string default:-- desc:描述 * @return name:growth type:string default:-- desc:积分数 */ public function getUserLevelSet() { $list = UserLevel::field('id,name,desc,growth')->select()->toArray(); $this->success('ok',['list'=>$list]); } }