123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-04-30
- // +—————————————————————————————————————————————————————————————————————
- class Model_Music extends PhalApi_Model_NotORM {
-
- /*获取分类列表*/
- public function classify_list(){
- $list=DI()->notorm->user_music_classify->select("id,title,img_url")->where("isdel=0")->order("orderno")->fetchAll();
- if(!$list){
- return 1001;
- }
- foreach ($list as $k => $v) {
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- }
- return $list;
- }
- /*获取音乐列表*/
- public function music_list($classify,$uid,$p){
- $nums=20;
- $start=($p-1)*$nums;
- $where=" isdel=0";
- if($classify>0){
- $where.=" and classify_id={$classify}";
- }
- $list=DI()->notorm->user_music->select("id,title,author,img_url,length,file_url,use_nums")->where($where)->order("use_nums desc")->limit($start,$nums)->fetchAll();
- if(!$list){
- return 1001;
- }
-
- if($uid<1){ //游客
- foreach ($list as $k => $v) {
- $list[$k]['iscollect']=0;
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }else{
-
- //获取本人收藏列表
- $collectLists=DI()->notorm->user_music_collection->select("music_id")->where("uid=? and status=1",$uid)->fetchAll();
- $collects=array();
- foreach ($collectLists as $val) {
- $collects[]=$val['music_id'];
- }
- foreach ($list as $k => $v) {
- if(in_array($v['id'],$collects)){
- $list[$k]['iscollect']="1";
- }else{
- $list[$k]['iscollect']="0";
- }
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }
-
- return $list;
- }
- /*搜索音乐(模糊查询本地,按照使用量排序)*/
- public function searchMusic($keywords,$uid,$p){
-
- $nums=50;
- $start=($p-1)*$nums;
- $where="1=1";
- if($keywords!=""){
- $where .=" and (title like '%".$keywords."%') or author like '%".$keywords."%'";
- }
- $list=DI()->notorm->user_music->select("id,title,author,img_url,length,file_url,use_nums")->where($where)->order("use_nums desc")->limit($start,$nums)->fetchAll();
- if(!$list){
- return 1001;
- }
- if($uid<1){ //游客
- foreach ($list as $k => $v) {
- $list[$k]['iscollect']=0;
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }else{
- //获取本人收藏列表
- $collectLists=DI()->notorm->user_music_collection->select("music_id")->where("uid=? and status=1",$uid)->fetchAll();
- $collects=array();
- foreach ($collectLists as $val) {
- $collects[]=$val['music_id'];
- }
- foreach ($list as $k => $v) {
- if(in_array($v['id'],$collects)){
- $list[$k]['iscollect']="1";
- }else{
- $list[$k]['iscollect']="0";
- }
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }
- return $list;
- }
- /*收藏/取消收藏音乐*/
- public function collectMusic($uid,$musicid){
- //判断音乐是否存在
- $info=DI()->notorm->user_music->select("title,addtime")->where("id=?",$musicid)->fetchOne();
- if(!$info){
- return 1001;
- }
- //判断用户是否收藏过该视频
- $isexist=DI()->notorm->user_music_collection->select("*")->where("uid='{$uid}' and music_id='{$musicid}'")->fetchOne();
- //已经收藏过
- if($isexist){
- if($isexist['status']==1){ //已收藏
- //将状态改为取消收藏
- $result=DI()->notorm->user_music_collection->where("uid=? and music_id=?",$uid,$musicid)->update(array("status"=>0,"updatetime"=>time()));
- if($result!==false){
- return 200;
- }else{
- return 201;
- }
- }else{ //改为收藏
- //将状态改为收藏
- $result=DI()->notorm->user_music_collection->where("uid=? and music_id=?",$uid,$musicid)->update(array("status"=>1,"updatetime"=>time()));
- if($result!==false){
- return 300;
- }else{
- return 301;
- }
- }
-
- }else{
- //向收藏表中写入记录
- $data=array("uid"=>$uid,"music_id"=>$musicid,'addtime'=>time(),'status'=>1);
- $result=DI()->notorm->user_music_collection->insert($data);
- if($result!==false){
- return 300;
- }else{
- return 301;
- }
- }
- }
- /*获取用户收藏背景音乐列表*/
- public function getCollectMusicLists($uid,$p){
- $nums=20;
- $start=($p-1)*$nums;
- $where="uid='{$uid}' and status=1";
- $list=DI()->notorm->user_music_collection->select("music_id,addtime")->where($where)->order("addtime desc")->limit($start,$nums)->fetchAll();
- if(!$list){
- return 0;
- }
- foreach ($list as $k => $v) {
- $musicinfo=DI()->notorm->user_music->select("title,author,img_url,length,file_url,use_nums")->where("id=?",$v['music_id'])->fetchOne();
- unset($list[$k]['addtime']);
- $list[$k]['collecttime']=datetime($v['addtime']); //收藏时间
- $list[$k]['title']=$musicinfo['title'];
- $list[$k]['author']=$musicinfo['author'];
- $list[$k]['img_url']=get_upload_path($musicinfo['img_url']);
- $list[$k]['length']=$musicinfo['length'];
- $list[$k]['file_url']=get_upload_path($musicinfo['file_url']);
- $list[$k]['use_nums']=$musicinfo['use_nums'];
- $list[$k]['iscollect']='1';
- $list[$k]['id']=$v['music_id']; //为了app端模板解析统一,所以重新添加了一个id字段
- }
- return $list;
- }
- /*获取热门音乐列表*/
- public function hotLists($uid){
- $start=0;
- $nums=10;
- $where=" isdel=0";
- $list=DI()->notorm->user_music->select("id,title,author,img_url,length,file_url,use_nums")->where($where)->order("use_nums desc")->limit($start,$nums)->fetchAll();
- if(!$list){
- return 1001;
- }
-
- if($uid<1){ //游客
- foreach ($list as $k => $v) {
- $list[$k]['iscollect']=0;
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }else{
-
- //获取本人收藏列表
- $collectLists=DI()->notorm->user_music_collection->select("music_id")->where("uid=? and status=1",$uid)->fetchAll();
- $collects=array();
- foreach ($collectLists as $val) {
- $collects[]=$val['music_id'];
- }
- foreach ($list as $k => $v) {
- if(in_array($v['id'],$collects)){
- $list[$k]['iscollect']=1;
- }else{
- $list[$k]['iscollect']=0;
- }
- $list[$k]['img_url']=get_upload_path($v['img_url']);
- $list[$k]['file_url']=get_upload_path($v['file_url']);
- }
- }
-
- return $list;
- }
-
- }
|