Authored by mali

Merge branch 'test6.8.5' of http://git.yoho.cn/ufo/yohoufo-fore into test6.8.5

Showing 22 changed files with 496 additions and 49 deletions
... ... @@ -56,4 +56,6 @@ public interface StoragePriceMapper {
List<StoragePrice> selectBatchLeastPrice(@Param("skuList") Collection<Integer> skuList);
List<StoragePrice> selectByStorageIdsPlus(@Param("list") List<Integer> integers, @Param("storageId") Integer storageId, @Param("sellerUid") Integer sellerUid);
int updateSkupHideStatus(@Param("uid") Integer uid, @Param("status") int status);
}
\ No newline at end of file
... ...
... ... @@ -85,7 +85,7 @@
where skup = #{skup,jdbcType=INTEGER} and status = 2
</update>
<select id="selectLeastPrice" resultMap="BaseResultMap">
select price, skup from storage_price where storage_id = #{storageId,jdbcType=INTEGER} and status = 1 order by price limit 1
select price, skup from storage_price where storage_id = #{storageId,jdbcType=INTEGER} and status = 1 and is_hide = 0 order by price limit 1
</select>
<select id="selectByStorageIds" resultMap="BaseResultMap">
select id, skup, storage_id, price, status
... ... @@ -95,6 +95,7 @@
open="(" separator="," close=")">
#{item}
</foreach>
and is_hide = 0
</select>
<select id="selectBySkupList" resultMap="BaseResultMap">
select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
... ... @@ -138,6 +139,11 @@
</foreach>
</update>
<update id="updateSkupHideStatus">
update storage_price set is_hide = #{status}, update_time = unix_timestamp()
where seller_uid = #{uid} and status in(0,1,100)
</update>
<select id="selectBatchLeastPrice" resultMap="BaseResultMap">
select storage_id , min(price) as price from storage_price where
storage_id in
... ...
... ... @@ -3,10 +3,12 @@ package com.yohoufo.order.charge;
import com.yoho.core.common.utils.YHMath;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohoufo.order.charge.model.*;
import com.yohoufo.order.service.support.DeliveryWayCostSupport;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.support.ShoppingSupport;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -33,6 +35,9 @@ public class ChargeService {
@Autowired
private DeliveryWayCostSupport deliveryWayCostSupport;
@Autowired
private ShoppingSupport shoppingSupport;
/**
* 算费
... ... @@ -87,9 +92,12 @@ public class ChargeService {
*/
private void calculateShippingAmount(ChargeContext chargeContext) {
double deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
//如果是门店自提,则免运费
double deliveryWayCost = shoppingSupport.isDeliveryWayByStore(chargeContext.getChargeParam().getDeliveryWay()) ?
0 : deliveryWayCostSupport.getCostOfSf();
//运费
chargeContext.getChargeResult().setDeliveryWay(chargeContext.getChargeParam().getDeliveryWay());
chargeContext.getChargeResult().setShippingAmount(deliveryWayCost);
ChargeResult chargeResult = chargeContext.getChargeResult();
... ... @@ -98,8 +106,9 @@ public class ChargeService {
//包括运费
double newFinalAmount = YHMath.add(oldFinalAmount, deliveryWayCost);
chargeResult.setFinalAmount(newFinalAmount);
logger.info("[{}] step shipping charge,sfExpressAmount:{},oldFinalAmount:{},newFinalAmount:{}",
logger.info("[{}] step shipping charge, deliveryWay:{},sfExpressAmount:{},oldFinalAmount:{},newFinalAmount:{}",
chargeContext.getChargeParam().getUid(),
chargeContext.getChargeParam().getDeliveryWay(),
chargeResult.getShippingAmount(),
oldFinalAmount,
chargeResult.getFinalAmount());
... ...
... ... @@ -15,5 +15,6 @@ import java.util.List;
@Builder
public class ChargeParam {
private int uid;
private int deliveryWay;
private List<String> couponCodes;
}
... ...
... ... @@ -20,6 +20,11 @@ public class ChargeResult {
*/
private double shippingAmount;
/**
* 发货方式
*/
private int deliveryWay;
/**
* 优惠券支付结果
... ...
... ... @@ -49,6 +49,23 @@ public class ActionStatusHold {
static {
canModifyAddressStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode(), OrderStatus.SELLER_SEND_OUT.getCode(),OrderStatus.PLATFORM_RECEIVE.getCode());
}
//has paid
static List<Integer> hasPaid ;
static {
hasPaid = Arrays.asList(OrderStatus.HAS_PAYED.getCode(),
OrderStatus.SELLER_SEND_OUT.getCode(),
OrderStatus.PLATFORM_CHECKING.getCode(),
OrderStatus.WAITING_RECEIVE.getCode(),
OrderStatus.PLATFORM_RECEIVE.getCode(),
OrderStatus.JUDGE_PASS.getCode(),
OrderStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER.getCode(),
OrderStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE.getCode());
}
}
public static boolean isBuyerPaid(Integer status){
return BuyerASH.hasPaid.contains(status);
}
public static boolean buyerCanModifyAddress(Integer status){
... ...
package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.model.request.OfflineShoppingRequest;
import com.yohoufo.order.model.response.ComputeResponse;
import com.yohoufo.order.model.response.OfflinePaymentResponse;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.IOfflineShoppingService;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/shopping")
public class OfflineShoppingController {
private Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
IOfflineShoppingService offlineShoppingService;
/**
* 结算
* @return
*/
@RequestMapping(params = "method=ufo.order.offlinePayment")
public ApiResponse offlinePayment(@RequestParam(name = "uid") Integer uid,
@RequestParam(name = "skup") Integer skup,
@RequestParam(name = "store_id") Integer storeId){
OfflineShoppingRequest req = new OfflineShoppingRequest();
req.setUid(uid);
req.setSkup(skup);
req.setStoreId(storeId);
logger.info("in ufo.order.offlinePayment, req {}", req);
OfflinePaymentResponse paymentResponse = offlineShoppingService.offlinePayment(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(paymentResponse).build();
}
/**
* 用券结算
*
* @return
*/
@RequestMapping(params = "method=ufo.order.offlineCompute")
public ApiResponse offlineCompute(@RequestParam(name = "uid") Integer uid,
@RequestParam(name = "skup") Integer skup,
@RequestParam(name = "coupon_code",required = false) String couponCode) {
OfflineShoppingRequest req = new OfflineShoppingRequest();
req.setUid(uid);
req.setSkup(skup);
req.setCouponCodes(CouponCodeUtils.asList(couponCode));
logger.info("in ufo.order.offlineCompute, req {}", req);
ComputeResponse resp = offlineShoppingService.offlineCompute(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).build();
}
/**
* 提交订单成功
* @return
*/
@RequestMapping(params = "method=ufo.order.offlineSubmit")
public ApiResponse offlineSubmit(@RequestParam(name = "uid") Integer uid,
@RequestParam(name = "skup") Integer skup,
@RequestParam(name = "coupon_code",required = false) String couponCode,
@RequestParam(name = "channelNo", required = false) String channelNo,
@RequestParam(name = "store_id") Integer storeId,
@RequestParam(name = "user_longitude") Double userLongitude,
@RequestParam(name = "user_latitude") Double userLatitude,
@RequestParam(name = "client_type", required = false) String clientType){
if(StringUtils.isBlank(channelNo)){
channelNo = "2919";
}
OfflineShoppingRequest request = new OfflineShoppingRequest();
request.setUid(uid);
request.setSkup(skup);
request.setCouponCodes(CouponCodeUtils.asList(couponCode));
request.setChannelNo(channelNo);
request.setAddressId("0"); //门店自提,不需addressId
request.setStoreId(storeId);
request.setUserLongitude(userLongitude);
request.setUserLatitude(userLatitude);
request.setClientType(clientType);
logger.info("in ufo.order.offlineSubmit, req {}", request);
OrderSubmitResponse submitResponse = offlineShoppingService.offlineSubmit(request);
logger.info("out ufo.order.offlineSubmit,resp:{}", submitResponse);
return new ApiResponse.ApiResponseBuilder().code(200).data(submitResponse).build();
}
}
... ...
... ... @@ -15,6 +15,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
@NoArgsConstructor
public class BuyerPenaltyCalResult {
private Integer uid;
private Long orderCode;
private BigDecimal orderActualAmount;
... ... @@ -22,4 +23,9 @@ public class BuyerPenaltyCalResult {
private BigDecimal penaltyAmount;
private BigDecimal leftAmount;
private BigDecimal penaltyRate;
private final static BuyerPenaltyCalResult defaultBPCR;
static {defaultBPCR = new BuyerPenaltyCalResult();}
public static BuyerPenaltyCalResult getDefault(){
return defaultBPCR;
}
}
... ...
package com.yohoufo.order.model.request;
import lombok.Data;
import lombok.ToString;
@Data
@ToString(callSuper = true)
public class OfflineShoppingRequest extends ShoppingRequest {
private Integer storeId;
private Double userLongitude;
private Double userLatitude;
}
... ...
package com.yohoufo.order.model.response;
import lombok.Data;
import lombok.ToString;
@Data
@ToString(callSuper = true)
public class OfflinePaymentResponse extends PaymentResponse {
private String storeName;
private String storeAddress;
public static OfflinePaymentResponse wrap(PaymentResponse paymentResponse) {
OfflinePaymentResponse offlinePaymentResponse = new OfflinePaymentResponse();
offlinePaymentResponse.setAmount(paymentResponse.getAmount());
offlinePaymentResponse.setGood(paymentResponse.getGood());
offlinePaymentResponse.setPaymentWay(paymentResponse.getPaymentWay());
offlinePaymentResponse.setDeliveryWay(paymentResponse.getDeliveryWay());
offlinePaymentResponse.setPromotionFormulaList(paymentResponse.getPromotionFormulaList());
offlinePaymentResponse.setDamagesDesc(paymentResponse.getDamagesDesc());
return offlinePaymentResponse;
}
}
... ...
package com.yohoufo.order.service;
import com.yohoufo.order.model.request.OfflineShoppingRequest;
import com.yohoufo.order.model.response.ComputeResponse;
import com.yohoufo.order.model.response.OfflinePaymentResponse;
import com.yohoufo.order.model.response.OrderSubmitResponse;
public interface IOfflineShoppingService {
/**
* 结算页数据
* @param request
* @return
*/
OfflinePaymentResponse offlinePayment(OfflineShoppingRequest request);
/**
* 重新结算
* @param request
* @return
*/
ComputeResponse offlineCompute(OfflineShoppingRequest request);
/**
* 提交订单
* @param shoppingRequest
* @return
*/
OrderSubmitResponse offlineSubmit(OfflineShoppingRequest shoppingRequest);
}
... ...
... ... @@ -624,7 +624,14 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
|| type == SellerWalletDetail.Type.APPRAISE_FAIL
|| type == SellerWalletDetail.Type.CS_CANCEL_BEFORE_DEPOT_RECEIVE) {
// 处罚保证金
// TODO 如果是超级卖家
boolean isSuper = false;
logger.info("{}修改钱包,uid={},处罚保证金场合:获取身份超级卖家:{}", type.getName(), uid, isSuper);
if(isSuper) {
availAmount = money.multiply(new BigDecimal("-1"));
} else {
lockAmount = money.multiply(new BigDecimal("-1"));
}
tradeAmount = lockAmount;
logger.info("{}修改钱包,uid={},处罚保证金场合:", type.getName(), uid);
}
... ... @@ -635,7 +642,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
logger.info("{}修改钱包表余额,bean={}", message, sw);
if (sellerWalletMapper.addMoney(sw) == 0) {
logger.error(message + "失败,(余额不足或钱包不可用)更新表返回0,bean={}", sw);
// CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "(余额不足货钱包不可用)更新表返回0,uid=" + uid + ", bean为:"+ sw);
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.walletPunishment", "用户:" + uid + ",(余额不足货钱包不可用),更新表返回 0,bean为:"+ sw);
return null;
}
logger.info("修改钱包表余额成功,bean={}", sw);
... ...
... ... @@ -10,17 +10,15 @@ import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.OrdersPayMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.OrdersPay;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.model.dto.BuyerPenalty;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.service.impl.MetaConfigService;
import com.yohoufo.order.service.impl.OrderDynamicConfig;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Objects;
... ... @@ -42,6 +40,9 @@ public class BuyerCancelCompensateComputeHandler {
public BuyerPenaltyCalResult calBuyerPenaltyCalResult(BuyerOrder buyerOrder){
Integer buyerUid = buyerOrder.getUid();
Long orderCode = buyerOrder.getOrderCode();
if(!ActionStatusHold.isBuyerPaid(buyerOrder.getStatus())){
return BuyerPenaltyCalResult.getDefault();
}
OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
BigDecimal orderActualAmount = buyerOrder.getAmount();
BigDecimal shipFee = buyerOrder.getShipFee();
... ...
... ... @@ -7,14 +7,16 @@ import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.ButtonShow;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.*;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.GoodsInfo;
import com.yohoufo.order.model.response.OrderDetailInfo;
... ... @@ -36,9 +38,6 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private OrdersPayService ordersPayService;
@Autowired
protected IExpressInfoService expressInfoService;
abstract BuyerOrder getBuyerOrder(int uid, long orderCode);
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl;
import com.google.common.base.Verify;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
... ... @@ -30,11 +29,13 @@ import java.math.BigDecimal;
import java.util.Objects;
import java.util.function.BiConsumer;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
/**
* @author LUOXC
* @date 2019/1/8 14:07
*/
@Slf4j
@Slf4j(topic = "orderCloseLog")
class BuyerOrderCancelHandler {
private final int uid;
... ... @@ -65,8 +66,6 @@ class BuyerOrderCancelHandler {
private BuyerRefundCouponEvent.BizCase refundCouponCase;
private AlarmConfig failAlarm;
BuyerOrderCancelHandler(int uid, long orderCode) {
... ... @@ -132,19 +131,29 @@ class BuyerOrderCancelHandler {
}
public void cancel() {
log.info("cancel order {} from {} to {}", orderCode, expectStatus, targetStatus);
verify();
// 获取买家订单
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(buyerOrder)) {
log.info("cancel order {} fail, order is not exist", orderCode);
throwServiceException(ServiceError.ORDER_NOT_EXIST);
}
// 当前状态不可取消订单
if (expectStatus.getCode() != buyerOrder.getStatus()) {
throw new ServiceException(ServiceError.ORDER_SERVICE_ERROR);
log.info("cancel order {} fail, order status is not expect", orderCode);
throwServiceException("当前状态不可取消订单");
}
// 更新订单状态成功
if (updateBuyerOrderStatus()) {
log.info("cancel order {} from {} to {} success", orderCode, expectStatus, targetStatus);
refundCoupon();
transfer();
refundPayGoodsMoney(buyerOrder);
noticeSeller();
} else {
log.info("cancel order {} fail, order status has changed", orderCode);
throwServiceException("当前状态不可取消订单");
}
}
... ... @@ -180,6 +189,7 @@ class BuyerOrderCancelHandler {
.uid(uid)
.orderCode(orderCode)
.build();
log.info("refund coupon by order {} request is {}", orderCode, buyerRefundCouponEvent);
EventBusPublisher.publishEvent(buyerRefundCouponEvent);
}
... ... @@ -193,6 +203,7 @@ class BuyerOrderCancelHandler {
.transferCase(transferCase)
.swdType(sellerWalletDetailType)
.build();
log.info("transfer by order {} request is {}", orderCode, transferMoneyRequest);
transferService.transfer(transferMoneyRequest);
}
... ... @@ -215,9 +226,11 @@ class BuyerOrderCancelHandler {
.refundCase(goodsMoneyRefundCase)
.amount(goodsMoney);
try {
log.info("refund pay goods money by order {} request is {} ", orderCode, paymentRequest);
goodsMoneyRefundConsumer.accept(paymentRequest, billLogEventBuilder.skup(getSkup()));
} catch (Exception ex) {
log.warn("pay refund fail,req {}", paymentRequest, ex);
log.info("refund pay goods money by order {} success", orderCode);
} catch (Exception e) {
log.info("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e);
BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
EventBusPublisher.publishEvent(billLogEvent);
... ... @@ -235,10 +248,11 @@ class BuyerOrderCancelHandler {
private void noticeSeller() {
if (Objects.nonNull(sellerNoticeSender)) {
try {
log.info("notice seller buyer order has closed by order {}", orderCode);
SellerOrderGoods sog = getSellerOrderGoods();
sellerNoticeSender.notice(sog, orderCode, sellerNoticeSenderTimes);
} catch (Exception ex) {
log.warn("seller deliver notice fail,times {} order code is {}", sellerNoticeSenderTimes, orderCode, ex);
} catch (Exception e) {
log.info("notice seller buyer order has closed by order {} fail", orderCode, e);
}
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.response.store.StoreInfoBo;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.order.model.request.OfflineShoppingRequest;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.ComputeResponse;
import com.yohoufo.order.model.response.OfflinePaymentResponse;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.service.IOfflineShoppingService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("offlineShoppingService")
public class OfflineShoppingServiceImpl extends ShoppingServiceImpl implements IOfflineShoppingService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
UfoServiceCaller ufoServiceCaller;
@Override
public OfflinePaymentResponse offlinePayment(OfflineShoppingRequest request) {
StoreInfoBo storeInfoBo = queryStoreInfo(request.getStoreId());
if(storeInfoBo == null) {
logger.warn("storeId from goods not invalid, req: {}", request);
throw new UfoServiceException(500, "商品门店信息为空");
}
PaymentResponse paymentResponse = super.payment(request);
return buildOfflinePaymentResponse(paymentResponse, storeInfoBo);
}
private OfflinePaymentResponse buildOfflinePaymentResponse(PaymentResponse paymentResponse, StoreInfoBo storeInfoBo) {
OfflinePaymentResponse offlinePaymentResponse = OfflinePaymentResponse.wrap(paymentResponse);
offlinePaymentResponse.setStoreName(storeInfoBo.getStoreName());
offlinePaymentResponse.setStoreAddress(storeInfoBo.getStoreAddress());
return offlinePaymentResponse;
}
@Override
public ComputeResponse offlineCompute(OfflineShoppingRequest request) {
return super.compute(request);
}
@Override
public OrderSubmitResponse offlineSubmit(OfflineShoppingRequest offlineRequest) {
if(!checkLocationInStore(offlineRequest.getStoreId(), offlineRequest.getUserLongitude(), offlineRequest.getUserLatitude())) {
logger.warn("user not location in the store, req: {}", offlineRequest);
throw new UfoServiceException(500, "定位不在门店内,不允许购买");
}
return super.submit(offlineRequest);
}
private boolean checkLocationInStore(int storeId, double userLongitude, double userLatitude) {
ApiResponse resp = ufoServiceCaller.call("ufo.store.isLocationInStore", ApiResponse.class, storeId, userLongitude, userLatitude);
if (resp != null && resp.getCode()==200) {
if (resp.getData() != null) {
JSONObject json = (JSONObject)resp.getData();
return json.getBoolean("isInRange");
}
}
logger.warn("check location failed: {}", resp);
throw new UfoServiceException(500, "校验定位信息失败");
}
//查询门店信息
private StoreInfoBo queryStoreInfo(int storeId) {
ApiResponse resp = ufoServiceCaller.call("ufo.store.queryStoreInfoById", ApiResponse.class, storeId);
if (resp != null && resp.getCode()==200) {
if (resp.getData() != null) {
return (StoreInfoBo)resp.getData();
}
}
return null;
}
@Override
protected Pair<AddressInfo, AddressInfo> getAndCheckAddressInfo(ShoppingRequest shoppingRequest) {
OfflineShoppingRequest offlineShoppingRequest = (OfflineShoppingRequest) shoppingRequest;
StoreInfoBo storeInfoBo = queryStoreInfo(offlineShoppingRequest.getStoreId());
if(storeInfoBo == null) {
logger.warn("storeInfo not exist, req: {}", offlineShoppingRequest);
throw new UfoServiceException(500, "门店信息不存在");
}
AddressInfo storeAddress = new AddressInfo();
storeAddress.setAddress_id(0);
storeAddress.setUid(offlineShoppingRequest.getUid());
storeAddress.setAddress(storeInfoBo.getStoreAddress());
return Pair.of(storeAddress, storeAddress);
}
@Override
protected OrderAttributes buildOrderArrtribute() {
return OrderAttributes.OFFLINE;
}
@Override
protected int buildDeliveryWay() {
return OrderConstant.DELIVERY_WAY_STORE;
}
}
... ...
... ... @@ -43,13 +43,17 @@ import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.MathUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
@Primary
@Service
public class ShoppingServiceImpl implements IShoppingService {
... ... @@ -119,7 +123,7 @@ public class ShoppingServiceImpl implements IShoppingService {
PaymentResponse response = new PaymentResponse();
response.setPaymentWay(shoppingSupport.getPaymentWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult().getShippingAmount()));
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult()));
response.setGood(shoppingSupport.getGoodsInfo(skupGood));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
... ... @@ -149,8 +153,12 @@ public class ShoppingServiceImpl implements IShoppingService {
}
private ChargeContext buildChargeContext(ShoppingRequest request, SellerOrderGoods skupInfo) {
ChargeParam chargeParam = ChargeParam.builder().uid(request.getUid())
.deliveryWay(buildDeliveryWay())
.couponCodes(request.getCouponCodes()).build();
return ChargeContext.builder()
.chargeParam(ChargeParam.builder().uid(request.getUid()).couponCodes(request.getCouponCodes()).build())
.chargeParam(chargeParam)
.chargeGoods(ChargeGoods.builder().goodsPrice(skupInfo.getGoodsPrice()).productId(skupInfo.getProductId()).skup(skupInfo.getId()).build()).build();
}
... ... @@ -230,22 +238,11 @@ public class ShoppingServiceImpl implements IShoppingService {
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 检查地址是否合法
int addressId = AddressUtil.getDecryptStr(shoppingRequest.getAddressId());
if (addressId < 0){
logger.warn("submit addressId invalidate, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
//查询并校验用户地址
Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest);
// 检查skup是否可售
SellerOrderGoods skup = checkSkupSellOrNot(shoppingRequest.getSkup());
AddressInfo addressInfo = userProxyService.getAddressInfoNotHidden(shoppingRequest.getUid(), addressId);
if(AddressHelper.isNeedUpdate(addressInfo)){
logger.warn("submit addressId need update, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}
//算费
ChargeContext chargeContext = buildChargeContext(shoppingRequest,skup);
... ... @@ -258,8 +255,6 @@ public class ShoppingServiceImpl implements IShoppingService {
logger.info("generate new orderCode:{}",orderCode);
AddressInfo hiddenAddress = userProxyService.getHiddenAddressInfo(shoppingRequest.getUid(), addressId);
// 减库存,skup更新成不可售,入库
//BigDecimal shipFee = new BigDecimal(delivery_way_sf_cost);
int uid;
... ... @@ -269,7 +264,7 @@ public class ShoppingServiceImpl implements IShoppingService {
.orderCode(orderCode)
.productId(skup.getProductId())
.paymentType(OrderConstant.PAYMENT_ONLINE)
.deliverWay(OrderConstant.DELIVERY_WAY_SF)
.deliverWay(buildDeliveryWay())
.channelNo(shoppingRequest.getChannelNo())
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
.shipFee(BigDecimal.valueOf(chargeResult.getShippingAmount()))
... ... @@ -277,10 +272,10 @@ public class ShoppingServiceImpl implements IShoppingService {
.couponAmount(BigDecimal.valueOf(chargeResult.getCouponPayResult().getCouponAmount()))
.build()
)
.hiddenAddressInfo(hiddenAddress)
.addressInfo(addressInfo)
.hiddenAddressInfo(userAddressPair.getRight())
.addressInfo(userAddressPair.getLeft())
.clientType(shoppingRequest.getClientType())
.attributes(OrderAttributes.COMMON_IN_STOCK.getCode())
.attributes(buildOrderArrtribute().getCode()) //1,普通;2,线下店;3,急速发货
.build();
BuyerOrderSubmitResult submitResult = ordeCreationService.doSumbitOrder(orderBuilder);
... ... @@ -323,6 +318,43 @@ public class ShoppingServiceImpl implements IShoppingService {
}
/**
* 查询并校验用户地址(left: 用户地址; right: 脱敏的用户地址)
*
* @return
*/
protected Pair<AddressInfo, AddressInfo> getAndCheckAddressInfo(ShoppingRequest shoppingRequest) {
// 检查地址是否合法
int addressId = AddressUtil.getDecryptStr(shoppingRequest.getAddressId());
if (addressId < 0){
logger.warn("submit addressId invalidate, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
AddressInfo addressInfo = userProxyService.getAddressInfoNotHidden(shoppingRequest.getUid(), addressId);
if(AddressHelper.isNeedUpdate(addressInfo)){
logger.warn("submit addressId need update, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}
//脱敏的用户地址
AddressInfo hiddenAddress = userProxyService.getHiddenAddressInfo(shoppingRequest.getUid(), addressId);
return Pair.of(addressInfo, hiddenAddress);
}
/**
* 获取订单attribute属性
* @return
*/
protected OrderAttributes buildOrderArrtribute() {
return OrderAttributes.COMMON_IN_STOCK;
}
protected int buildDeliveryWay() {
return OrderConstant.DELIVERY_WAY_SF;
}
}
... ...
... ... @@ -39,16 +39,25 @@ public class ShoppingSupport {
* 配送方式
* @return
*/
public PaymentResponse.DeliveryWay getDeliverWay(double deliveryWayCost) {
public PaymentResponse.DeliveryWay getDeliverWay(final ChargeResult chargeResult) {
// 快递方式
PaymentResponse.DeliveryWay deliveryWay = new PaymentResponse.DeliveryWay();
deliveryWay.setDeliveryWayId(OrderConstant.DELIVERY_WAY_SF);
deliveryWay.setDeliveryWayCost(OrderConstant.MONEY_SIGN + deliveryWayCost);
deliveryWay.setDeliveryWayName(OrderConstant.DELIVERY_WAY_SF_NAME);
deliveryWay.setDeliveryWayId(chargeResult.getDeliveryWay());
deliveryWay.setDeliveryWayCost(OrderConstant.MONEY_SIGN + chargeResult.getShippingAmount());
deliveryWay.setDeliveryWayName(getDeliveryWayStr(chargeResult.getDeliveryWay()));
return deliveryWay;
}
private String getDeliveryWayStr(int deliveryWay) {
return deliveryWay == OrderConstant.DELIVERY_WAY_STORE ? OrderConstant.DELIVERY_WAY_STORE_NAME : OrderConstant.DELIVERY_WAY_SF_NAME;
}
public boolean isDeliveryWayByStore(int deliveryWay) {
return deliveryWay == OrderConstant.DELIVERY_WAY_STORE;
}
/**
* 商品情报
* @param skup
... ...
package com.yohoufo.order.utils;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
/**
* @author LUOXC
* @date 2019/1/9 11:14
*/
public class ServiceExceptions {
public static void throwServiceException(String message) {
ServiceException serviceException = new ServiceException(ServiceError.ORDER_SERVICE_ERROR);
serviceException.setParams(message);
throw serviceException;
}
public static void throwServiceException(ServiceError serviceError) {
throw new ServiceException(serviceError);
}
}
... ...
... ... @@ -39,6 +39,7 @@ public class ProductController {
private final Logger LOG = LoggerFactory.getLogger(ProductController.class);
@Autowired
private ProductService productService;
... ... @@ -279,6 +280,24 @@ public class ProductController {
return new ApiResponse(200, "取消卖出成功!", Boolean.TRUE);
}
@RequestMapping(params = "method=ufo.product.hideSellerAllSkup")
public ApiResponse hideSellerAllSkup(
@RequestParam(value = "uid", required = true) Integer uid) {
LOG.info("in method=ufo.product.hideSellerAllSkup uid={}", uid);
productService.changeSkupHideStatus(uid, 1);// status:1 隐藏商品
LOG.info("hideSellerAllSkup success uid = {}", uid);
return new ApiResponse(200, "隐藏用户商品成功!", Boolean.TRUE);
}
@RequestMapping(params = "method=ufo.product.showSellerAllSkup")
public ApiResponse showSellerAllSkup(
@RequestParam(value = "uid", required = true) Integer uid) {
LOG.info("in method=ufo.product.showSellerAllSkup uid={}", uid);
productService.changeSkupHideStatus(uid, 0);// status:0 展示商品
LOG.info("showSellerAllSkup success uid = {}", uid);
return new ApiResponse(200, "隐藏用户商品成功!", Boolean.TRUE);
}
@Autowired
private ControllerCacheAop cacheAop;
private ExecutorService executors = Executors.newFixedThreadPool(1);
... ...
... ... @@ -83,4 +83,6 @@ public interface ProductService {
* @return
*/
SkupDetailForScreenResp getSkuPDetailForShopsScreen(Integer skuP, Integer storeId);
void changeSkupHideStatus(Integer uid, int status);
}
... ...
... ... @@ -736,6 +736,13 @@ public class ProductServiceImpl implements ProductService{
}
@Override
public void changeSkupHideStatus(Integer uid, int status) {
LOGGER.info("开始:Skup隐藏展示状态修改,uid={} , toStatus={}");
int count = storagePriceMapper.updateSkupHideStatus(uid, status);
LOGGER.info("完成:Skup隐藏展示状态修改,uid={} , toStatus={}, exeCount={}", uid, status, count);
}
@Override
public List<SaleCategoryBo> querySaleCategory() {
// 查数据库List
List<SaleCategory> dbData = saleCategoryMapper.selectValid();
... ... @@ -979,4 +986,5 @@ public class ProductServiceImpl implements ProductService{
result.setSkupDetail(innerResult);
return result;
}
}
... ...