Commit ac66175f authored by zhoujun's avatar zhoujun

预警接口

parent 3bbe8182
Pipeline #2069 passed with stage
in 0 seconds
......@@ -229,9 +229,20 @@ class WarnController extends BaseController
* @date 2021/07/31
* @author live
*/
public function getConfigSetStatus()
public function getConfigSetStatus(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'id' => 'required|numeric',
'status' => 'required|numeric'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getConfigSetStatus($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
......@@ -240,9 +251,20 @@ class WarnController extends BaseController
* @date 2021/07/31
* @author live
*/
public function getConfigSetAllStatus()
public function getConfigSetAllStatus(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'ids' => 'required|string',
'status' => 'required|numeric'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getConfigSetAllStatus($postData);
return $this->getSuccessMsg($data['list'],$data['msg']);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
......
......@@ -20,4 +20,8 @@ interface IWarnService
public function getConfigEdit($postData); //预警配置编辑
public function getConfigDel($postData); //预警配置删除
public function getConfigSetStatus($postData); //设置预警配置状态
public function getConfigSetAllStatus($postData); //批量设置预警状态
}
\ No newline at end of file
......@@ -261,4 +261,54 @@ class WarnService implements IWarnService
if ($list->delete()) return true;
throw new Exception(config('msg.common.1003'), 1003);
}
/**
* 预警配置状态设置
* @return araay
* @date 2021/07/31
* @author live
*/
public function getConfigSetStatus($postData)
{
$list = WarnConfigModel::where('id', $postData['id'])->first();
if (!$list) throw new Exception(config('msg.common.1002'), 1002);
if($list->status == $postData['status']) throw new Exception(config('msg.common.1009'), 1009);
$list->status = $postData['status'];
$list->op_user = $postData['user'] ?? '';
$list->updated_at = $this->time;
if ($list->save()) return true;
throw new Exception(config('msg.common.1003'), 1003);
}
/**
* 批量设置预警状态
* @return araay
* @date 2021/07/31
* @author live
*/
public function getConfigSetAllStatus($postData)
{
$array = ['list'=>true,'msg'=>''];
$ids = explode('#',$postData['ids']);
if(empty($ids)) throw new Exception(config('msg.common.1015'), 1015);
$lists = WarnConfigModel::whereIn('id', $ids)->get();
if ($lists->isEmpty()) throw new Exception(config('msg.common.1002'), 1002);
$total = $lists->count();
$succuss = 0;
$fail = 0;
foreach($lists as $list){
$list->status = $postData['status'];
$list->op_user = $postData['user'] ?? '';
$list->updated_at = $this->time;
if ($list->save()){
$succuss++;
}else{
$fail++;
}
}
$array['msg'] = '总共操作'.$total.'条数据,其中成功'.$succuss.'条,失败'.$fail.'条';
return $array;
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ return [
'1012' => '用户ID不存在',
'1013' => '请填写有效的预警手机号',
'1014' => '平台和渠道为必填项',
'1015' => '请选择有效的数据ID',
],
];
\ No newline at end of file
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