123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <?php
- namespace app\api\controller;
- use think\Db;
- class Usermanage extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::check_login();
- }
-
- 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()]);
- }
-
- 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]);
- }
-
- 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('商品已收藏');
- }
-
- 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('取消成功');
- }
-
- 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]);
- }
-
- 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('编辑成功');
- }
-
- 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('删除成功!');
- }
-
- 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]);
- }
-
- public function getDeliveryAddressDetail()
- {
- $detail = Db::table('delivery_address')->find(input('id'));
- $this->success('ok',$detail);
- }
-
- 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 ]);
- }
-
- 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');
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
- }
|