Commit 89614dfe authored by zhoujun's avatar zhoujun

货币查询

parent 275ee02a
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Throwable;
use Exception;
use Carbon\Carbon;
use Illuminate\Validation\Rule;
use App\Services\Warn\IWarnService;
class WarnController extends BaseController
{
private $time;
private $warnService;
public function __construct(IWarnService $warnService)
{
$this->time = Carbon::now()->format('Y-m-d H:i:s');
$this->warnService = $warnService;
}
/**
* 新增预警人
* @return array
* @date 2021/07/31
* @author live
*/
public function getPeopleAdd(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'platform' => 'required|numeric',
'channel' => 'required|numeric',
'remarkName' => 'required|string',
'phone' => 'required|string'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getPeopleAdd($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
* 预警人列表
* @return array
* @date 2021/07/31
* @author live
*/
public function getPeopleList(Request $request)
{
$postData = $request->all();
try {
$data = $this->warnService->getPeopleList($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
* 预警人编辑
* @return array
* @date 2021/07/31
* @author live
*/
public function getPeopleEdit(Request $request)
{
$postData = $request->all();
$validate = Validator::make($postData, [
'id' => 'required|numeric',
'platform' => 'required|numeric',
'channel' => 'required|numeric',
'remarkName' => 'required|string',
'phone' => 'required|string'
]);
if ($validate->fails()) return $this->getErrorMsg('1001', config('msg.common.1001'));
try {
$data = $this->warnService->getPeopleEdit($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
/**
* 删除预警人
* @return array
* @date 2021/07/31
* @author live
*/
public function getPeopleDel(Request $request)
{
$postData = $request->all();
try {
$data = $this->warnService->getPeopleDel($postData);
return $this->getSuccessMsg($data);
} catch (Exception $e) {
return $this->getErrorMsg($e->getCode(), $e->getMessage());
}
}
}
\ No newline at end of file
...@@ -19,6 +19,7 @@ class Kernel extends HttpKernel ...@@ -19,6 +19,7 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class, \App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\EnableCrossRequestMiddleware::class
]; ];
/** /**
......
<?php
namespace App\Http\Middleware;
use Closure;
class EnableCrossRequestMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->header('Access-Control-Allow-Origin','*');
$response->header('Access-Control-Allow-Headers','*');
$response->header('Access-Control-Expose-Headers', '*');
$response->header('Access-Control-Allow-Methods', '*');
$response->header('Access-Control-Allow-Credentials', 'true');
$response->header('Access-Control-Allow-Headers', 'Content-Type,token');
return $response;
}
}
<?php
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
class WarnPeopleModel extends BaseModel
{
use SoftDeletes;
protected $connection = 'mysql';
protected $table = 'club_warn_people';
}
...@@ -16,6 +16,7 @@ class AppServiceProvider extends ServiceProvider ...@@ -16,6 +16,7 @@ class AppServiceProvider extends ServiceProvider
$this->app->bind('App\Services\User\IUserService', 'App\Services\User\UserService'); $this->app->bind('App\Services\User\IUserService', 'App\Services\User\UserService');
$this->app->bind('App\Services\White\IWhiteService', 'App\Services\White\WhiteService'); $this->app->bind('App\Services\White\IWhiteService', 'App\Services\White\WhiteService');
$this->app->bind('App\Services\Account\IAccountService', 'App\Services\Account\AccountService'); $this->app->bind('App\Services\Account\IAccountService', 'App\Services\Account\AccountService');
$this->app->bind('App\Services\Warn\IWarnService', 'App\Services\Warn\WarnService');
} }
/** /**
......
<?php
namespace App\Services\Warn;
interface IWarnService
{
public function getPeopleAdd($postData); //预警人添加
public function getPeopleList($postData);//预警人列表
public function getPeopleEdit($postData);//预警人编辑
public function getPeopleDel($postData); //预警人删除
}
\ No newline at end of file
<?php
namespace App\Services\Warn;
use App\Services\Warn\IWarnService;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Models\WarnPeopleModel;
use Illuminate\Support\Facades\Cache;
class WarnService implements IWarnService
{
private $time;
public function __construct()
{
$this->time = Carbon::now()->format('Y-m-d H:i:s');
}
/**
* 新增预警人信息
* @return int
* @date 2021/07/31
* @author live
*/
public function getPeopleAdd($postData)
{
if(!preg_match("/^1[3456789]\d{9}$/", $postData['phone'])) throw new Exception(config('msg.common.1013'), 1013);
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 (!$verity) {
$row = new WarnPeopleModel();
$row->platform = $postData['platform'] ?? 0;
$row->channel = $postData['channel'] ?? 0;
$row->name = $postData['remarkName'] ?? '';
$row->phone = $postData['phone'] ?? '';
$row->op_user = $postData['user'] ?? '';
$row->remark = $postData['remark'] ?? '';
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 getPeopleList($postData)
{
$name = $postData['key'] ?? '';
$platform = $postData['platform'] ?? 0;
$start = $postData['startTime'] ?? '';
$end = $postData['endTime'] ?? '';
$pagePerNum = $postData['pageSize'] ?? 20;
$currentPage = $postData['page'] ?? 1;
$lists = WarnPeopleModel::when($name != '', function ($query) use ($name) {
return $query->where('name', 'like', $name . '%');
})->when($platform > 0, function ($query) use ($platform) {
return $query->where('platform',$platform);
})->when($start != '', function ($query) use ($start) {
$startTime = date('Y-m-d H:i:s',strtotime($start) - 1);
return $query->where('created_at', '>',$startTime);
})->when($end != '', function ($query) use ($end) {
$endTime = date('Y-m-d H:i:s',strtotime($end) + 1);
return $query->where('created_at', '<',$endTime);
})->select('id', 'platform', 'channel', 'name', 'phone','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');
foreach ($lists as $list) {
$tem['id'] = $list->id;
$tem['platform'] = $platformArr[$list->platform] ?? '';
$tem['channel'] = $channelArr[$list->channel] ?? '';
$tem['name'] = $list->name;
$tem['phone'] = $list->phone;
$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($users, $user, $user);
return $array;
}
/**
* 编辑预警人
* @return araay
* @date 2021/07/31
* @author live
*/
public function getPeopleEdit($postData)
{
if(!preg_match("/^1[3456789]\d{9}$/", $postData['phone'])) throw new Exception(config('msg.common.1013'), 1013);
if($postData['platform'] < 1 || $postData['channel'] < 1) throw new Exception(config('msg.common.1014'), 1014);
$verity = WarnPeopleModel::where('id','!=',$postData['id'])->where('platform', $postData['platform'])->where('channel', $postData['channel'])->where('phone',$postData['phone'])->select('id')->first();
if (!$verity) {
$row = WarnPeopleModel::find($postData['id']);
if(!$row) throw new Exception(config('msg.common.1002'), 1002);
$row->platform = $postData['platform'] ?? 0;
$row->channel = $postData['channel'] ?? 0;
$row->name = $postData['remarkName'] ?? '';
$row->phone = $postData['phone'] ?? '';
$row->op_user = $postData['user'] ?? '';
$row->remark = $postData['remark'] ?? '';
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 getPeopleDel($postData)
{
$list = WarnPeopleModel::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);
}
/**
* 设置预警人状态
* @return araay
* @date 2021/07/31
* @author live
*/
public function getPeopleSetStatus($postData)
{
$list = WarnPeopleModel::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->addTime = $this->time;
if ($list->save()) return true;
throw new Exception(config('msg.common.1003'), 1003);
}
}
\ No newline at end of file
...@@ -20,6 +20,8 @@ return [ ...@@ -20,6 +20,8 @@ return [
'1010' => '请带上过期的token', '1010' => '请带上过期的token',
'1011' => 'token过期请重新登录', '1011' => 'token过期请重新登录',
'1012' => '用户ID不存在', '1012' => '用户ID不存在',
'1013' => '请填写有效的预警手机号',
'1014' => '平台和渠道为必填项',
], ],
]; ];
\ No newline at end of file
...@@ -38,13 +38,20 @@ Route::group(['namespace' => 'Api','middleware' => ['user.login']], function () ...@@ -38,13 +38,20 @@ Route::group(['namespace' => 'Api','middleware' => ['user.login']], function ()
Route::post('/set/status','WhiteController@getSetStatus');//设置白名单状态 Route::post('/set/status','WhiteController@getSetStatus');//设置白名单状态
}); });
Route::group(['prefix' => 'warn'],function() {
Route::post('/people/add','WarnController@getPeopleAdd');//新增预警人
Route::post('/people/list','WarnController@getPeopleList');//预警人列表
Route::post('/people/edit','WarnController@getPeopleEdit');//编辑预警人
Route::post('/people/del','WarnController@getPeopleDel');//删除预警人
});
Route::group(['prefix' => 'account'],function() { Route::group(['prefix' => 'account'],function() {
Route::post('/platform/list','AccountController@getPlatformList');//平台列表 Route::post('/platform/list','AccountController@getPlatformList');//平台列表
Route::post('/channel/list','AccountController@getChannelList');//渠道列表 Route::post('/channel/list','AccountController@getChannelList');//渠道列表
Route::post('/currency/list','AccountController@getCurrencyList');//货币种类列表 Route::post('/currency/list','AccountController@getCurrencyList');//货币种类列表
Route::post('/log','AccountController@getAccountLog');//货币查询 Route::post('/log','AccountController@getAccountLog');//货币查询
}); });
}); });
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