|
|
|
@ -19,7 +19,7 @@ use Yansongda\Pay\Exceptions\GatewayException; |
|
|
|
|
use app\admin\model\transaction\Record; |
|
|
|
|
use think\Log; |
|
|
|
|
use addons\shopro\traits\CouponSend; |
|
|
|
|
|
|
|
|
|
use think\Cache; |
|
|
|
|
/** |
|
|
|
|
* 首页接口 |
|
|
|
|
*/ |
|
|
|
@ -28,7 +28,7 @@ class Order extends Api |
|
|
|
|
use CouponSend; |
|
|
|
|
protected $noNeedLogin = ['callback','test']; |
|
|
|
|
protected $noNeedRight = ['*']; |
|
|
|
|
|
|
|
|
|
const CACHE_TIME = 5; |
|
|
|
|
/** |
|
|
|
|
* 首页 |
|
|
|
|
* |
|
|
|
@ -288,6 +288,14 @@ class Order extends Api |
|
|
|
|
if (time() > strtotime($warehouse['end'])) { |
|
|
|
|
$this->error("抢购时间已结束!"); |
|
|
|
|
} |
|
|
|
|
//使用redis锁,限制下单 |
|
|
|
|
$lock_key = $this->request->domain()."_createOrder_".$goods_id; |
|
|
|
|
$res = Cache::store('redis')->setnx($lock_key, 1); |
|
|
|
|
|
|
|
|
|
if (!$res) { |
|
|
|
|
$this->error("您的手速太慢了,商品已被抢!"); |
|
|
|
|
} |
|
|
|
|
Cache::store('redis')->expire($lock_key, self::CACHE_TIME); |
|
|
|
|
//exit(); |
|
|
|
|
$order_amount = $order['pay_amount']; |
|
|
|
|
$pay_amount = $order_amount; |
|
|
|
@ -338,6 +346,8 @@ class Order extends Api |
|
|
|
|
$obj = new UserService(); |
|
|
|
|
$obj->userCommission(0, $this->auth->getUserinfo(), $order_sn, $commission); |
|
|
|
|
|
|
|
|
|
Cache::store('redis')->rm($lock_key); |
|
|
|
|
|
|
|
|
|
$this->success("succ"); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|