Commit 3bbe8182 authored by zhoujun's avatar zhoujun

预警接口

parent 1ffa2d95
Pipeline #2068 passed with stage
in 0 seconds
......@@ -163,9 +163,15 @@ class WarnController extends BaseController
* @date 2021/07/31
* @author live
*/
public function getConfigList()
public function getConfigList(Request $request)
{
$postData = $request->all();
try {
$data = $this->warnService->getConfigList($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
......@@ -174,9 +180,26 @@ class WarnController extends BaseController
* @date 2021/07/31
* @author live
*/
public function getConfigEdit()
public function getConfigEdit(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'id' => 'required|numeric',
'platform' => 'required|numeric',
'channel' => 'required|numeric',
'type' => 'required|numeric',
'oneWithdrawal' => 'required|numeric',
'dayWithdrawal' => 'required|numeric',
'userDayWithdrawal' => 'required|numeric'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getConfigEdit($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
......@@ -185,9 +208,19 @@ class WarnController extends BaseController
* @date 2021/07/31
* @author live
*/
public function getConfigDel()
public function getConfigDel(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'id' => 'required|numeric'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getConfigDel($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
......
......@@ -122,7 +122,7 @@ class AccountService implements IAccountService
$tem['remark'] = $log->extra;
$array['data'][] = $tem;
}
unset($users,$user,$user);
unset($logs,$log,$account);
return $array;
}
}
\ No newline at end of file
......@@ -68,7 +68,7 @@ class UserService implements IUserService{
$tem['created_at'] = Carbon::parse($user->created_at)->format('Y-m-d H:i:s');
$array['data'][] = $tem;
}
unset($users,$user,$user);
unset($users,$user);
return $array;
}
......
......@@ -14,4 +14,10 @@ interface IWarnService
public function getPeopleSetStatus($postData);//设置预警人状态
public function getConfigAdd($postData);//预警配置添加
public function getConfigList($postData); //预警配置列表
public function getConfigEdit($postData); //预警配置编辑
public function getConfigDel($postData); //预警配置删除
}
\ No newline at end of file
......@@ -90,7 +90,7 @@ class WarnService implements IWarnService
$tem['createdAt'] = Carbon::parse($list->created_at)->format('Y-m-d H:i:s');
$array['data'][] = $tem;
}
unset($users, $user, $user);
unset($lists, $list);
return $array;
}
......@@ -162,14 +162,16 @@ class WarnService implements IWarnService
*/
public function getConfigAdd($postData)
{
if($postData['platform'] < 1 || $postData['channel'] < 1) throw new Exception(config('msg.common.1014'), 1014);
$verity = WarnPeopleModel::where('platform', $postData['platform'])->where('channel', $postData['channel'])->where('phone',$postData['phone'])->select('id')->first();
if($postData['platform'] < 1 || $postData['channel'] < 1 || $postData['type'] < 1) throw new Exception(config('msg.common.1014'), 1014);
$verity = WarnConfigModel::where('platform', $postData['platform'])->where('channel', $postData['channel'])->where('type',$postData['type'])->where('one_withdrawal',$postData['oneWithdrawal'])->where('day_withdrawal',$postData['dayWithdrawal'])->where('people_day_withdrawal',$postData['userDayWithdrawal'])->select('id')->first();
if (!$verity) {
$row = new WarnPeopleModel();
$row = new WarnConfigModel();
$row->platform = $postData['platform'] ?? 0;
$row->channel = $postData['channel'] ?? 0;
$row->name = $postData['remarkName'] ?? '';
$row->phone = $postData['phone'] ?? '';
$row->type = $postData['type'] ?? 0;
$row->one_withdrawal = $postData['oneWithdrawal'] * 100;
$row->day_withdrawal = $postData['dayWithdrawal'] * 100;
$row->people_day_withdrawal = $postData['userDayWithdrawal'] * 100;
$row->op_user = $postData['user'] ?? '';
$row->remark = $postData['remark'] ?? '';
if ($row->save()) return $row->id;
......@@ -178,4 +180,85 @@ class WarnService implements IWarnService
throw new Exception(config('msg.common.1005'), 1005);
}
/**
* 预警配置列表
* @return araay
* @date 2021/07/31
* @author live
*/
public function getConfigList($postData)
{
$status = $postData['status'] ?? 0;
$pagePerNum = $postData['pageSize'] ?? 20;
$currentPage = $postData['page'] ?? 1;
$lists = WarnConfigModel::when($status > 0, function ($query) use ($status) {
return $query->where('status',$status);
})->select('id', 'platform', 'channel', 'type', 'one_withdrawal','day_withdrawal','people_day_withdrawal','status','op_user', 'created_at')->orderBy('id', 'DESC')->paginate($pagePerNum, ['*'], 'currentPage', $currentPage);
$array['totalNum'] = $lists->total();
$array['totalPage'] = $lists->lastPage();
$platformArr = config(env('ENVIRONMENT') . '.PLATFORM');
$channelArr = config(env('ENVIRONMENT') . '.CHANNEL');
$typeArr = config(env('ENVIRONMENT') . '.CURRENCY');
foreach ($lists as $list) {
$tem['id'] = $list->id;
$tem['platform'] = $platformArr[$list->platform] ?? '';
$tem['channel'] = $channelArr[$list->channel] ?? '';
$tem['type'] = $typeArr[$list->type] ?? '';
$tem['oneWithdrawal'] = sprintf('%.2f',$list->one_withdrawal / 100);
$tem['dayWithdrawal'] = sprintf('%.2f',$list->day_withdrawal / 100);
$tem['userDayWithdrawal'] = sprintf('%.2f',$list->people_day_withdrawal / 100);
$tem['status'] = $list->status;
$statusName = '停用';
if($list->status == 1) $statusName = '正常';
$tem['statusName'] = $statusName;
$tem['optionUser'] = $list->op_user;
$tem['createdAt'] = Carbon::parse($list->created_at)->format('Y-m-d H:i:s');
$array['data'][] = $tem;
}
unset($lists, $list);
return $array;
}
/**
* 预警配置编辑
* @return araay
* @date 2021/07/31
* @author live
*/
public function getConfigEdit($postData)
{
if($postData['platform'] < 1 || $postData['channel'] < 1 || $postData['type'] < 1) throw new Exception(config('msg.common.1014'), 1014);
$verity = WarnConfigModel::where('id','!=',$postData['id'])->where('platform', $postData['platform'])->where('channel', $postData['channel'])->where('type',$postData['type'])->where('one_withdrawal',$postData['oneWithdrawal'])->where('day_withdrawal',$postData['dayWithdrawal'])->where('people_day_withdrawal',$postData['userDayWithdrawal'])->select('id')->first();
if (!$verity) {
$row = WarnConfigModel::find($postData['id']);
$row->platform = $postData['platform'] ?? 0;
$row->channel = $postData['channel'] ?? 0;
$row->type = $postData['type'] ?? 0;
$row->one_withdrawal = $postData['oneWithdrawal'] * 100;
$row->day_withdrawal = $postData['dayWithdrawal'] * 100;
$row->people_day_withdrawal = $postData['userDayWithdrawal'] * 100;
$row->op_user = $postData['user'] ?? '';
$row->remark = $postData['remark'] ?? '';
$row->updated_at = $this->time;
if ($row->save()) return $row->id;
throw new Exception(config('msg.common.1006'), 1006);
}
throw new Exception(config('msg.common.1005'), 1005);
}
/**
* 预警配置删除
* @return araay
* @date 2021/07/31
* @author live
*/
public function getConfigDel($postData)
{
$list = WarnConfigModel::where('id', $postData['id'])->first();
if (!$list) throw new Exception(config('msg.common.1002'), 1002);
if ($list->delete()) return true;
throw new Exception(config('msg.common.1003'), 1003);
}
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ class WhiteService implements IWhiteService
$tem['addTime'] = $list->add_time;
$array['data'][] = $tem;
}
unset($users, $user, $user);
unset($lists, $list);
return $array;
}
......
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