feat(openapi): 实现秒级订单限制功能
- 新增 Redis 记录用户订单数功能- 按分钟限制用户下单数量 - 优化订单限制判断逻辑 - 修复了一些代码格式问题
This commit is contained in:
parent
7fff2e8043
commit
02659fcf98
@ -20,7 +20,6 @@ class Yuchu extends Core
|
||||
|
||||
|
||||
$this->api='api/order/SubmitOrder';
|
||||
# 判断运营商的方法
|
||||
|
||||
return $this->submit($param, $check);
|
||||
}
|
||||
@ -173,6 +172,7 @@ class Yuchu extends Core
|
||||
$request = $param['detail']; //上面替换剩下的
|
||||
#结束初步
|
||||
|
||||
|
||||
$request['AgentId']=$this->mid;
|
||||
|
||||
$request['CallbackUrl']=$this->getNotify($param['order'], 1); //回调方法默认不用改
|
||||
|
@ -158,15 +158,12 @@ class Coretb extends Controller
|
||||
|
||||
Log::write('openapi', 'taobao_request', $this->input);#写入到日志里
|
||||
|
||||
|
||||
#
|
||||
$this->agentId = $this->input['app_key'];
|
||||
|
||||
if (!$this->agentId) {
|
||||
$this->noTB('9999');
|
||||
}
|
||||
|
||||
|
||||
$inputData = $this->input ;
|
||||
$this->proid = $this->input['cardId'];
|
||||
|
||||
@ -176,9 +173,6 @@ class Coretb extends Controller
|
||||
$OrderSnapArray = json_decode($OrderSnapJson[1], true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->proid) {
|
||||
|
||||
if($this->proid == 111){
|
||||
@ -228,14 +222,14 @@ class Coretb extends Controller
|
||||
if($this->input['By_OpenUid'] != 'error'){
|
||||
$check_black = $this->check_black($this->input['By_OpenUid']);
|
||||
if($check_black != 'ok'){
|
||||
$tempnum=2;
|
||||
while($tempnum>0){
|
||||
$tempNum=2;
|
||||
while($tempNum>0){
|
||||
$msg = $this->tradeUpdate("该订单买家已经被拉入黑名单 ,停止发货--REAPI 系统自动化",5);
|
||||
|
||||
if($msg=='error'&&$tempnum>0){
|
||||
$tempnum--;
|
||||
if($msg=='error'){
|
||||
$tempNum--;
|
||||
}else{
|
||||
$tempnum=0;
|
||||
$tempNum=0;
|
||||
}
|
||||
}
|
||||
$this->noTB('0503', 'submit' ,$this->input['order']);
|
||||
@ -257,8 +251,6 @@ class Coretb extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->input['account'] = $this->input['customer']??'更正账号';
|
||||
if(!$this->input['account'] || $this->input['account'] == '' || $this->input['account'] == '0' || $this->input['account'] == 0){
|
||||
$this->input['account'] = '更正账号';
|
||||
@ -293,7 +285,7 @@ class Coretb extends Controller
|
||||
$propertiesArray1 = explode("^",$this->input['properties']) ;
|
||||
$propertiesArray = array();
|
||||
foreach($propertiesArray1 as $key=>$value){
|
||||
$temp=explode(":",$propertiesArray1[$key]);
|
||||
$temp=explode(":", $value);
|
||||
if(!$temp)continue;
|
||||
$propertiesArray[$temp[0]]=$temp[1];
|
||||
}
|
||||
@ -350,28 +342,67 @@ class Coretb extends Controller
|
||||
#检测是否为限购
|
||||
|
||||
public function check_limitbuy($By_OpenUid,$is_coop = false){
|
||||
#查询 param 中json数据 By_OpenUid 出现次数counO create_at data(Y-
|
||||
$count = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$By_OpenUid."%")->count();
|
||||
|
||||
|
||||
$other_param = $this->merchant['other_param'];
|
||||
if(!$other_param){
|
||||
return ;
|
||||
}
|
||||
$array = json_decode($other_param,true);
|
||||
|
||||
if(is_array($array)){
|
||||
if(isset($array['limitbuy_min_num'])){
|
||||
# 使用redis记录,并按分钟限制订单
|
||||
$min = $array['limitbuy_min_num'][0]??0; #每隔几分钟
|
||||
$num = $array['limitbuy_min_num'][1]??0; #限制规则
|
||||
if($min && $num){
|
||||
$redis = RedisService::getInstance();
|
||||
$redis_key = $this->merchant['id'].'_['.$By_OpenUid.']_LimitM';
|
||||
$countS = $redis->get($redis_key);
|
||||
|
||||
if(!$countS){
|
||||
$redis->set($redis_key,1,$min*60);
|
||||
}else{
|
||||
# 检测是否超过限制
|
||||
$new_num = $countS + 1;
|
||||
if($new_num >=$num){
|
||||
#超出,需要退款
|
||||
$tempNum=2;
|
||||
while($tempNum>0){
|
||||
$msg = $this->tradeUpdate("该订单买家在{$min} 分钟内采购了 {$countS} 笔,超过限制 规则每{$min}分钟限制 {$num} 笔,停止发货--REAPI 系统自动化",5);
|
||||
if($msg=='error'){
|
||||
$tempNum--;
|
||||
}else{
|
||||
$tempNum=0;
|
||||
}
|
||||
}
|
||||
if($is_coop){
|
||||
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
|
||||
}
|
||||
$this->noTB('0503', 'submit' ,$this->input['order']);
|
||||
}else{
|
||||
#未触发,设置redis,继续发货
|
||||
$redis->set($redis_key,$new_num,$min*60);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#查询 param 中json数据 By_OpenUid 出现次数counO create_at data(Y-
|
||||
$count = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$By_OpenUid."%")->count();
|
||||
if(isset($array['limitbuy_num'])){
|
||||
|
||||
|
||||
if($count>=$array['limitbuy_num']){
|
||||
|
||||
$tempnum=2;
|
||||
while($tempnum>0){
|
||||
$tempNum=2;
|
||||
while($tempNum>0){
|
||||
$msg = $this->tradeUpdate("该订单买家今日采购了 {$count} 笔,超过限制 {$array['limitbuy_num']} ,停止发货--REAPI 系统自动化",5);
|
||||
|
||||
if($msg=='error'&&$tempnum>0){
|
||||
$tempnum--;
|
||||
if($msg=='error'){
|
||||
$tempNum--;
|
||||
}else{
|
||||
$tempnum=0;
|
||||
$tempNum=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,14 +425,14 @@ class Coretb extends Controller
|
||||
|
||||
if($cash>=$array['limitbuy_amount']){
|
||||
|
||||
$tempnum=2;
|
||||
while($tempnum>0){
|
||||
$tempNum=2;
|
||||
while($tempNum>0){
|
||||
$msg = $this->tradeUpdate("该订单因为同IP累计金额为{$cash},超过限制{$array['limitbuy_amount']},停止发货--REAPI 系统自动化",5);
|
||||
|
||||
if($msg=='error'&&$tempnum>0){
|
||||
$tempnum--;
|
||||
if($msg=='error'){
|
||||
$tempNum--;
|
||||
}else{
|
||||
$tempnum=0;
|
||||
$tempNum=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,9 +444,9 @@ class Coretb extends Controller
|
||||
$this->noTB('0503', 'submit' ,$this->input['order']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return 'ok';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user