Commit 96d66c68 by 杨昕

添加异常处理

parent 03421914
Pipeline #9856 passed with stages
in 33 seconds
......@@ -3,6 +3,7 @@
namespace App\Model;
use App\Exceptions\DatabaseException;
use App\Tool\Constant;
use Illuminate\Support\Facades\DB;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use MongoDB\Client;
......@@ -35,7 +36,7 @@ class MediaModel extends Eloquent
try{
$test = MediaModel::query()->raw(function ($collection) use($request){
$aggregate = [];
$aggregate[]['$limit'] = Constant::PAGE_NUMBER??$request->pagesize;
if (isset($request->media_id)){
......@@ -50,7 +51,8 @@ class MediaModel extends Eloquent
$aggregate[]['$match']['media_name'] = ['$regex' => $request->media_name ];
}
dd($aggregate);
return $collection->aggregate($aggregate)->toArray();
......@@ -99,6 +101,13 @@ class MediaModel extends Eloquent
*/
$media_id = $request->media_id;
$media = MediaModel::where("_id",$media_id)->first();
if (!empty($media)){
throw new \Exception("媒资编号已被使用");
}
//hb15011&河北公务员考试试题
/**
* 媒资名称是由课程编号与课程名称组成
......
<?php
namespace App\Tool;
/**
* 主节点常量
*/
class Constant {
# 接口响应成功
const RESPONSE_SUCCESS = 0;
# 表单验证失败
const EXCEPTION_FORM_FAIL = 1;
# 数据库操作失败
const EXCEPTION_DATA_FAIL = 2;
# 控制器异常
const EXCEPTION_CTRL_FAIL = 3;
# 默认分页数
const PAGE_NUMBER = 10;
# 升序
const SORT_ASC = 'asc';
# 降序
const SORT_DESC = 'desc';
}
\ No newline at end of file
......@@ -39,6 +39,8 @@ class SrsHookValidate {
$params = $request->all();
$request->replace(self::filterField($params,array_keys($rules)));
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), $rules,$message);
if ($callback) {
$validator->after(function() use ($callback,$validator,$request){
......
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