Commit 07c319fc by 杨昕

优化代码

parent 349d0e0a
Pipeline #14160 passed with stages
in 5 minutes 7 seconds
...@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; ...@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
use App\Exceptions\FormException; use App\Exceptions\FormException;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\MediaCategoryModel;
use App\Model\MediaModel; use App\Model\MediaModel;
use App\Model\QiniuModel; use App\Model\QiniuModel;
use App\Tool\Constant; use App\Tool\Constant;
...@@ -190,9 +191,10 @@ class MediaController extends Controller ...@@ -190,9 +191,10 @@ class MediaController extends Controller
); );
//shop_id为100时,代表的是北大学堂的视频
if ($request->shop_id=='100'){ if ($request->shop_id=='100'){
$params['media_type'] = "5f3d073a033f5a336b2b4346"; $catg = MediaCategoryModel::getCategoryByName("北大学堂");
$params['media_type'] = $catg['_id'];
} }
$request->replace(array_merge($request->all(),$params)); $request->replace(array_merge($request->all(),$params));
......
...@@ -200,4 +200,26 @@ class MediaCategoryModel extends Eloquent ...@@ -200,4 +200,26 @@ class MediaCategoryModel extends Eloquent
return $flag; return $flag;
} }
/**
* 根据媒资名称,获取媒资信息。
* @param $name
* @return mixed
* @throws DatabaseException
*/
public static function getCategoryByName($name){
try{
$catg = MediaCategoryModel::where("name",$name)->first();
if (empty($catg)){
throw new \Exception("店铺不存在");
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $catg;
}
} }
...@@ -177,19 +177,18 @@ class MediaModel extends Eloquent ...@@ -177,19 +177,18 @@ class MediaModel extends Eloquent
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
//replace 不为空的时候代表做视频替换操作,1.需要清空CDN缓存,2.将原来的视频保存至回收站,3.更新视频信息
if ($request->replace){ if ($request->replace){
$recycleId = RecycleModel::addRecycle($media_id); $recycleId = RecycleModel::addRecycle($media_id);
$call_back = $mediaCatg['call_back']; $call_back = $mediaCatg['call_back'];
#清空CND缓存
$url = getRbac($request,$call_back,$mediaCatg['media_category_id'] ,$type='clear_cache'); $url = getRbac($request,$call_back,$mediaCatg['media_category_id'] ,$type='clear_cache');
http_request_code($url,null,'POST',['mediaId'=>$media_id]); http_request_code($url,null,'POST',['mediaId'=>$media_id]);
#更新视频信息
self::updatehookMedia($request,$media_id); self::updatehookMedia($request,$media_id);
if (!$recycleId){ if (!$recycleId){
throw new \Exception('回收站保存失败'); throw new \Exception('回收站保存失败');
} }
...@@ -221,16 +220,6 @@ class MediaModel extends Eloquent ...@@ -221,16 +220,6 @@ class MediaModel extends Eloquent
$end_time = new UTCDateTime(strtotime($request->end_time) * 1000); $end_time = new UTCDateTime(strtotime($request->end_time) * 1000);
$create_time = new UTCDateTime(time() * 1000);; $create_time = new UTCDateTime(time() * 1000);;
// $start_time = $request->start_time;
// $end_time = $request->end_time;
// $create_time = date('Y-m-d H:i:s',time());
// if ($request->shop_id=='100'){
// $mediaCatg = MediaCategoryModel::where('_id','5f3d073a033f5a336b2b4346')->first();
// }
/** /**
* 处理文件名称,确认是否包含"&"符合 * 处理文件名称,确认是否包含"&"符合
......
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