Commit cd3d8c10 authored by clone's avatar clone

重复提交控制

parent 2f51ab30
......@@ -6,6 +6,8 @@ use app\api_broker\extend\Basic;
use app\api_broker\service\HouseNumUpdateService;
use app\api_broker\service\OrderLogService;
use app\api_broker\service\PushMessageService;
use app\api_broker\service\VerifyRepetitionService;
use app\extra\RedisExt;
use app\model\AAgents;
use app\model\OBargainModel;
use app\model\OMarchInModel;
......@@ -25,6 +27,7 @@ class OrderLog extends Basic
private $o_march_in_model;
private $o_refund_model;
private $service_;
private $verifyService_;
function __construct($request = null)
{
......@@ -32,6 +35,7 @@ class OrderLog extends Basic
$this->o_march_in_model = new OMarchInModel();
$this->o_refund_model = new ORefundModel();
$this->service_ = new OrderLogService();
$this->verifyService_ = new VerifyRepetitionService();
}
......@@ -60,7 +64,10 @@ class OrderLog extends Basic
);*/
// $params["reception_id"] = $this->agentName;
$is_execute = $this->verifyService_->verifyStart(1, $params["reception_id"], $params["order_id"]);
if (!$is_execute) {
return $this->response("101", "请不要重复提交");
}
$is_ok = $this->o_march_in_model->addMarchIn($params);
if ($is_ok > 0) {
$pushMarchIn = new PushMessageService();
......@@ -69,6 +76,8 @@ class OrderLog extends Basic
} else {
return $this->response("101", "request faild");
}
}
/**
......
......@@ -30,12 +30,7 @@ class LookShopService
public function __construct()
{
try {
$this->redis = RedisExt::getRedis();
} catch (RedisException $exception) {
$this->redis = false;
}
$this->nowTime = date("Y-m-d", time());
$this->gHousesToAgentsModel = new GHousesToAgents();
$this->agentsModel = new AAgents();
......
<?php
namespace app\api_broker\service;
use app\extra\RedisExt;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/6/6
* Time : 10:28
* Intro:
*/
class VerifyRepetitionService {
private $redis_;
const MARCH_IN_KEY = "_march_in_";
const TIME_OUT = 60; // 超时时间1分钟
public function __construct()
{
$this->redis_ = RedisExt::getRedis();
}
public function verifyStart(int $type,int $agent_id,int $order_id) : bool {
if(!$this->redis_){
return true;
}
$key = "";
switch ($type){
case 1: //进场
$key = self::MARCH_IN_KEY;
break;
case 2:
break;
case 3:
break;
default:
}
if($this->redis_->get($agent_id.$key.$order_id)){
return false;
}else{
$this->redis_->set($agent_id.$key.$order_id,1,self::TIME_OUT);
return true;
}
}
}
\ No newline at end of file
......@@ -44,9 +44,13 @@ class RedisExt
public static function getRedis()
{
try {
if (!self::$_instance) {
new self;
}
} catch (RedisException $exception) {
return false;
}
return self::$_instance;
}
......
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