在线音乐网站公众号小程序源码,第三篇
作者:互联网
接着前面两篇,现在是第三篇,如果需要用到的,大家可以看看前面的就可以了。
在我的文章主页有的,现在也是讲会员部分的。
有其他问题的可以联系我的扣就行了,是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