Browse Source

Merge branch 'develop' of ssh://120.24.33.109:11022/hyzjshwo/lanzu_api_hyperf into develop

master
weigang 5 years ago
parent
commit
d9f59818a2
  1. 10
      app/Controller/CouponController.php

10
app/Controller/CouponController.php

@ -100,10 +100,17 @@ class CouponController extends BaseController
$test = $this->request->input("test", 0);
$ids = explode(',', $ids);
$cps = Coupon::whereIn('id', $ids)->get();
$now = time();
$success = [];
$fail = [];
Db::transaction(function () use ($ids,$receiveType,$userId,&$success,&$fail,$test) {
//读写锁,完全控制,性能底
$cps = Coupon::whereIn('id', $ids)->lockForUpdate()->get();
//写锁,可能在高并发下,读取到脏数据,写入可能有超发情况
//$cps = Coupon::whereIn('id', $ids)->sharedLock()->get();
foreach ($cps as $key => $cp) {
$crt = CouponUserRecType::where(
[
@ -140,6 +147,7 @@ class CouponController extends BaseController
}
}
});
return $this->success([
'success' => $success,

Loading…
Cancel
Save