Commit f91cc4e8 authored by yinxiaoling's avatar yinxiaoling

异常捕获

parent aa44aef9
......@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Route; */
trait Tool
{
public function getAllowLoginUser(){
return ['user_name'=>'yxl001','user_sn'=>'SYSUSER|9da548a2e392a679eb274a0b2abeb627','parent_sn'=>'ljs'];
return ['user_name'=>'yxl002','user_sn'=>'SYSUSER|9da548a2e392a679eb274a0b2abeb627','parent_sn'=>'ljs'];
}
public function getAllowProjects($style=0){
$projectInfo = [['sn'=>'projects|a3a4259352c8e964ad6ea6c5ee8a7208','name'=>'liuy-转人工测试'],['sn'=>'projects|17a71649f886bce050d637e86a3c85e8','name'=>'小贷-测试林俊生']];
......
......@@ -21,6 +21,7 @@ class StrategySetController extends Controller
use Tool;
public function index(){
try{
$projectArr = $this->getAllowProjects(1);
$strategyInfo = StrategySet::all()->toArray();
$listInfo = [];
......@@ -36,9 +37,14 @@ class StrategySetController extends Controller
$listInfo[] = $v;
}
return $this->successWithInfo($listInfo);
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
public function store(Request $request,StrategyService $StrategyService){
try{
$allowLoginUser = $this->getAllowLoginUser();
$validator = Validator::make($request->all(), [
......@@ -99,9 +105,14 @@ class StrategySetController extends Controller
//返回成功数、失败数、失败导出文件
$returnArr = compact('total','successTotal','failTotal','failDataFile');
return $this->successWithInfo($returnArr);
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
//删除策略
public function destroy($strategySn){
try{
DB::transaction(function () use ($strategySn) {
// 删除逻辑 注意多表关联的情况
StrategySet::where('strategy_sn', $strategySn)->delete();
......@@ -110,6 +121,10 @@ class StrategySetController extends Controller
StrategyTask::where([['strategy_sn', $strategySn],['is_created',0]])->delete(); //删除未新建的任务数据
});
return $this->successWithInfo('操作完成');
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
//子账号列表
public function getUsersList(){
......@@ -165,6 +180,7 @@ class StrategySetController extends Controller
//导入excel数据
public function importExcelData(Request $request,StrategyService $StrategyService){
try{
$validator = Validator::make($request->all(), [
'strategy_sn' => 'required',
'upload' => 'required'
......@@ -205,5 +221,9 @@ class StrategySetController extends Controller
}else{
return $this->errorWithInfo('请选择导入文件', 401);
}
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
}
......@@ -16,7 +16,7 @@ class StrategyTaskController extends Controller
use Tool;
public function index(Request $request){
//搜索分页?
try{
$pageSize=request()->pageSize;
$projectArr = $this->getAllowProjects(1);
//$strategyInfo = StrategyTask::all()->toArray();
......@@ -66,17 +66,20 @@ class StrategyTaskController extends Controller
}
}
return $this->successWithInfo($strategyInfo);
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
public function update(Request $request, $id)
{
try{
$phone = $request->phone;
$name = $request->name;
$callTime = $request->call_time;
$validator = Validator::make($request->all(), [
'phone' => 'required|regex:/^1[3-8]{1}[0-9]{9}$/',
'user_sn' => 'required',
......@@ -100,7 +103,10 @@ class StrategyTaskController extends Controller
$taskInfo->call_time = $callTime;
$taskInfo->save();
return $this->successWithInfo('更新成功');
}catch (\Exception $e){
Log::channel('api')->error($e->getFile().'-'.$e->getLine().'-'.$e->getMessage());
return $this->errorWithInfo('操作异常', 500);
}
}
......
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