$user_id, 'status' => 1, ]; $check = Db::name('live_room_admin')->where('room_no',$room_no)->where('user_id',$user_id)->whereOr(function($query) use ($whereor) { $query->where($whereor); })->find(); if(empty($check)){ $this->error('没有操作权限'); } $rs = empty($check) ? false : true; return $rs; } //商城所有商品列表 public function goods_index() { //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); //全平台所有商品列表 $service = new GoodsService(); $service->up(); $keyword = input('keyword','','trim'); if ($keyword) { $service->search($keyword); } $goods = $service->order('weigh desc,id desc')->select_autopage(); $goods = collection($goods)->toArray(); $goods = list_domain_image($goods,['image']);//主图 //本直播间已经有的,标记 $goods_ids = Db::name('live_room_goods')->where('room_no',$room_no)->where('status','up')->column('goods_id'); foreach($goods as $key => $good){ $good['goods_added'] = 0; if(in_array($good['id'],$goods_ids)){ $good['goods_added'] = 1; } $goods[$key] = $good; } $this->success('获取成功', $goods); } //直播间商品列表顶部三个统计 public function liveroom_index_tongji() { //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); $session = input('session','','trim'); $room_log = Db::name('live_room_log')->where('session',$session)->where('room_no',$room_no)->find(); $rs = [ 'sales_total_price' => $room_log['order_total_amount'], //销售额 'paid_ordernum' => $room_log['order_paidnum'], //支付订单量 'uv' => $room_log['uv'], //访客数 ]; $this->success('获取成功', $rs); } //直播间商品列表 public function liveroom_index() { //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); //直播间上架商品 $goods_list = Db::name('live_room_goods')->field('goods_id,goods_no,is_top')->where('room_no',$room_no)->where('status','up')->order('is_top desc,goods_no asc,id desc')->select(); if(empty($goods_list)) { $this->success(1,null); } $goods_ids = array_column($goods_list,'goods_id'); //商品列表 $service = new GoodsService(); $service->up(); $keyword = input('keyword','','trim'); if ($keyword) { $service->search($keyword); } $service->whereIds($goods_ids); $goods = $service->select_autopage(); $goods = collection($goods)->toArray(); $goods = list_domain_image($goods,['image']);//主图 //追加字段 foreach($goods as $key => $good){ foreach($goods_list as $k => $v){ if($good['id'] == $v['goods_id']){ $good['is_top'] = $v['is_top']; $good['goods_no'] = $v['goods_no']; } } $goods[$key] = $good; } $rs = [ 'number' => count($goods_ids), 'list' => $goods, ]; $this->success('获取成功', $rs); } //添加 public function add(){ //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); //检查商品 $goods_id = input('goods_id',0,'intval'); $goods_info = Db::name('shopro_goods')->where('id',$goods_id)->where('status','up')->find(); if(empty($goods_info)){ $this->error('该商品已下架'); } //商品序号拿最大的+1 $max = Db::name('live_room_goods')->where('room_no',$room_no)->order('goods_no desc')->value('goods_no'); $max = $max ? $max : 0; $new_goods_no = $max + 1; //直播间上架商品 $goods_check = Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id',$goods_id)->find(); if($goods_check){ if($goods_check['status'] == 'up'){$this->error('该商品已存在');} //重新上架 Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id',$goods_id)->update(['status'=>'up','goods_no'=>$new_goods_no,'update_time'=>time()]); }else{ $room_info = Db::name('live_room')->where('room_no',$room_no)->find(); $new = [ 'room_id' => $room_info['id'], 'room_no' => $room_info['room_no'], 'user_id' => $room_info['user_id'], 'goods_id' => $goods_id, 'goods_no' => $new_goods_no, 'status' => 'up', 'create_time' => time(), 'update_time' => time(), ]; Db::name('live_room_goods')->insertGetId($new); } $this->success('添加成功'); } //删除 public function down(){ //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); $goods_id = input('goods_id',''); $goods_id = explode(',',$goods_id); Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id','IN',$goods_id)->update(['status'=>'down','goods_no'=>0]); $this->success('操作成功'); } //设置为讲解中,取消讲解 public function top(){ //鉴权 $room_no = input('room_no','','trim'); $user = auth_user(); $this->check_auth($room_no,$user['id']); $goods_id = input('goods_id',0,'intval'); $is_top = input('is_top',0,'intval'); //取消讲解 if($is_top == 0){ Db::name('live_room_goods')->where('room_no',$room_no)->update(['is_top'=>0]); //修改房间属性 $top_good[] = [ 'key' => 'top_good', 'value' => json_encode((object)[]), ]; $im = new TencentIm(); $im->modify_group_attr($room_no,$top_good); $this->success('操作成功'); } //直播间商品 $check = Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id',$goods_id)->where('status','up')->find(); if(empty($check)){ $this->error('不存在的商品'); } //商品 $service = new GoodsService(); $service->up(); $service->where('id',$goods_id); $goods = $service->find(); if(empty($goods)){ $this->error('该商品已下架'); } //精简商品 $goods = json_decode(json_encode($goods),true); $goods = [ 'id' => $goods['id'], 'title' => $goods['title'], 'image' => localpath_to_netpath($goods['image']), 'price' => $goods['price'], 'is_sku'=> $goods['is_sku'], 'goods_sku_price_id' => 0, ]; if($goods['is_sku'] != 1){ $goods['goods_sku_price_id'] = Db::name('shopro_goods_sku_price')->where('goods_id',$goods['id'])->value('id'); } //其他取消讲解,讲解这个 $goods_id = input('goods_id',0,'intval'); Db::name('live_room_goods')->where('room_no',$room_no)->update(['is_top'=>0]); Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id',$goods_id)->update(['is_top'=>1]); //修改房间属性 $top_good[] = [ 'key' => 'top_good', 'value' => json_encode($goods), ]; $im = new TencentIm(); $im->modify_group_attr($room_no,$top_good); $this->success('操作成功'); } //获取属性 public function get_room_attr(){ $room_no = input('room_no','','trim'); $im = new TencentIm(); // $im->delete_group_attr($room_no,'jiangjie'); $im->get_group_attr($room_no); dump($im->getData()); } }