Commit e5b99af9 by 杨昕

媒资列表

parent ff453931
Pipeline #9805 passed with stages
in 33 seconds
......@@ -13,6 +13,11 @@ class MediaCategoryModel extends Eloquent
protected $primaryKey = '_id';
public function medias()
{
return $this->hasMany('MediaModel');
}
/**
* 查询媒资列表
* @param $request
......
......@@ -15,6 +15,12 @@ class MediaModel extends Eloquent
protected $primaryKey = '_id';
public function media_category()
{
return $this->belongsTo('MediaCategoryModel');
}
public static function mediaList($request){
try{
......@@ -22,12 +28,21 @@ class MediaModel extends Eloquent
if ($request->name){
$where['name'] = $request->name;
}
$medias = DB::connection('mongodb')->collection('media_category')->leftJoin('media_category',"media.media_type",'media_category._id')->where($where)->paginate(10);
$mediaCatgs = MediaCategoryModel::select("_id","name")->get()->toArray();
$tmp = [];
foreach ($mediaCatgs as $catg){
$tmp[$catg['_id']] = $catg['name'];
}
$medias = MediaModel::where($where)->paginate(10);
foreach ($medias as $media){
$media['media_type'] = $tmp[$media['media_type']];
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $medias;
}
......@@ -45,8 +60,6 @@ class MediaModel extends Eloquent
* 判断媒资ID是否存在
*/
$media_id = $request->media_id;
$media = MediaModel::find($media_id);
if (!empty($media)){
throw new \Exception('媒资已经存在');
......@@ -58,6 +71,9 @@ class MediaModel extends Eloquent
*/
$media_info = explode("&",$request->media_name);
if (count($media_info)!=2){
throw new \Exception('视频名称格式不对');
}
$mediaCatg = MediaCategoryModel::where('_id',$request->media_type)->first();
if (empty($mediaCatg)){
......@@ -68,6 +84,7 @@ class MediaModel extends Eloquent
'_id' => $media_id,
'media_name' => $request->media_name,
'media_type' => $mediaCatg->_id,
'media_category'=> $mediaCatg['name'],
'class_id' => $media_info[0],
'class_name' => $media_info[1],
'media_url' => $request->media_url,
......@@ -77,12 +94,9 @@ class MediaModel extends Eloquent
];
$id = MediaModel::insertGetId($data);
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $id;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment