Browse Source

批量自增or插入

master
parent
commit
c715d1e81f
  1. 14
      app/Service/CouponRebateService.php

14
app/Service/CouponRebateService.php

@ -193,16 +193,6 @@ class CouponRebateService implements CouponRebateServiceInterface
// if($inventory['inventory'] <= 0){ // if($inventory['inventory'] <= 0){
// return '库存不足'; // return '库存不足';
// } // }
//判断用户是否已有该类型优惠券
$exist_coupon = Db::table('ims_system_coupon_user_receive')
->where([
['system_coupon_user_id', '=', $coupon->system_coupon_id],
['user_id', '=', $coupon->send_user_id],
['receive_type', '=', 5],
['status', '=', 0],
])
->select('id')
->first();
//return $exist_coupon; //return $exist_coupon;
//开启事务 //开启事务
try { try {
@ -211,7 +201,7 @@ class CouponRebateService implements CouponRebateServiceInterface
* 否则新增一条返券记录 * 否则新增一条返券记录
*/ */
$nowTime = time(); $nowTime = time();
$res = Db::table('ims_system_coupon_user_receive')->updateOrIncrement(
$res = Db::table('ims_system_coupon_user_receive')->moreIncrementOrInsert(
[ [
'system_coupon_user_id' => $coupon->system_coupon_id, 'system_coupon_user_id' => $coupon->system_coupon_id,
'user_id' => $coupon->send_user_id, 'user_id' => $coupon->send_user_id,
@ -254,6 +244,6 @@ class CouponRebateService implements CouponRebateServiceInterface
} }
return $exist_coupon->id;
return '返券成功';
} }
} }
Loading…
Cancel
Save