123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace app\api\controller;
- use think\Controller;
- use think\Db;
- /**
- * @title 直播
- * Class Live
- * @controller Live
- * @group base
- */
- class Live extends Base
- {
- public function initialize(){
- parent::initialize();
- change_live_status();
- parent::check_login();
- }
- /**
- * @title 获取直播商品详情
- * @desc 获取直播商品详情
- * @author qc
- * @url /api/Live/getLiveGoods
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int request:1 default:0 desc:id
- * @return name:cate_id type:int default:-- desc:分类id
- * @return name:title type:string default:-- desc:分类名称
- * @return name:goods type:array default:-- desc:商品
- * @return name:goods.name type:string default:-- desc:商品名称
- * @return name:goods.cover type:string default:-- desc:商品封面
- * @return name:goods.goods_id type:int default:-- desc:商品id
- * @return name:goods.is_app type:int default:-- desc:会员是否预约此商品(0未预约,1已预约)
- */
- public function getLiveGoods()
- {
- $live_id = input('id',0);
- $user_app = Db::table('live_goods_app')->where(['user_id'=>$this->uid,'live_id'=>$live_id])->select();
- $app_goods = array_column($user_app,'goods_id');// 预约的商品id
- $live_cate = Db::table('store_live_goods')
- ->field('l.cate_id,c.title,c.sort')
- ->alias('l')
- ->join('store_live_cate c','l.cate_id = c.id','LEFT')
- ->where('l.live_id','=',$live_id)
- ->group('l.cate_id')
- ->order('c.sort desc , c.id desc')
- ->select();
- $ret_data = [];
- foreach ($live_cate as $val)
- {
- $cal_data= ['cate_id'=>$val['cate_id'],'title'=>$val['title']];
- $goods = Db::table('store_live_goods')
- ->field('g.id,g.live_id,l.name,l.cover,g.goods_id')
- ->alias('g')
- ->join('live_goods_list l','g.goods_id = l.id','LEFT')
- ->where('g.live_id','=',$live_id)
- ->where('g.cate_id','=',$val['cate_id'])
- ->order('g.sort desc , g.id desc')
- ->select();
- foreach ($goods as &$gv) {
- $gv['is_app'] = in_array($gv['goods_id'],$app_goods) ?1:0;
- }
- $cal_data['goods'] =$goods;
- $ret_data[] = $cal_data;
- }
- $this->success('ok',['live_goods'=>$ret_data]);
- }
- /**
- * @title 预约直播商品(添加 || 修改)
- * @desc 预约直播商品
- * @author qc
- * @url /api/Live/appLiveGoods
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int request:1 default:0 desc:直播id
- * @param name:goods_ids type:string default:-- desc:商品id(多个用逗号隔开)
- */
- public function appLiveGoods()
- {
- $live_id = input('post.id');
- $goods_ids = input('post.goods_ids');
- if(!$live_id ) $this->error('参数错误');
- Db::table('live_goods_app')->where(['user_id'=>$this->uid,'live_id'=>$live_id])->delete();
- if(!$goods_ids) $this->success('ok');
- $app_data = [];
- foreach (explode(',',$goods_ids) as $v) {
- $app_data[] = [
- 'user_id' => $this->uid,
- 'live_id' => $live_id,
- 'goods_id' => $v,
- 'create_at' => date("Y-m-d H:i:s"),
- ];
- }
- $check_msg = Db::table('live_app_msg')->where(['live_id'=>$live_id,'user_id'=>$this->uid])->count();
- if(!$check_msg) {
- $live_info = Db::table('store_live')->find($live_id);
- $jump_url = Db::table('platform_set')->where(['name'=>'push_link'])->value('content');
- Db::table('live_app_msg')->insert(['live_id'=>$live_id,
- 'user_id'=>$this->uid,
- 'show_time'=>$live_info['start_at'],
- 'title'=>$live_info['name'],
- 'create_at' =>date('Y-m-d H:i:s'),
- 'url'=>$jump_url
- ]);
- }
- Db::table('live_goods_app')->insertAll($app_data);
- $this->success('ok');
- }
- /**
- * @title 观看直播预告(赠送积分)
- * @desc 观看直播预告(赠送积分)
- * @author qc
- * @url /api/Live/readLiveNotice
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @return name:integral type:int default:-- desc:获得积分数
- * @return name:growth type:int default:-- desc:获得成长值
- */
- public function readLiveNotice()
- {
- $check_num = Db::table('integral_info')
- ->where('user_id','=',$this->uid)
- ->where('create_at','> time',date('Y-m-d 00:00:00'))
- ->where('type','=',2)
- ->count();
- if($check_num >= 1) $this->success('您已获得观看直播预告积分');
- $int_set =Db::table('system_config')->where('name','live_preview')->find();
- if(!empty($int_set) && intval(trim($int_set['value'])) > 0) {
- $num = intval(trim($int_set['value']));
- update_user_integral($this->uid,$num,2,'恭喜亲通过观看直播预告获得'.$num.'积分');
- update_user_growth($this->uid,$num,2,'恭喜亲通过观看直播预告获得'.$num.'成长值');
- $this->success('ok',['integral'=>$num,'growth'=>$num]);
- }else{
- $this->success('ok',['integral'=>0,'growth'=>0]);
- }
- }
- /**
- * @title 分享直播赠送积分
- * @desc 分享直播赠送积分
- * @author qc
- * @url /api/Live/shareLiveNotice
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @return name:integral type:int default:-- desc:获得积分数
- * @return name:growth type:int default:-- desc:获得成长值
- */
- public function shareLiveNotice()
- {
- $share_integral_set =Db::table('system_config')->where('name','share_integral')->value('value');
- $share_integral = intval(trim($share_integral_set));
- $max_integral_set =Db::table('system_config')->where('name','max_integral')->value('value');
- $max_integral = intval(trim($max_integral_set));
- $check_integral = Db::table('integral_info')
- ->where('user_id','=',$this->uid)
- ->where('create_at','> time',date('Y-m-d 00:00:00'))
- ->where('type','=',9)
- ->sum('integral');
- if($share_integral <= 0 || $max_integral<= 0) $this->error('分享设置有误');
- if($share_integral + intval($check_integral) > $max_integral ) $this->error('分享活得积分达到每日上限');
- update_user_integral($this->uid,$share_integral,9,'恭喜亲通过分享直播预告获得'.$share_integral.'积分');
- update_user_growth($this->uid,$share_integral,9,'恭喜亲通过分享直播预告获得'.$share_integral.'成长值');
- $this->success('ok',['integral'=>$share_integral,'growth'=>$share_integral]);
- }
- }
|