ITPub博客

首页 > 应用开发 > IT综合 > 快速实现直播视频app源码的关注功能

快速实现直播视频app源码的关注功能

IT综合 作者:云豹科技晓彤 时间:2021-09-03 16:35:47 0 删除 编辑

为了方便用户寻找自己喜欢的主播、商家等信息,直播视频app源码实现了关注的功能,这样用户就可以快速找到关注的主播或商家,下面就是实现直播视频app源码关注功能的代码。

 public function createAttention(Request $request){
        $my_attention_id = $request->get('my_attention_id');//我关注的商家id
        $seller_id = $this->seller->id;
        try{
            // 记录或更新我关注的
            $myInfo = SellerAttention::where('seller_id',$seller_id)->first();
            if(!empty($myInfo)){
                if(empty($myInfo['my_attention_users'])){
                    $my_attention_users = $my_attention_id;
                }else{
                    $my_attention_users = $myInfo['my_attention_users'] . ','.  $my_attention_id;
                }
                SellerAttention::where('seller_id',$seller_id)->update(['my_attention_users'=>$my_attention_users]);
            }else{
                
                $data = [
                    'seller_id'=>$seller_id,
                    // 'user_id'=>$this->user->id,
                    'my_attention_users'=>$my_attention_id
                ];
                SellerAttention::create($data); 
            }   
            // 被关注商家也要记录数据
            $heInfo = SellerAttention::where('seller_id',$my_attention_id)->first();
            if(!empty($heInfo)){
                if(empty($heInfo['attention_me_users'])){
                    $attention_me_users = $seller_id;
                }else{
                    $attention_me_users = $heInfo['attention_me_users'] . ',' . $seller_id;
                }
                SellerAttention::where('seller_id',$my_attention_id)->update(['attention_me_users'=>$attention_me_users]);
            }else{
                
                $data = [
                    'seller_id'=>$my_attention_id,
                    'attention_me_users'=>$seller_id
                ];
                SellerAttention::create($data); 
            }
        }catch  (\Exception $e){
            // throw new \Exception('关注失败!' . $e->getMessage());
            return $this->resFailed(707, $e->getMessage());
        }
        
        return $this->resSuccess('关注成功!');
    }

数据表如下:
在这里插入图片描述

 

/*
    * 获取关注商家
    * @Author swl 
    * @param type (0:我关注的 1:关注我的 2:互相关注)
    */
    public function attentionInfo(Request $request){
        
        $type = $request->get('type','0');
        $info = SellerAttention::where('seller_id',1)->first();
        
        $my_attention = explode(',', $info['my_attention_users']);
        $attention_me = explode(',', $info['attention_me_users']);
        switch ($type) {
            case '0':
                $sellers = $my_attention;
                break;
            case '1':
                $sellers = $attention_me;
                break;
            default:
                // 获取互相关注的商家
                $sellers = array_intersect($my_attention,$attention_me);
                break;
        }
        $sellerList = SellerConfig::whereIn('seller_id',$sellers)->get();
        return $this->resSuccess($sellerList);
    }
/*
    * 取消关注商家
    * @Author swl 2020-3-26
    * @param seller_id
    */
    public function cancelAttention(Request $request){
        $he_seller_id = $request->get('seller_id');
        // $my_seller_id = $this->seller->id;
        if(empty($he_seller_id)){
            return $this->resFailed(707, '商家id不能为空');
        }
        $my_seller_id = 1030;
        $my = SellerAttention::where('seller_id',$my_seller_id)->first();
        $my_attention = explode(',', $my['my_attention_users']);
        $my_attention = array_merge(array_diff($my_attention, array($he_seller_id)));
        $he = SellerAttention::where('seller_id',$he_seller_id)->first();
        $attention_me = explode(',', $he['attention_me_users']);
        $attention_me = array_merge(array_diff($attention_me, array($my_seller_id)));
        $my_attention = implode(',', $my_attention);
        $attention_me = implode(',', $attention_me);
        try{
            SellerAttention::where('seller_id',$my_seller_id)->update(['my_attention_users'=>$my_attention]);
            SellerAttention::where('seller_id',$he_seller_id)->update(['attention_me_users'=>$attention_me]);
        }catch  (\Exception $e){
    
            return $this->resFailed(707, $e->getMessage());
        }
        return $this->resSuccess('取消成功!');
    }

以上代码,主要实现直播视频app源码如何实现商家的关注和取关的,但是实现关注的原理都差不多。

声明:本文由云豹科技转发我是等闲之辈博客,如有侵权请联系作者删除


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70002045/viewspace-2790333/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
音视频软件开发相关知识科普账号

注册时间:2021-06-11

  • 博文量
    163
  • 访问量
    60338