Commit cd3d8c10 authored by clone's avatar clone

重复提交控制

parent 2f51ab30
...@@ -6,6 +6,8 @@ use app\api_broker\extend\Basic; ...@@ -6,6 +6,8 @@ use app\api_broker\extend\Basic;
use app\api_broker\service\HouseNumUpdateService; use app\api_broker\service\HouseNumUpdateService;
use app\api_broker\service\OrderLogService; use app\api_broker\service\OrderLogService;
use app\api_broker\service\PushMessageService; use app\api_broker\service\PushMessageService;
use app\api_broker\service\VerifyRepetitionService;
use app\extra\RedisExt;
use app\model\AAgents; use app\model\AAgents;
use app\model\OBargainModel; use app\model\OBargainModel;
use app\model\OMarchInModel; use app\model\OMarchInModel;
...@@ -25,6 +27,7 @@ class OrderLog extends Basic ...@@ -25,6 +27,7 @@ class OrderLog extends Basic
private $o_march_in_model; private $o_march_in_model;
private $o_refund_model; private $o_refund_model;
private $service_; private $service_;
private $verifyService_;
function __construct($request = null) function __construct($request = null)
{ {
...@@ -32,6 +35,7 @@ class OrderLog extends Basic ...@@ -32,6 +35,7 @@ class OrderLog extends Basic
$this->o_march_in_model = new OMarchInModel(); $this->o_march_in_model = new OMarchInModel();
$this->o_refund_model = new ORefundModel(); $this->o_refund_model = new ORefundModel();
$this->service_ = new OrderLogService(); $this->service_ = new OrderLogService();
$this->verifyService_ = new VerifyRepetitionService();
} }
...@@ -60,7 +64,10 @@ class OrderLog extends Basic ...@@ -60,7 +64,10 @@ class OrderLog extends Basic
);*/ );*/
// $params["reception_id"] = $this->agentName; // $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); $is_ok = $this->o_march_in_model->addMarchIn($params);
if ($is_ok > 0) { if ($is_ok > 0) {
$pushMarchIn = new PushMessageService(); $pushMarchIn = new PushMessageService();
...@@ -69,6 +76,8 @@ class OrderLog extends Basic ...@@ -69,6 +76,8 @@ class OrderLog extends Basic
} else { } else {
return $this->response("101", "request faild"); return $this->response("101", "request faild");
} }
} }
/** /**
...@@ -426,9 +435,9 @@ class OrderLog extends Basic ...@@ -426,9 +435,9 @@ class OrderLog extends Basic
{ {
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"bargain_id" => 469, "bargain_id" => 469,
);*/ );*/
if (!isset($params["bargain_id"])) { if (!isset($params["bargain_id"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
......
...@@ -30,12 +30,7 @@ class LookShopService ...@@ -30,12 +30,7 @@ class LookShopService
public function __construct() public function __construct()
{ {
try { $this->redis = RedisExt::getRedis();
$this->redis = RedisExt::getRedis();
} catch (RedisException $exception) {
$this->redis = false;
}
$this->nowTime = date("Y-m-d", time()); $this->nowTime = date("Y-m-d", time());
$this->gHousesToAgentsModel = new GHousesToAgents(); $this->gHousesToAgentsModel = new GHousesToAgents();
$this->agentsModel = new AAgents(); $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,8 +44,12 @@ class RedisExt ...@@ -44,8 +44,12 @@ class RedisExt
public static function getRedis() public static function getRedis()
{ {
if (!self::$_instance) { try {
new self; if (!self::$_instance) {
new self;
}
} catch (RedisException $exception) {
return false;
} }
return self::$_instance; 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