Commit 5f182b73 by 杨昕

第三方媒资编号不能为空

parent a39008dd
Pipeline #13104 passed with stages
in 45 seconds
......@@ -181,7 +181,7 @@ class MediaController extends Controller
$params = array(
'media_id' => 'mda-'.generateRandomNum(16),
'media_id' => MediaModel::getMediaId(),
'media_type'=> '5efa9cb5d16f5a214671fd86',//默认,中公网校
'start_time'=> $data_time,
'end_time' => $data_time,
......
......@@ -798,7 +798,32 @@ class MediaModel extends Eloquent
}
/**
* @return string
* @throws DatabaseException
*/
public static function getMediaId(){
try{
$i = 0;
do {
$media_id = "mda-".generateRandomNum(16);
$media = MediaModel::find($media_id);
$i ++;
} while ($i < 3 && !empty($media) );
if ($i == 3){
throw new \Exception('获取媒资编号失败');
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return 'mda-'.$media_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