ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

在线音乐网站公众号小程序源码,第三篇

2021-09-23 13:58:42  阅读:149  来源: 互联网

标签:第三篇 return extend 在线音乐 title 源码 result post id


 接着前面两篇,现在是第三篇,如果需要用到的,大家可以看看前面的就可以了。

在我的文章主页有的,现在也是讲会员部分的。

有其他问题的可以联系我的扣就行了,是8582-36016

个人音乐页面

public function index()
    {
        $title = '我的音乐 - ' . config('web_site_title');
        return $this->fetch('', ['meta_title' => $title]);
    }

    /**
     * 个人音乐待审页面
     * @return \think\response
     */
    public function audit()
    {
        $title = '审核的音乐 - ' . config('web_site_title');
        return $this->fetch('', ['meta_title' => $title]);
    }
    
    /**
     * 个人音乐驳回页面
     * @return \think\response
     */
    public function back()
    {
        $title = '驳回列表 - ' . config('web_site_title');
        return $this->fetch('', ['meta_title' => $title]);
    }

    /**
     * 个人音乐下载页面
     * @return \think\response
     */
    public function down()
    {
        $title = '我的下载 - ' . config('web_site_title');
        return $this->fetch('', ['meta_title' => $title]);
    }

    /**
     * 创建歌曲
     * @return \think\response
     */
    public function create()
    {
        if(config('only_musician_upload') && !$this->user['is_musician']) {
            $this->error('你还没有认证音乐人,请先认证!!', 'user/Musician/auth', '', 5);
        }
        
        //获取当前用户的专辑
        $albums = Album::where('add_uid', UID)->field('id,name')->select();
        $this->meta_title = '分享音乐 - ' . config('web_site_title');
        return $this->fetch('share', ['albums' => $albums]);
    }

编辑歌曲

public function edit($id = 0)
    {
        if (!intval($id)) {
            $this->error('参数错误');
        }
    
        $model = new Songs();
        $map['id'] = $id;
        $map['status'] = 0;
        $map['up_uid'] =$this->user['uid'];
        
        $song = $model->where($map)
            ->field('id,name,genre_id,cover_id,cover_url,artist_id,artist_name,album_id,album_name')
            ->with(['extend' => function($query){
                $query->field('mid,listen_url,introduce,server_id,listen_file_id');
            }])
            ->find();
        
        if (!$song) {
            $this->error('音乐不存在');
        }
        
        $info = $song->getData();
        $info = array_merge($info, $song->extend->getData());
        
        //获取当前用户的专辑
        $albums = Album::where('add_uid', UID)->field('id,name')->select();
        $this->meta_title = '编辑音乐 - ' . config('web_site_title');
        return $this->fetch('share', ['albums' => $albums, 'data' => $info]);
    }
    
    /**
     * 保存创建的歌曲
     * @param Request $request
     * @return \think\response
     */
    public function save(Request $request)
    {
        if(config('only_musician_upload') && !$this->user['is_musician']) {
            return json(['code' => 40403, 'error' => '你还没有认证音乐人,请先认证']);
        }
        
        $post = $request->post();
        $post['up_uid'] = $this->user['uid'];
        
        
        $result = $this->validate($post, 'Songs.user_create');
        if (true !== $result) {
            return json(['code' => 40030, 'error' => $result]);
        }
        
        $extend = $post['extend'];
        $result = $this->validate($extend, 'SongsExtend');
        if (true !== $result) {
            return json(['code' => 40030, 'error' => $result]);
        }
        $post['status'] = 2;
        $songs = new Songs();
        
        if ($songs->allowField(true)->save($post)) {
            if ($songs->extend()->save($extend)) {
                return json([
                    'code' => 0,
                    'msg' =>'音乐[' . $songs->name . ']添加成功,请等待审核!',
                    'url' => url('user/Music/audit')
                ]);
            }
            $songs->delete();
        }
        return json(['code' => 40500, 'msg' => '添加失败,请稍后重试']);
    }

更新歌曲

public function update(Request $request)
    {
        $post = $request->post();
        $map['up_uid'] = $post['up_uid'] = $this->user['uid'];
        $id = $post['id'];
        
        if (empty($id)) {
            return json(['code' => 40004, 'error' => '参数错误']);
        }
    
        $result = $this->validate($post, 'Songs.user_create');
    
        if (true !== $result) {
            return json(['code' => 40030, 'error' => $result]);
        }
        $extend = $post['extend'];
        $result = $this->validate($extend, 'SongsExtend');
        if (true !== $result) {
            return json(['code' => 40030, 'error' => $result]);
        }
    
        $model = new Songs();
        $map['id'] = $id;
        $map['status'] = 0;
        
        if (empty($id) || !$song = $model->where($map)->find()) {
            return json(['code' => 40404, 'error' => '你编辑的音乐不存在']);
        }
        $post['status'] = 2;
        $data = $model->checkUpdateField($post, $song);
        $extend['mid'] = $data['id'];
        $res = $model->isUpdate(true)->allowField(true)->save($data);
        $res2 = $model->extend()->update($extend);
    
        if ($res || $res2) {
            return json([
                'code' => 0,
                'msg' =>'音乐[' . $model->name . ']修改成功,请等待审核!',
                'url' => url('user/Music/audit')
            ]);
        }

        return json(['code' => 40500, 'msg' => '音乐修改失败,请稍后重试']);
    }
}

标签:第三篇,return,extend,在线音乐,title,源码,result,post,id
来源: https://blog.csdn.net/tengda7/article/details/120433468

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有