• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

音乐dj网站小程序公众号开发项目-第三篇

php 搞代码 3年前 (2022-02-28) 27次浏览 已收录 0个评论


接着后面两篇,当初是第三篇,如果须要用到的,大家能够看看后面的就能够了。

在我的文章主页有的,当初也是讲会员局部的。

有其余问题的能够分割我的扣就行了,是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' => '音乐批改失败,请稍后重试']);
}

}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:音乐dj网站小程序公众号开发项目-第三篇

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址