Browse Source

退单接口整合 有失效优惠券时返回失效原因

master
Lemon 6 years ago
parent
commit
117e356d0a
  1. 6
      app/Model/CouponUserUse.php
  2. 43
      app/Service/CouponService.php
  3. 2
      app/Service/CouponServiceInterface.php
  4. 6
      app/Service/OrderService.php
  5. 2
      app/Service/PurchaseLimitService.php

6
app/Model/CouponUserUse.php

@ -13,5 +13,11 @@ class CouponUserUse extends Model
public $timestamps = false;
protected $fillable = [
'status',
'return_time',
'update_time'
];
protected $table = 'ims_system_coupon_user_use';
}

43
app/Service/CouponService.php

@ -160,18 +160,6 @@ class CouponService implements CouponServiceInterface
{
$available = [];
$notAvailable = [];
//如果存在特价商品 不给用券
$carIdsArr = explode(',',$carIds);
$shopCarExists = ShopCar::whereIn('id',$carIdsArr)
->where('money',0.01)
->exists();
if($shopCarExists){
return [
'available' => $available,
'not_available' => array_values($notAvailable)
];
}
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId));
if (empty($orderAmount) || empty($userId)) {
@ -218,12 +206,27 @@ class CouponService implements CouponServiceInterface
foreach ($data as $key => &$item) {
if (in_array($item->id, $couponIds)) {
$item->msg = '今日已使用';
$notAvailable[$item->id] = $item;
} else {
$available[] = $item;
}
}
//如果存在特价商品 不给用券
$carIdsArr = explode(',',$carIds);
$shopCarExists = ShopCar::whereIn('id',$carIdsArr)
->where('money',0.01)
->exists();
if($shopCarExists){
var_dump(1111);
foreach ($available as $k => $v) {
$v->msg = '特价商品不可使用';
$notAvailable[$v->id] = $v;
}
$available = [];
}
return [
'available' => $available,
'not_available' => array_values($notAvailable)
@ -334,7 +337,7 @@ class CouponService implements CouponServiceInterface
'coupon_'.date('Ymd').'_used_'.$order_main->user_id,
$coupon->system_coupon_id
);
return $res;
return $remRes;
}
/* 删除-优惠券今日使用的缓存
@ -359,19 +362,22 @@ class CouponService implements CouponServiceInterface
* 先查询是否正常使用优惠券
* 修改状态,退还领取记录库存,删除ssdb缓存
*/
public function orderRefundCoupon($global_order_id)
public function orderRefundCoupons($global_order_id)
{
$order_main = OrderMain::where('global_order_id',$global_order_id)
->select('id','user_id')
->first();
$time = time();
Db::beginTransaction();
try {
$couponUses = CouponUserUse::query()
->select('id','system_coupon_id','user_id','number','user_receive_id')
->where('global_order_id',$global_order_id)
->where('order_main_id',$order_main->id)
->where('status',CouponUserUse::COUPON_USE_STATE_USED)
->select();
if(!empty($couponUse)){
->get();
if(!empty($couponUses)){
foreach($couponUses as $use){
$use->status = CouponUserUse::COUPON_USE_STATE_USED;
$use->status = CouponUserUse::COUPON_USE_STATE_CANCEL;
$use->return_time = $time;
$use->update_time = $time;
$res = $use->save();
@ -397,6 +403,5 @@ class CouponService implements CouponServiceInterface
Db::rollBack();
return false;
}
return true;
}
}

2
app/Service/CouponServiceInterface.php

@ -29,5 +29,5 @@ interface CouponServiceInterface
public function refundOrderCoupons($global_order_id);
public function clearTodayCouponUsed($userId, $couponId);
public function orderRefundCoupon($global_order_id);
public function orderRefundCoupons($global_order_id);
}

6
app/Service/OrderService.php

@ -733,10 +733,10 @@ class OrderService implements OrderServiceInterface
OrderMain::where('global_order_id',$global_order_id)
->update(['state' => OrderMain::ORDER_STATE_CANCEL]);
//撤销redis 用券记录
$res = $this->couponService->refundOrderCoupons($global_order_id);
$redisRes = $this->couponService->orderRefundCoupons($global_order_id);
//撤销特价商品购买记录
$res = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id);
return $res;
$ssdbRes = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id);
return $redisRes && $ssdbRes;
}
/**
* @inheritDoc

2
app/Service/PurchaseLimitService.php

@ -71,8 +71,6 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface
foreach ($goods as $k2 => $v2) {
$ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']);
var_dump($v1['user_id']);
var_dump($v1['good_id']);
}
}
return true;

Loading…
Cancel
Save