Live.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\api\controller;
  3. use think\Controller;
  4. use think\Db;
  5. /**
  6. * @title 直播
  7. * Class Live
  8. * @controller Live
  9. * @group base
  10. */
  11. class Live extends Base
  12. {
  13. public function initialize(){
  14. parent::initialize();
  15. change_live_status();
  16. parent::check_login();
  17. }
  18. /**
  19. * @title 获取直播商品详情
  20. * @desc 获取直播商品详情
  21. * @author qc
  22. * @url /api/Live/getLiveGoods
  23. * @method GET
  24. * @header name:Authorization require:1 desc:Token
  25. * @param name:id type:int request:1 default:0 desc:id
  26. * @return name:cate_id type:int default:-- desc:分类id
  27. * @return name:title type:string default:-- desc:分类名称
  28. * @return name:goods type:array default:-- desc:商品
  29. * @return name:goods.name type:string default:-- desc:商品名称
  30. * @return name:goods.cover type:string default:-- desc:商品封面
  31. * @return name:goods.goods_id type:int default:-- desc:商品id
  32. * @return name:goods.is_app type:int default:-- desc:会员是否预约此商品(0未预约,1已预约)
  33. */
  34. public function getLiveGoods()
  35. {
  36. $live_id = input('id',0);
  37. $user_app = Db::table('live_goods_app')->where(['user_id'=>$this->uid,'live_id'=>$live_id])->select();
  38. $app_goods = array_column($user_app,'goods_id');// 预约的商品id
  39. $live_cate = Db::table('store_live_goods')
  40. ->field('l.cate_id,c.title,c.sort')
  41. ->alias('l')
  42. ->join('store_live_cate c','l.cate_id = c.id','LEFT')
  43. ->where('l.live_id','=',$live_id)
  44. ->group('l.cate_id')
  45. ->order('c.sort desc , c.id desc')
  46. ->select();
  47. $ret_data = [];
  48. foreach ($live_cate as $val)
  49. {
  50. $cal_data= ['cate_id'=>$val['cate_id'],'title'=>$val['title']];
  51. $goods = Db::table('store_live_goods')
  52. ->field('g.id,g.live_id,l.name,l.cover,g.goods_id')
  53. ->alias('g')
  54. ->join('live_goods_list l','g.goods_id = l.id','LEFT')
  55. ->where('g.live_id','=',$live_id)
  56. ->where('g.cate_id','=',$val['cate_id'])
  57. ->order('g.sort desc , g.id desc')
  58. ->select();
  59. foreach ($goods as &$gv) {
  60. $gv['is_app'] = in_array($gv['goods_id'],$app_goods) ?1:0;
  61. }
  62. $cal_data['goods'] =$goods;
  63. $ret_data[] = $cal_data;
  64. }
  65. $this->success('ok',['live_goods'=>$ret_data]);
  66. }
  67. /**
  68. * @title 预约直播商品(添加 || 修改)
  69. * @desc 预约直播商品
  70. * @author qc
  71. * @url /api/Live/appLiveGoods
  72. * @method POST
  73. * @header name:Authorization require:1 desc:Token
  74. * @param name:id type:int request:1 default:0 desc:直播id
  75. * @param name:goods_ids type:string default:-- desc:商品id(多个用逗号隔开)
  76. */
  77. public function appLiveGoods()
  78. {
  79. $live_id = input('post.id');
  80. $goods_ids = input('post.goods_ids');
  81. if(!$live_id ) $this->error('参数错误');
  82. Db::table('live_goods_app')->where(['user_id'=>$this->uid,'live_id'=>$live_id])->delete();
  83. if(!$goods_ids) $this->success('ok');
  84. $app_data = [];
  85. foreach (explode(',',$goods_ids) as $v) {
  86. $app_data[] = [
  87. 'user_id' => $this->uid,
  88. 'live_id' => $live_id,
  89. 'goods_id' => $v,
  90. 'create_at' => date("Y-m-d H:i:s"),
  91. ];
  92. }
  93. $check_msg = Db::table('live_app_msg')->where(['live_id'=>$live_id,'user_id'=>$this->uid])->count();
  94. if(!$check_msg) {
  95. $live_info = Db::table('store_live')->find($live_id);
  96. $jump_url = Db::table('platform_set')->where(['name'=>'push_link'])->value('content');
  97. Db::table('live_app_msg')->insert(['live_id'=>$live_id,
  98. 'user_id'=>$this->uid,
  99. 'show_time'=>$live_info['start_at'],
  100. 'title'=>$live_info['name'],
  101. 'create_at' =>date('Y-m-d H:i:s'),
  102. 'url'=>$jump_url
  103. ]);
  104. }
  105. Db::table('live_goods_app')->insertAll($app_data);
  106. $this->success('ok');
  107. }
  108. /**
  109. * @title 观看直播预告(赠送积分)
  110. * @desc 观看直播预告(赠送积分)
  111. * @author qc
  112. * @url /api/Live/readLiveNotice
  113. * @method POST
  114. * @header name:Authorization require:1 desc:Token
  115. * @return name:integral type:int default:-- desc:获得积分数
  116. * @return name:growth type:int default:-- desc:获得成长值
  117. */
  118. public function readLiveNotice()
  119. {
  120. $check_num = Db::table('integral_info')
  121. ->where('user_id','=',$this->uid)
  122. ->where('create_at','> time',date('Y-m-d 00:00:00'))
  123. ->where('type','=',2)
  124. ->count();
  125. if($check_num >= 1) $this->success('您已获得观看直播预告积分');
  126. $int_set =Db::table('system_config')->where('name','live_preview')->find();
  127. if(!empty($int_set) && intval(trim($int_set['value'])) > 0) {
  128. $num = intval(trim($int_set['value']));
  129. update_user_integral($this->uid,$num,2,'恭喜亲通过观看直播预告获得'.$num.'积分');
  130. update_user_growth($this->uid,$num,2,'恭喜亲通过观看直播预告获得'.$num.'成长值');
  131. $this->success('ok',['integral'=>$num,'growth'=>$num]);
  132. }else{
  133. $this->success('ok',['integral'=>0,'growth'=>0]);
  134. }
  135. }
  136. /**
  137. * @title 分享直播赠送积分
  138. * @desc 分享直播赠送积分
  139. * @author qc
  140. * @url /api/Live/shareLiveNotice
  141. * @method POST
  142. * @header name:Authorization require:1 desc:Token
  143. * @return name:integral type:int default:-- desc:获得积分数
  144. * @return name:growth type:int default:-- desc:获得成长值
  145. */
  146. public function shareLiveNotice()
  147. {
  148. $share_integral_set =Db::table('system_config')->where('name','share_integral')->value('value');
  149. $share_integral = intval(trim($share_integral_set));
  150. $max_integral_set =Db::table('system_config')->where('name','max_integral')->value('value');
  151. $max_integral = intval(trim($max_integral_set));
  152. $check_integral = Db::table('integral_info')
  153. ->where('user_id','=',$this->uid)
  154. ->where('create_at','> time',date('Y-m-d 00:00:00'))
  155. ->where('type','=',9)
  156. ->sum('integral');
  157. if($share_integral <= 0 || $max_integral<= 0) $this->error('分享设置有误');
  158. if($share_integral + intval($check_integral) > $max_integral ) $this->error('分享活得积分达到每日上限');
  159. update_user_integral($this->uid,$share_integral,9,'恭喜亲通过分享直播预告获得'.$share_integral.'积分');
  160. update_user_growth($this->uid,$share_integral,9,'恭喜亲通过分享直播预告获得'.$share_integral.'成长值');
  161. $this->success('ok',['integral'=>$share_integral,'growth'=>$share_integral]);
  162. }
  163. }