123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <?php
- namespace app\api\controller;
- use app\common\model\DeliveryAddress;
- use app\common\model\UserLevel;
- use think\Db;
- use app\common\model\User;
- use app\common\model\InviteInfo;
- /**
- * @title 会员管理
- * @controller UserManage
- * @group base
- */
- class UserManage extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * @title 设置收货地址(新增或修改)
- * @desc 设置收货地址(新增或修改)
- * @author qc
- * @url /api/User_manage/setDeliveryAddress
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int : default:0 desc:收货地址记录id(不传值是添加)
- * @param name:pro_name type:int require:1 default:-- desc:省名
- * @param name:city_name type:int require:1 default:-- desc:市名
- * @param name:county_name type:int require:1 default:-- desc:县区名
- * @param name:street_name type:int 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/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]);
- }
- }
|