乐趣区

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


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

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

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

}

退出移动版