Authored by wujiexiang

求购 -- 退款状态控制

... ... @@ -183,7 +183,10 @@ public class BuyerBidDepositPaymentService extends AbstractOrderPaymentService {
final static List<Integer> canRefundStatusList = Arrays.asList(
OrderStatus.BIDING.getCode(),
OrderStatus.HAS_PAYED.getCode()
OrderStatus.HAS_PAYED.getCode(),
OrderStatus.BUYER_CLOSE_BID.getCode(),
OrderStatus.SYSTEM_CLOSE_BID.getCode(),
OrderStatus.PLATFORM_CLOSE_BID.getCode()
);
@Override
... ...
... ... @@ -11,6 +11,8 @@ import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
/**
... ... @@ -26,6 +28,7 @@ public class BidSkupService {
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public int create(int uid, GoodsInfo goodsInfo) {
Assert.notNull(goodsInfo, "goodsInfo must not be null");
... ... @@ -48,6 +51,7 @@ public class BidSkupService {
*
* @param uid
*/
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public void bind(int uid, int skup, boolean finishPay) {
SellerOrderGoods condition = new SellerOrderGoods();
... ... @@ -69,6 +73,7 @@ public class BidSkupService {
* @param uid
* @param skup
*/
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public void unbind(int uid,int skup) {
SellerOrderGoods condition = new SellerOrderGoods();
... ...
... ... @@ -27,6 +27,8 @@ import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
... ... @@ -76,6 +78,7 @@ public class BuyerBidOrderSubmitService {
*
* @param orderBuilder
*/
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public BuyerOrderSubmitResult createOrder(OrderBuilder orderBuilder, BidOrderMetaBo bidOrderMetaBo) {
... ...
... ... @@ -21,6 +21,8 @@ import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
... ... @@ -95,6 +97,7 @@ public class SellerBidOrderBindService {
* @param submitSellerOrder
* @return
*/
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public void bindAndCreateOrder(SubmitSellerOrder submitSellerOrder) {
/**
... ... @@ -109,6 +112,7 @@ public class SellerBidOrderBindService {
}
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster = true, DataSource = "ufo_order")
public void unbind(int uid, long orderCode, int skup, SellerOrderStatus targetStatus) {
bidSkupService.unbind(uid, skup);
... ... @@ -207,10 +211,10 @@ public class SellerBidOrderBindService {
buyerOrder.setBidType(OrderConstant.BUYER_BID_TYPE);
boolean success = buyerOrderMapper.updateByOrderCode(buyerOrder) > 0;
if (!success) {
logger.warn("[{}] buyer order is bind with sellerUid:{} fail ", buyerOrderGoods.getOrderCode());
logger.warn("[{}] buyer order is bind with sellerUid:{} fail ", buyerOrderGoods.getOrderCode(), sellerUid);
throw new UfoServiceException(500, "操作失败");
}
logger.info("[{}] buyer order is bind with sellerUid:{} success ", buyerOrderGoods.getOrderCode());
logger.info("[{}] buyer order is bind with sellerUid:{} success ", buyerOrderGoods.getOrderCode(), sellerUid);
}
}
}
\ No newline at end of file
... ...
... ... @@ -5,6 +5,7 @@ import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.RequestedStatusChangeBuyerOrder;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.service.AbstractBuyerOrderStateChanger;
... ... @@ -68,8 +69,8 @@ public class BuyerOrderBidingCancelChanger extends AbstractBuyerOrderStateChange
.build();
logger.info("[{}] refund deposit,paymentRequest:{}", orderCode, paymentRequest);
paymentService.refund(paymentRequest);
logger.info("[{}] refund deposit success", buyerOrder.getOrderCode());
PayRefundBo payRefundBo = paymentService.refund(paymentRequest);
logger.info("[{}] refund deposit end,result:{}", buyerOrder.getOrderCode(), payRefundBo);
}
@Override
... ...
... ... @@ -17,6 +17,7 @@ import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.bo.ActivityBo;
import com.yohoufo.order.model.bo.BidOrderMetaBo;
import com.yohoufo.order.model.request.PaymentRequest;
... ... @@ -328,8 +329,8 @@ public class BuyerOrderChangeBusinessPostProcessor {
.build();
logger.info("[{}] refund deposit,paymentRequest:{}", orderCode, paymentRequest);
paymentService.refund(paymentRequest);
logger.info("[{}] refund deposit success", buyerOrder.getOrderCode());
PayRefundBo payRefundBo = paymentService.refund(paymentRequest);
logger.info("[{}] refund deposit end,result:{}", buyerOrder.getOrderCode(), payRefundBo);
}
... ...
package com.yohoufo.order.service.proxy;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.BidStoragePriceVo;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.Operator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class BidProductProxyService extends AbsProxyService {
... ... @@ -59,8 +64,7 @@ public class BidProductProxyService extends AbsProxyService {
default:
api = null;
}
ufoServiceCaller.call(api, skup);
return true;
return getResultFromApiResponse(ufoServiceCaller.call(api, skup), Boolean.class);
}
public boolean cancelSaleByUser(int skup) {
... ... @@ -69,16 +73,14 @@ public class BidProductProxyService extends AbsProxyService {
}
public boolean trySale(int productId, int skup) {
logger.info("trySale,productId:{},skup:{}", productId, skup);
ufoServiceCaller.call(SALE_API, productId, skup);
return true;
return getResultFromApiResponse(ufoServiceCaller.call(SALE_API, productId, skup), Boolean.class);
}
public boolean isCanceled(int skup) {
logger.info("isCanceled,skup:{}", skup);
return ufoServiceCaller.call(IS_CANCELED_API, skup);
return getResultFromApiResponse(ufoServiceCaller.call(IS_CANCELED_API, skup), Boolean.class);
}
/**
... ... @@ -88,14 +90,13 @@ public class BidProductProxyService extends AbsProxyService {
*/
public BidStoragePriceVo getSaleable(int skup) {
logger.info("getSaleable,skup:{}", skup);
return ufoServiceCaller.call(GET_SALEABLE_API, skup);
return getResultFromApiResponse(ufoServiceCaller.call(GET_SALEABLE_API, skup), BidStoragePriceVo.class);
}
public boolean resetSaleableFromUserCancel(int skup) {
logger.info("resetSaleableFromUserCancel,skup:{}", skup);
try {
ufoServiceCaller.call(RESET_SALEABLE_FROM_USERCANCEL_API, skup);
return true;
return getResultFromApiResponse(ufoServiceCaller.call(RESET_SALEABLE_FROM_USERCANCEL_API, skup), Boolean.class);
} catch (Exception ex) {
logger.warn("exception happened when reset saleable,skup:{}", skup);
return false;
... ... @@ -105,11 +106,28 @@ public class BidProductProxyService extends AbsProxyService {
public boolean resetSaleableFromBidFinished(int skup) {
logger.info("resetSaleableFromBidFinished,skup:{}", skup);
try {
ufoServiceCaller.call(RESET_SALEABLE_FROM_BIDFINISHED_API, skup);
return true;
return getResultFromApiResponse(ufoServiceCaller.call(RESET_SALEABLE_FROM_BIDFINISHED_API, skup), Boolean.class);
} catch (Exception ex) {
logger.warn("exception happened when reset saleable,skup:{}", skup);
return false;
}
}
public <T> T getResultFromApiResponse(ApiResponse resp, Class<T> clazz) {
if (resp == null) {
throw new UfoServiceException(500, "服务器访问异常");
}
if (resp.getCode() != 200) {
throw new UfoServiceException(resp.getCode(), resp.getMessage());
}
if (Objects.isNull(resp.getData())) {
return null;
}
if (resp.getData() instanceof JSONObject) {
return ((JSONObject) resp.getData()).toJavaObject(clazz);
} else {
return JSONObject.parseObject(JSONObject.toJSONString(resp.getData()), clazz);
}
}
}
... ...
package com.yohoufo.product.controller;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.BidStoragePriceVo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.product.service.impl.BidProductService;
... ... @@ -21,10 +22,9 @@ public class BidProductController {
// 创建skup
@RequestMapping(params = "method=ufo.product.bid.createSkup")
public boolean createSkup(@RequestBody BidStoragePriceVo skupVo) {
public void createSkup(@RequestBody BidStoragePriceVo skupVo) {
logger.info("in method=ufo.product.bid.createSkup, skupVo = {}", skupVo);
bidProductService.createSkup(skupVo);
return true;
}
... ... @@ -35,9 +35,16 @@ public class BidProductController {
* @return
*/
@RequestMapping(params = "method=ufo.product.bid.isCanceled")
public boolean isCanceled(@RequestParam(value = "skup") int skup) {
public ApiResponse isCanceled(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.isCanceled, skup = {}", skup);
return bidProductService.isCanceled(skup);
try {
boolean result = bidProductService.isCanceled(skup);
return new ApiResponse(200, "ok", result);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -47,9 +54,15 @@ public class BidProductController {
@RequestMapping(params = "method=ufo.product.bid.cancelSaleByUser")
public ApiResponse cancelSaleByUser(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.cancelSaleByUser, skup = {}", skup);
try {
bidProductService.cancelSaleByUser(skup);
logger.info("cancelSaleByUser success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -59,9 +72,15 @@ public class BidProductController {
@RequestMapping(params = "method=ufo.product.bid.cancelSaleBySystem")
public ApiResponse cancelSaleBySystem(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.cancelSaleBySystem, skup = {}", skup);
try {
bidProductService.cancelSaleBySystem(skup);
logger.info("cancelSaleBySystem success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -71,9 +90,15 @@ public class BidProductController {
@RequestMapping(params = "method=ufo.product.bid.cancelSaleByCS")
public ApiResponse cancelSaleByCS(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.cancelSaleByCS, skup = {}", skup);
try {
bidProductService.cancelSaleByPlatform(skup);
logger.info("cancelSaleByCS success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -83,9 +108,15 @@ public class BidProductController {
@RequestMapping(params = "method=ufo.product.bid.resetSaleableFromUserCancel")
public ApiResponse resetSaleableFromUserCancel(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.resetSaleableFromUserCancel, skup = {}", skup);
try {
bidProductService.resetSaleableFromUserCancel(skup);
logger.info("resetSaleable success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -95,9 +126,15 @@ public class BidProductController {
@RequestMapping(params = "method=ufo.product.bid.resetSaleableFromBidFinished")
public ApiResponse resetSaleableFromBidFinished(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.resetSaleableFromBidFinished, skup = {}", skup);
try {
bidProductService.resetSaleableFromBidFinished(skup);
logger.info("resetSaleable success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -110,9 +147,15 @@ public class BidProductController {
public ApiResponse sale(@RequestParam(value = "productId") int productId,
@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.sale,productId = {}, skup = {}", productId, skup);
try {
bidProductService.sale(productId, skup);
logger.info("sale success, skup = {}", skup);
return new ApiResponse(200, "ok", Boolean.TRUE);
return new ApiResponse(200, "ok", true);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), false);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", false);
}
}
/**
... ... @@ -122,8 +165,15 @@ public class BidProductController {
* @return
*/
@RequestMapping(params = "method=ufo.product.bid.getSaleable")
public BidStoragePriceVo getSaleable(@RequestParam(value = "skup") int skup) {
public ApiResponse getSaleable(@RequestParam(value = "skup") int skup) {
logger.info("in method=ufo.product.bid.getSaleable, skup = {}", skup);
return bidProductService.getSaleable(skup);
try {
BidStoragePriceVo bidStoragePriceVo = bidProductService.getSaleable(skup);
return new ApiResponse(200, "ok", bidStoragePriceVo);
} catch (ServiceException sex) {
return new ApiResponse(sex.getCode(), sex.getErrorMessage(), null);
} catch (Exception ex) {
return new ApiResponse(500, "操作失败", null);
}
}
}
... ...
... ... @@ -60,7 +60,8 @@ public class BidProductService {
//检测一下skup是否存在
checkAndGetSkup(skup);
if (!doCancelSale(skup, BidSkupStatus.USER_CANCEL)) {
throw new ServiceException(500, "商品(skup)取消失败:" + skup);
logger.warn("cancelSaleByUser fail, skup:{}", skup);
throw new ServiceException(500, "商品取消失败");
}
}
... ... @@ -75,7 +76,8 @@ public class BidProductService {
//检测一下skup是否存在
checkAndGetSkup(skup);
if (!doCancelSale(skup, BidSkupStatus.SYS_CANCEL)) {
throw new ServiceException(500, "商品(skup)取消失败:" + skup);
logger.warn("cancelSaleBySystem fail, skup:{}", skup);
throw new ServiceException(500, "商品取消失败:" + skup);
}
}
... ... @@ -90,7 +92,8 @@ public class BidProductService {
//检测一下skup是否存在
checkAndGetSkup(skup);
if (!doCancelSale(skup, BidSkupStatus.PLATFORM_CANCEL)) {
throw new ServiceException(500, "商品(skup)取消失败:" + skup);
logger.warn("cancelSaleByPlatform fail, skup:{}", skup);
throw new ServiceException(500, "商品取消失败");
}
}
... ... @@ -103,7 +106,8 @@ public class BidProductService {
public void resetSaleableFromUserCancel(int skup) {
logger.info("resetSaleableFromUserCancel, skup:{}", skup);
if (!doResetSaleable(skup, BidSkupStatus.USER_CANCEL)) {
throw new ServiceException(500, "商品(skup)恢复到可售状态失败:" + skup);
logger.warn("resetSaleableFromUserCancel fail, skup:{}", skup);
throw new ServiceException(500, "商品恢复到可售状态失败");
}
}
... ... @@ -116,7 +120,8 @@ public class BidProductService {
public void resetSaleableFromBidFinished(int skup) {
logger.info("resetSaleableFromBidFinished, skup:{}", skup);
if (!doResetSaleable(skup, BidSkupStatus.BID_FINISHED)) {
throw new ServiceException(500, "商品(skup)恢复到可售状态失败:" + skup);
logger.warn("resetSaleableFromBidFinished fail, skup:{}", skup);
throw new ServiceException(500, "商品恢复到可售状态失败");
}
}
... ... @@ -133,7 +138,8 @@ public class BidProductService {
checkProductStatus(productId);
//必须是上架状态
if (!doSale(skup)) {
throw new ServiceException(500, "商品(skup)已卖出:" + skup);
logger.warn("sale fail, skup:{}", skup);
throw new ServiceException(500, "商品已卖出");
}
}
... ... @@ -264,7 +270,8 @@ public class BidProductService {
BidStoragePrice sp = bidStoragePriceMapper.selectBySkup(skup);
if (sp == null) {
throw new ServiceException(400, "商品(skup)不存在:" + skup);
logger.warn("not find sp,skup = {}", skup);
throw new ServiceException(400, "商品不存在");
}
return sp;
}
... ...