Commit 5bff1ec4 authored by zhoujun's avatar zhoujun

预警

parent a17c5cb9
Pipeline #2096 passed with stage
in 0 seconds
<?php
/**
* curl方法
* @param $object
* @return array
*/
if(!function_exists('postCurlJson')){
function postCurlJson($url, $data,$headers = [], $timeout = 30){
try {
$requestHeader[] = "API-RemoteIP: ";
$requestHeader[] = "Content-type: application/json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER,$requestHeader);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$timeout = intval ( $timeout ) ? intval ( $timeout ) : 30;
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HEADER, 0);
$result = curl_exec($curl);
curl_close($curl);
return $result;
} catch (exception $e) {
throw new Exception($e->getMessage());
}
}
}
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Util\Log;
use App\Services\Script\IScriptService;
class ClearLogData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ClearLogData';
/**
* The console command description.
*
* @var string
*/
protected $description = '定时清理历史数据';
/**
* @var ActivityOrder
*/
private $scriptService;
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct(IScriptService $scriptService)
{
parent::__construct();
$this->scriptService = $scriptService;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$this->scriptService->getClearLogData();
$this->line('结束');
}
}
\ No newline at end of file
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Util\Log;
use App\Services\Script\IScriptService;
class PolymerizeWithdrawal extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'PolymerizeWithdrawal';
/**
* The console command description.
*
* @var string
*/
protected $description = '聚合玩家提现数据';
/**
* @var ActivityOrder
*/
private $scriptService;
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct(IScriptService $scriptService)
{
parent::__construct();
$this->scriptService = $scriptService;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$this->scriptService->getPolymerizeWithdrawal();
$this->line('结束');
}
}
\ No newline at end of file
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Util\Log;
use App\Services\Script\IScriptService;
class SendDDMsg extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'SendDDMsg';
/**
* The console command description.
*
* @var string
*/
protected $description = '发送钉钉消息';
/**
* @var ActivityOrder
*/
private $scriptService;
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct(IScriptService $scriptService)
{
parent::__construct();
$this->scriptService = $scriptService;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$this->scriptService->getSendDDMsg();
$this->line('结束');
}
}
\ No newline at end of file
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Util\Log;
use App\Services\Script\IScriptService;
class SingleDayWithdrawal extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'SingleDayWithdrawal';
/**
* The console command description.
*
* @var string
*/
protected $description = '单日提现预警';
/**
* @var ActivityOrder
*/
private $scriptService;
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct(IScriptService $scriptService)
{
parent::__construct();
$this->scriptService = $scriptService;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$this->scriptService->getSingleDayWithdrawal();
$this->line('结束');
}
}
\ No newline at end of file
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Util\Log;
use App\Services\Script\IScriptService;
class SingleUserDayWithdrawal extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'SingleUserDayWithdrawal';
/**
* The console command description.
*
* @var string
*/
protected $description = '单日单用户提现预警';
/**
* @var ActivityOrder
*/
private $scriptService;
/**
* Create a new command instance.
* @param ProductOrder $productOrder
* @param ScoreDetail $scoreDetail
*/
public function __construct(IScriptService $scriptService)
{
parent::__construct();
$this->scriptService = $scriptService;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
$this->line('开始');
$this->scriptService->getSingleUserDayWithdrawal();
$this->line('结束');
}
}
\ No newline at end of file
......@@ -12,7 +12,13 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
'App\Console\Commands\SingleWithdrawal',
'App\Console\Commands\ClearLogData',
'App\Console\Commands\SingleWithdrawal',
'App\Console\Commands\PolymerizeWithdrawal',
'App\Console\Commands\SingleDayWithdrawal',
'App\Console\Commands\SingleUserDayWithdrawal',
'App\Console\Commands\SendDDMsg',
];
/**
......@@ -23,7 +29,14 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('SingleWithdrawal')->everyMinute()->withoutOverlapping();//每分钟跑一次
$schedule->command('ClearLogData')->dailyAt('3:00')->withoutOverlapping();//每天凌晨3:00点钟跑一次
$schedule->command('SingleWithdrawal')->everyFiveMinutes()->withoutOverlapping();//每5分钟跑一次
$schedule->command('PolymerizeWithdrawal')->everyFiveMinutes()->withoutOverlapping();//每5分钟跑一次
$schedule->command('SingleDayWithdrawal')->everyFiveMinutes()->withoutOverlapping();//每5分钟跑一次
$schedule->command('SingleUserDayWithdrawal')->everyFiveMinutes()->withoutOverlapping();//每5分钟跑一次
$schedule->command('SendDDMsg')->everyMinute()->withoutOverlapping();//每分钟跑一次
}
/**
......
......@@ -2,11 +2,9 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
class UserCashModel extends BaseModel
{
use SoftDeletes;
protected $connection = 'mysql';
protected $table = 'club_user_cash';
}
\ No newline at end of file
......@@ -2,11 +2,9 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
class WarnWaitModel extends BaseModel
{
use SoftDeletes;
protected $connection = 'mysql';
protected $table = 'club_warn_wait';
}
\ No newline at end of file
......@@ -4,4 +4,14 @@ namespace App\Services\Script;
interface IScriptService
{
public function getSingleWithdrawal();//单次最高提现预警
public function getPolymerizeWithdrawal();//聚合玩家提现数据
public function getClearLogData();//清理历史数据
public function getSingleDayWithdrawal();//单日最高提现预警
public function getSingleUserDayWithdrawal();//单日单用户最高提现预警
public function getSendDDMsg();//发送钉钉消息
}
<?php
namespace App\Services\Script;
use App\Models\DepartmentManagerModel;
use App\Services\Script\IScriptService;
use Carbon\Carbon;
use Exception;
......@@ -37,6 +38,7 @@ class ScriptService implements IScriptService
$lastId = self::getLastDataId(2);
$warnPeople = self::getWarnPeople();
if(empty($warnPeople)) return true;
$logs = SyceeWithdrawModel::where('sycee_withdraw.serial','>',$lastId)->where('sycee_withdraw.cash','>',$oneMin)->join('account','sycee_withdraw.user_id','account.user_id')->orderBy('sycee_withdraw.serial','ASC')->select('account.user_id','account.platform','account.platform_id','account.channel','sycee_withdraw.serial','sycee_withdraw.cash','sycee_withdraw.withdraw_time')->limit(100)->get();
$array = [];
......@@ -68,10 +70,12 @@ class ScriptService implements IScriptService
try{
if(!empty($array)) WarnWaitModel::insert($array);
if($maxId > 0) self::getUpdateLastId(2,$maxId);
unset($array,$tem,$config,$warnPeople,$logs,$log,$tem);
DB::commit();
return true;
} catch (\Exception $e){
DB::rollback();
unset($array,$tem,$config,$warnPeople,$logs,$log,$tem);
return false;
}
}
......@@ -144,10 +148,12 @@ class ScriptService implements IScriptService
* @date 2021/08/02
* @author live
*/
public static function getWarnConfig($type)
public static function getWarnConfig($type,$yf = [])
{
$array = ['oneMin'=>0,'dayMin'=>0,'userMin'=>0];
$configs = WarnConfigModel::where('status',1)->select('id','platform','channel','one_withdrawal','day_withdrawal','people_day_withdrawal')->get();
$configs = WarnConfigModel::where('status',1);
if(!empty($yf)) $configs->whereNotIn('id',$yf);
$configs = $configs->select('id','platform','channel','one_withdrawal','day_withdrawal','people_day_withdrawal')->get();
if(!$configs->count()) return [];
foreach($configs as $con){
......@@ -182,4 +188,201 @@ class ScriptService implements IScriptService
unset($configs,$con,$tem);
return $array;
}
/**
* 聚合玩家提现数据
* @return array
* @date 2021/08/02
* @author live
*/
public function getPolymerizeWithdrawal(){
$lastId = self::getLastDataId(1);
$logs = SyceeWithdrawModel::where('sycee_withdraw.serial','>',$lastId)->join('account','sycee_withdraw.user_id','account.user_id')->orderBy('sycee_withdraw.serial','ASC')->select('account.user_id','account.platform','account.platform_id','account.channel','sycee_withdraw.serial','sycee_withdraw.cash','sycee_withdraw.withdraw_time')->limit(300)->get();
$array = [];
$maxId = 0;
foreach($logs as $log){
$maxId = $log->serial;
$ymd = date('Ymd',strtotime($log->withdraw_time));
$key = $log->platform_id.'-'.$ymd;
if(isset($array[$key])){
$array[$key]['cash'] = $array[$key]['cash'] + $log->cash;
}else{
$tem['ymd'] = $ymd;
$tem['platform'] = $log->platform;
$tem['channel'] = $log->channel;
$tem['user_id'] = $log->platform_id;
$tem['open_id'] = $log->user_id;
$tem['cash'] = $log->cash;
$tem['created_at'] = $this->time;
$tem['updated_at'] = $this->time;
$array[$key] = $tem;
}
}
DB::beginTransaction();
try{
if(!empty($array)){
foreach($array as $key=>$arr){
$verity = UserCashModel::where('ymd',$arr['ymd'])->where('user_id',$arr['user_id'])->select('id','cash')->first();
if($verity){
$verity->cash = $verity->cash + $arr['cash'];
$verity->updated_at = $this->time;
$verity->save();
}else{
unset($array[$key]);
}
}
if(!empty($array)) UserCashModel::insert($array);
}
if($maxId > 0) self::getUpdateLastId(1,$maxId);
DB::commit();
unset($logs,$log,$tem,$array);
return true;
} catch (\Exception $e){
DB::rollback();
unset($logs,$log,$tem,$array);
return false;
}
}
/**
* 清理历史数据
* @return array
* @date 2021/08/03
* @author live
*/
public function getClearLogData()
{
$day = date('Ymd',strtotime(date('Y-m-d')) - 432000);
WarnWaitModel::where('ymd','<',$day)->delete();
UserCashModel::where('ymd','<',$day)->delete();
return true;
}
/**
* 单日最高体现预警
* @return array
* @date 2021/08/03
* @author live
*/
public function getSingleDayWithdrawal()
{
$ymd = date('Ymd');
$yfConfig = WarnWaitModel::where('ymd',$ymd)->where('type',2)->groupBy('config_id')->pluck('config_id');
$config = self::getWarnConfig(2,$yfConfig->toArray());
$dayMin = $config['dayMin'] ?? 0;
if(empty($config) || $dayMin == 0) return true;
$warnPeople = self::getWarnPeople();
if(empty($warnPeople)) return true;
$cash = UserCashModel::where('ymd',$ymd)->groupBy('platform','channel')->select('platform','channel',DB::raw('sum(cash) as cash'))->get();
$array = [];
foreach($cash as $log){
$key = $log->platform.'-'.$log->channel;
$warnConfig = $config[$key] ?? [];
if(empty($warnConfig)) continue;
$people = $warnPeople[$key] ?? [];
if(empty($people)) continue;
if($log->cash < $dayMin) continue;
$tem['ymd'] = date('Ymd',strtotime($this->time));
$tem['config_id'] = $warnConfig['id'];
$tem['type'] = 2;
$tem['cash'] = $log->cash;
$tem['warn_value'] = $warnConfig['day'];
$tem['people_id'] = implode('#',$people['id']);
$tem['people_phone'] = implode('#',$people['phone']);
$tem['people_name'] = implode('#',$people['name']);
$tem['user_id'] = 0;
$tem['open_id'] = '';
$tem['status'] = 0;
$tem['created_at'] = $this->time;
$tem['updated_at'] = $this->time;
$array[] = $tem;
}
if(!empty($array)){
foreach($array as $key=>$arr){
$verity = WarnWaitModel::where('ymd',$arr['ymd'])->where('config_id',$arr['config_id'])->where('type',2)->select('id')->first();
if($verity) unset($array[$key]);
}
if(!empty($array)) WarnWaitModel::insert($array);
}
unset($logs,$log,$tem,$array);
return true;
}
/**
* 单日单用户最高体现预警
* @return array
* @date 2021/08/03
* @author live
*/
public function getSingleUserDayWithdrawal()
{
$ymd = date('Ymd');
$config = self::getWarnConfig(3);
$userMin = $config['userMin'] ?? 0;
if(empty($config) || $userMin == 0) return true;
$warnPeople = self::getWarnPeople();
if(empty($warnPeople)) return true;
$cash = UserCashModel::where('ymd',$ymd)->select('platform','channel','user_id','open_id','cash')->get();
$array = [];
foreach($cash as $log){
$key = $log->platform.'-'.$log->channel;
$warnConfig = $config[$key] ?? [];
if(empty($warnConfig)) continue;
$people = $warnPeople[$key] ?? [];
if(empty($people)) continue;
if($log->cash < $userMin) continue;
$tem['ymd'] = date('Ymd',strtotime($this->time));
$tem['config_id'] = $warnConfig['id'];
$tem['type'] = 3;
$tem['cash'] = $log->cash;
$tem['warn_value'] = $warnConfig['user'];
$tem['people_id'] = implode('#',$people['id']);
$tem['people_phone'] = implode('#',$people['phone']);
$tem['people_name'] = implode('#',$people['name']);
$tem['user_id'] = $log->user_id;
$tem['open_id'] = $log->open_id;
$tem['status'] = 0;
$tem['created_at'] = $this->time;
$tem['updated_at'] = $this->time;
$array[] = $tem;
}
if(!empty($array)){
foreach($array as $key=>$arr){
$verity = WarnWaitModel::where('ymd',$arr['ymd'])->where('user_id',$arr['user_id'])->where('type',3)->select('id')->first();
if($verity) unset($array[$key]);
}
if(!empty($array)) WarnWaitModel::insert($array);
}
unset($logs,$log,$tem,$array);
return true;
}
/**
* 发送钉钉消息
* @return array
* @date 2021/08/03
* @author live
*/
public function getSendDDMsg()
{
$sends = WarnWaitModel::where('status',0)->limit(100)->get();
foreach($sends as $send){
$message = '';
$mobiles = str_replace('#',',',$send->people_phone);
if($send->type == 1) $message = '单日单次提现:日期'.Carbon::parse($send->created_at)->format('Y-m-d H:i:s').',提现金额:'.sprintf('%.2f',$send->cash / 100);
if($send->type == 2) $message = '单日累计提现:日期'.Carbon::parse($send->created_at)->format('Y-m-d H:i:s').',提现金额:'.sprintf('%.2f',$send->cash / 100);
if($send->type == 3) $message = '单日单用户提现:日期'.Carbon::parse($send->created_at)->format('Y-m-d H:i:s').',提现金额:'.sprintf('%.2f',$send->cash / 100);
$submitData = ['mobile_list'=>$mobiles,'message'=>$message,'api_token'=>config(env('ENVIRONMENT') . '.DINGDING_TOKEN')];
postCurlJson(config(env('ENVIRONMENT') . '.DINGDING_URL'), $submitData, []);
$send->status = 1;
$send->save();
}
}
}
\ No newline at end of file
......@@ -38,6 +38,9 @@
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Common/Common.php"
]
},
"autoload-dev": {
......
......@@ -13,4 +13,7 @@ return [
'CURRENCY' => [
'1' => '元宝'
],
'DINGDING_URL' => 'http://api.srccwl.com/dingding/send_message',
'DINGDING_TOKEN' => 'qPf99DyrCgdSSrJFbhwYHOPEv66HE02FAJy2x3KTx65BfLHbxNlue1Nbbmu5',
];
\ No newline at end of file
......@@ -13,4 +13,7 @@ return [
'CURRENCY' => [
'1' => '元宝'
],
'DINGDING_URL' => 'http://api.srccwl.com/dingding/send_message',
'DINGDING_TOKEN' => 'qPf99DyrCgdSSrJFbhwYHOPEv66HE02FAJy2x3KTx65BfLHbxNlue1Nbbmu5',
];
\ 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