123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <?php
- namespace app\api\controller;
- use think\Db;
- /**
- * @title 会员管理
- * @controller Usermanage
- * @group base
- */
- class Usermanage extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::check_login();
- }
- /**
- * @title 发放(领取)优惠券
- * @desc 发放(领取)优惠券
- * @author qc
- * @url /api/Usermanage/sendCoupon
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:coupon_id type:int require:1 default:0 desc:券id
- * @return name:int_id type: int default:0 desc:发放(领取)id
- */
- public function sendCoupon()
- {
- $coupon_id = input("post.coupon_id");
- if(!$coupon_id) $this->error('请选择优惠券');
- $coupon_info = Db::table('store_coupon_config')
- ->where(['status'=>1,'is_deleted'=>0,'id'=>$coupon_id])
- ->find();
- if(empty($coupon_info)) $this->error('优惠券已过期或禁用');
- $has_get = Db::table('user_coupon_list')
- ->where(['user_id'=>$this->uid])
- ->count();
- if($coupon_info['user_num'] <= $has_get) $this->error('已达到领取上线');
- $coupon_data = [
- 'user_id'=>$this->uid,
- 'coupon_id'=>$coupon_id,
- 'low_amount'=>$coupon_info['low_amount'],
- 'amount'=>$coupon_info['amount'],
- 'low_day'=>$coupon_info['low_day'],
- 'create_at'=>date("Y-m-d 00:00:00"),
- 'past_at'=>date("Y-m-d 00:00:00",strtotime('+'.$coupon_info['low_day'].' days')),
- ];
- Db::table('user_coupon_list')->insert($coupon_data);
- $this->success('领取成功',['int_id'=>Db::getLastInsID()]);
- }
- /**
- * @title 获取我的优惠券
- * @desc 获取我的优惠券
- * @author qc
- * @url /api/Usermanage/getMyCouponByStatus
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:sel_status type:int : default:0 desc:0全部,1正常,2已使用,3过期
- * @param name:page type:int : default:1 desc:页数
- * @param name:page_num type:int : default:20 desc:每页数
- * @return name:coupon_id type:int default:-- desc:券id
- * @return name:low_amount type:float default:-- desc:最低消费
- * @return name:amount type:float default:-- desc:抵扣金额
- * @return name:create_at type:float default:-- desc:领取(发放时间)
- * @return name:status type:int default:-- desc:1正常,2已使用,3过期
- * @return name:past_at type:string default:-- desc:到期时间
- * @return name:used_time type:string default:-- desc:使用时间
- */
- public function getMyCouponByStatus()
- {
- $sel_status = input('sel_status');
- $where['user_id'] = $this->uid;
- if(in_array($sel_status,[1,2,3])) $where['status'] = $sel_status;
- $list = Db::table('user_coupon_list')->alias('l')
- ->field('l.*,c.title')
- ->join('store_coupon_config c',"l.coupon_id = c.id","LEFT")
- ->where($where)
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('获取成功',['list'=>$list]);
- }
- /**
- * @title 收藏商品
- * @desc 收藏商品
- * @author qc
- * @url /api/Usermanage/goodsCollect
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:goods_id type:int require:1 default:0 desc:商品id
- */
- public function goodsCollect()
- {
- $goods_id = input('post.goods_id');
- if(!$goods_id) $this->error('请选择商品');
- $check_collect = Db::table('goods_collect')
- ->where(['goods_id'=>$goods_id,'user_id'=>$this->uid])
- ->value('id');
- if($check_collect) $this->error('商品已收藏');
- Db::table('goods_collect')->insert(['goods_id'=>$goods_id,'user_id'=>$this->uid,'create_at'=>date('Y-m-d H:i:s')]);
- $this->success('商品已收藏');
- }
- /**
- * @title 取消收藏
- * @desc 取消收藏
- * @author qc
- * @url /api/Usermanage/cancelCollect
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:收藏记录id(两个参数不能同时为空)
- * @param name:goods_id type:int default:0 desc:商品id(两个参数不能同时为空)
- */
- public function cancelCollect()
- {
- $id = input('post.id');
- $goods_id = input('post.goods_id');
- if(!$id && !$goods_id) $this->error('参数错误');
- $del_where = [];
- $del_where['user_id'] = $this->uid;
- if($id) $del_where['id'] = $id;
- if($goods_id) $del_where['goods_id'] = $goods_id;
- Db::table('goods_collect')->where($del_where)->delete();
- $this->success('取消成功');
- }
- /**
- * @title 获取我的收藏列表
- * @desc 获取我的收藏列表
- * @author qc
- * @url /api/Usermanage/getMyGoodsCollect
- * @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:id type:int default:-- desc:收藏记录id
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:name type:string default:-- desc:商品名称
- * @return name:cover type:string default:-- desc:商品封面图
- * @return name:desc type:string default:-- desc:商品简述
- * @return name:floor_price type:float default:-- desc:最低价
- * @return name:month_sell type:int default:-- desc:月销量
- */
- public function getMyGoodsCollect()
- {
- $list = Db::table('goods_collect')->alias('c')
- ->field('c.id,c.goods_id,g.name,g.cover,g.desc,g.floor_price')
- ->join('store_goods g','c.goods_id = g.id','INNER')
- ->where(['c.user_id'=>$this->uid])
- ->order('c.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- foreach ($list as &$v) {
- $v['month_sell'] = Db::table('goods_sell_info')
- ->where(['goods_id'=>$v['goods_id']])
- ->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-1 month')))
- ->count();
- }
- $this->success('获取成功',['list'=>$list]);
- }
- /**
- * @title 设置收货地址(新增或修改)
- * @desc 设置收货地址(新增或修改)
- * @author qc
- * @url /api/Usermanage/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: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');// 县区
- $pro_id = Db::table('store_area')->where('name',$pro_name)->value('id');
- $city_id = Db::table('store_area')->where('name',$city_name)->value('id');
- $county_id = Db::table('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->uid;
- $set_data['pro_name'] = $pro_name;
- $set_data['city_name'] = $city_name;
- $set_data['county_name']= $county_name;
- $set_data['mer_name']=$pro_name . $city_name. $county_name;
- if($id) {
- Db::table('delivery_address')->where(['id'=>$id])->update($set_data);
- }else{
- Db::table('delivery_address')->insert($set_data);
- $id = Db::getLastInsID();
- }
- if($is_mr) Db::table('delivery_address')->where('user_id','=',$this->uid)->where('id','<>',$id)->where('is_mr','=',1)->update(['is_mr'=>0]);
- $this->success('编辑成功');
- }
- /**
- * @title 删除收货地址
- * @desc 删除收货地址
- * @author qc
- * @url /api/Usermanage/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::table('delivery_address')->where(['user_id'=>$this->uid,'id'=>$id])->delete();
- $this->success('删除成功!');
- }
- /**
- * @title 获取收货地址列表
- * @desc 获取收货地址列表
- * @author qc
- * @url /api/Usermanage/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 = Db::table('delivery_address')
- ->where(['user_id'=>$this->uid])
- ->order('is_mr desc ,id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取收货地址详情
- * @desc 获取收货地址详情
- * @author qc
- * @url /api/Usermanage/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::table('delivery_address')->find(input('id'));
- $this->success('ok',$detail);
- }
- /**
- * @title 获取消息未读数量
- * @desc 获取消息未读数量
- * @author qc
- * @url /api/Usermanage/getMsgCalNum
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:integral_num type:int default:0 desc:积分消息未读数量
- * @return name:lev_num type:int default:0 desc:等级变更消息未读数量
- * @return name:live_num type:int default:0 desc:直播消息未读数量
- * @return name:growth_num type:int default:0 desc:成长值消息未读数量
- */
- public function getMsgCalNum()
- {
- $integral_num = Db::table('integral_info')
- ->where(['user_id'=>$this->uid,'is_deleted'=>0,'is_read'=>0])
- ->count();
- $lev_num = Db::table('member_level_log')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->count();
- $live_num = Db::table('live_app_msg')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->count();
- $growth_num = Db::table('member_level_growth')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->count();
- $this->success('ok',['integral_num'=>$integral_num ? $integral_num:0,'lev_num'=>$lev_num ? $lev_num:0,'live_num'=>$live_num ? $live_num:0,'growth_num'=>$growth_num?$growth_num : 0 ]);
- }
- /**
- * @title 消息变更为全部已读
- * @desc 消息变更为全部已读
- * @author qc
- * @url /api/Usermanage/msgReadByType
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:type type:int default:1 desc:类型(1积分,2等级变更,3直播通知,4成长值)
- */
- public function msgReadByType()
- {
- $type = input('post.type',1);
- switch ($type) {
- case 1:
- Db::table('integral_info')
- ->where(['user_id'=>$this->uid,'is_deleted'=>0,'is_read'=>0])
- ->update(['is_read'=>1]);
- break;
- case 2:
- Db::table('member_level_log')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->update(['is_read'=>1]);
- break;
- case 3:
- Db::table('live_app_msg')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->update(['is_read'=>1]);
- break;
- case 4:
- Db::table('member_level_growth')
- ->where(['user_id'=>$this->uid,'is_read'=>0])
- ->update(['is_read'=>1]);
- break;
- }
- $this->success('ok');
- }
- /**
- * @title 获取积分变更日志
- * @desc 获取积分变更日志
- * @author qc
- * @url /api/Usermanage/getIntegralLog
- * @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:create_at type:string default:-- desc:时间
- * @return name:integral type:int default:-- desc:积分变更数
- * @return name:desc type:string default:-- desc:描述
- * @return name:is_read type:int default:-- desc:消息是否已读(0未读,1已读)
- */
- public function getIntegralLog()
- {
- $list = Db::table('integral_info')
- ->field('id,create_at,integral,desc,is_read')
- ->where(['user_id'=>$this->uid,'is_deleted'=>0])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取等级变更日志
- * @desc 获取等级变更日志
- * @author qc
- * @url /api/Usermanage/getMemberLevLog
- * @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:create_at type:string default:-- desc:时间
- * @return name:before_lev type:int default:-- desc:变更前等级id
- * @return name:after_lev type:int default:-- desc:变更后等级id
- * @return name:lev_name type:int default:-- desc:变更后等级名称
- * @return name:lev_logo type:int default:-- desc:变更后等级logo
- * @return name:desc type:string default:-- desc:描述
- * @return name:is_read type:int default:-- desc:消息是否已读(0未读,1已读)
- */
- public function getMemberLevLog()
- {
- $lev_set = Db::table('member_level')
- ->select();
- $lev_arr = array_column($lev_set,null,'id');
- $list = Db::table('member_level_log')
- ->field('id,create_at,before_lev,after_lev,is_read,desc')
- ->where(['user_id'=>$this->uid,'is_deleted'=>0])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- array_walk($list,function (&$val)use ($lev_arr){
- $val['lev_name'] = $lev_arr[$val['after_lev']]['name'];
- $val['lev_logo'] = $lev_arr[$val['after_lev']]['logo'];
- });
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取直播预告通知
- * @desc 获取直播预告通知
- * @author qc
- * @url /api/Usermanage/getLiveAppMsg
- * @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:title type:string default:-- desc:预约直播标题
- * @return name:show_time type:string default:-- desc:预约直播开始时间
- * @return name:create_at type:string default:-- desc:消息提醒时间
- * @return name:url type:string default:-- desc:跳转链接
- * @return name:is_read type:int default:-- desc:消息是否已读(0未读,1已读)
- */
- public function getLiveAppMsg()
- {
- $list = Db::table('live_app_msg')
- ->field('id,title,show_time,create_at,url,is_read')
- ->where(['user_id'=>$this->uid])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取成长值变更日志
- * @desc 获取成长值变更日志
- * @author qc
- * @url /api/Usermanage/getGrowthLog
- * @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:create_at type:string default:-- desc:时间
- * @return name:growth type:int default:-- desc:成长值变更数
- * @return name:desc type:string default:-- desc:描述
- * @return name:is_read type:int default:-- desc:消息是否已读(0未读,1已读)
- */
- public function getGrowthLog()
- {
- $list = Db::table('member_level_growth')
- ->field('id,create_at,growth,desc,is_read')
- ->where(['user_id'=>$this->uid])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- }
|