Authored by chenjian

只针对入驻卖家变价加锁

... ... @@ -437,8 +437,9 @@ public class ShoppingServiceImpl implements IShoppingService {
SellerOrderGoods psog = checkSkupSellOrNot(uid, shoppingRequest.getSkup());
GoodsPrepareData goodsPrepareData = checkSkupExtraWithlock(uid, psog, true);
//checkSkupIsChangePrice(uid, skup); //这个检查无效,改为下面的redis锁
checkSkupIsChangePrice(uid, skup); //这个变价检查针对个人卖家
//加锁,针对入驻卖家,变价同时买家下单,并发导致的卖家价格跟买家价格不一致(入驻卖家可利用此点套利)
RedisLock skupPriceLock = redisLockFactory.newLock(CacheKeyBuilder.skupPriceLockKey(skup), ExpiredTime.SKUP_PRICE_LOCK_SECONDS, TimeUnit.SECONDS);
boolean isSkupPriceLocked = skupPriceLock.tryLock();
if(!isSkupPriceLocked) {
... ... @@ -446,7 +447,6 @@ public class ShoppingServiceImpl implements IShoppingService {
throw new UfoServiceException(400, "卖家正在调整商品价格,请稍后下单");
}
//活动价格
ActivityPrice activityPrice = checkAndGetActivityPrice(shoppingRequest, psog);
... ...
... ... @@ -5,8 +5,6 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SingleGoodsChangePriceReq;
import com.yohoufo.common.concurrent.lock.RedisLock;
import com.yohoufo.common.concurrent.lock.RedisLockFactory;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
... ... @@ -14,8 +12,6 @@ import com.yohoufo.order.model.dto.LifeCycleSellerGoods;
import com.yohoufo.order.model.dto.SellerTaskDTO;
import com.yohoufo.order.model.dto.SellerTaskResult;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.ExpiredTime;
import com.yohoufo.order.service.handler.SellerDecrPriceTaskHandler;
import com.yohoufo.order.service.handler.SellerIncrPriceTaskHandler;
import com.yohoufo.order.service.impl.SellerOrderService;
... ... @@ -25,8 +21,6 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* Created by chao.chen on 2019/4/12.
*/
... ... @@ -52,10 +46,6 @@ public class ChangePriceService {
@Autowired
private SellerDecrPriceTaskHandler sellerDecrPriceTaskHandler;
@Autowired
private RedisLockFactory redisLockFactory;
private LifeCycleSellerGoods getLifeCycleSellerGoods(int skup){
if (skup <=0){
throw new UfoServiceException(400, "skup错误");
... ... @@ -129,20 +119,7 @@ public class ChangePriceService {
// 支持入驻后上架的商品变价,通过钱包支付
resp = changePriceOfEntryGoods(req);
}else{
//现有逻辑只支持 非入驻时上架的现货和预售,不支持瑕疵or二手
RedisLock skupPriceLock = redisLockFactory.newLock(CacheKeyBuilder.skupPriceLockKey(req.getSkup()), ExpiredTime.SKUP_PRICE_LOCK_SECONDS, TimeUnit.SECONDS);
boolean isSkupPriceLocked = skupPriceLock.tryLock();
if(!isSkupPriceLocked) {
logger.warn("skup price locked failed before price change, skup: {}", req.getSkup());
throw new UfoServiceException(400, "买家正在下单,不可改价");
}
try {
resp = singleGoodsChangePriceService.changePrice(req);
} finally {
if(isSkupPriceLocked) {
skupPriceLock.unlock();
}
}
resp = singleGoodsChangePriceService.changePrice(req);
}
break;
}
... ...