Authored by chenchao

Merge branch 'master' into hotfix_防止恶意刷单

... ... @@ -94,7 +94,7 @@ public class ChargeService {
//如果是门店自提,则免运费
if (shoppingSupport.isDeliveryWayByStore(chargeContext.getChargeParam().getDeliveryWay())){
deliveryWayCost = 0D;
}else if(chargeContext.getUserAddressPair() != null){
}else/* if(chargeContext.getUserAddressPair() != null){
String areaCode = chargeContext.getUserAddressPair().getLeft().getAreaCode();
deliveryWayCost = deliveryWayCostSupport.getCostOfSfByAreaCode(areaCode);
}else{
... ... @@ -102,6 +102,8 @@ public class ChargeService {
if (chargeContext.isShipFeeRequird()){
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
}
}*/{
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
}
//运费
chargeContext.getChargeResult().setDeliveryWay(chargeContext.getChargeParam().getDeliveryWay());
... ...
... ... @@ -40,10 +40,12 @@ public class ShoppingController {
*/
@RequestMapping(params = "method=ufo.order.payment")
public ApiResponse payment(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup){
@RequestParam(name = "skup") int skup,
@RequestParam(value = "app_version", required = false)String appVersion){
//AUTO 自动匹配
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup)
.couponCodes(CouponConstants.AUTO_RECOMMENDED_COUPON_CODES).build();
.couponCodes(CouponConstants.AUTO_RECOMMENDED_COUPON_CODES)
.appVersion(appVersion).build();
logger.info("in ufo.order.payment, req {}", req);
PaymentResponse paymentResponse = buyerOrderService.payment(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(paymentResponse).message("结算成功").build();
... ... @@ -59,7 +61,10 @@ public class ShoppingController {
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode) {
ShoppingRequest req = ShoppingRequest.builder().uid(uid).skup(skup).couponCodes(CouponCodeUtils.asList(couponCode)).build();
ShoppingRequest req = ShoppingRequest.builder()
.uid(uid).skup(skup)
.couponCodes(CouponCodeUtils.asList(couponCode))
.build();
logger.info("in ufo.order.selectCoupon, req {}", req);
ShoppingCouponListResp resp = buyerOrderService.selectCoupon(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("ok").build();
... ... @@ -74,12 +79,14 @@ public class ShoppingController {
public ApiResponse compute(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode,
@RequestParam(name = "addressId", required = false) String addressId) {
@RequestParam(name = "addressId", required = false) String addressId,
@RequestParam(value = "app_version", required = false)String appVersion) {
ShoppingRequest req = ShoppingRequest.builder().uid(uid)
.skup(skup)
.couponCodes(CouponCodeUtils.asList(couponCode))
.addressId(addressId)
.appVersion(appVersion)
.build();
logger.info("in ufo.order.compute, req {}", req);
ComputeResponse resp = buyerOrderService.compute(req);
... ...
... ... @@ -9,8 +9,8 @@ public class PayQueryBo {
//退款成功状态
private boolean refundStatus = false;
//订单编号
private String orderCode;
// //订单编号
// private String orderCode;
//订单金额
private double amount;
//
... ... @@ -46,14 +46,14 @@ public class PayQueryBo {
}
public String getOrderCode() {
return orderCode;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
//
// public String getOrderCode() {
// return orderCode;
// }
//
// public void setOrderCode(String orderCode) {
// this.orderCode = orderCode;
// }
public double getAmount() {
return amount;
... ...
... ... @@ -46,4 +46,9 @@ public class ShoppingRequest {
*/
private String inviteCode;
/**
*
*/
private String appVersion;
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.core.rabbitmq.YhProducer;
... ... @@ -22,6 +23,7 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ExpressForMqSend;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.BuyerOrderSellerDeliveryCheckEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
import com.yohoufo.order.model.response.AppraiseAddressResp;
... ... @@ -979,6 +981,40 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
return buyerOrderList.get(0);
}
private AddressInfo findBuyerAddressInfo(Integer uid, Long orderCode, Integer skup){
boolean skupIsNull = (null == skup);
boolean orderCodeIsNull = (null == orderCode);
BuyerOrder buyerOrder = null;
if (orderCodeIsNull){
//4 compatible before version 6.9.3(exclude), client transfer without order code
buyerOrder = findOrderCodeBySkup(skup);
orderCode = buyerOrder.getOrderCode();
LOGGER.info("in queryAppraiseAddress find buyer OrderCode By Skup , orderCode {} skup {}", orderCode, skup);
}
buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
AddressInfo buyerAddress = buyerOrderMetaService.getAddressInfo(buyerOrder.getUid(), orderCode);
LOGGER.info("in queryAppraiseAddress get buyerAddress {} orderCode {}, skup {}", buyerAddress, orderCode, skup);
return buyerAddress;
}
private AddressInfo findSellerAddressInfo(Integer uid, Integer skup){
SellerOrderMeta addressMeta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.BACK_2_SELLER_DELIVERY_ADDRESS);
AddressInfo addressInfo = null;
if (null != addressMeta) {
LOGGER.info("addressMeta is not null uid is {}, skup is {}", uid, skup);
try {
addressInfo = JSONObject.parseObject(addressMeta.getMetaValue(), AddressInfo.class);
}catch (Exception ex){
LOGGER.warn("findSellerAddressInfo parse addressMeta fail, uid {} skup {}, addressMeta {}",
uid, skup, addressMeta, ex);
}
}
return addressInfo;
}
/**
* 根据用户默认地址的省份定位到鉴定中心的地址返回 *
*
... ... @@ -996,16 +1032,10 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
return appraiseAddressService.queryInitAddress();
}
BuyerOrder buyerOrder = null;
if (orderCodeIsNull){
//4 compatible before version 6.9.3(exclude), client transfer without order code
buyerOrder = findOrderCodeBySkup(skup);
orderCode = buyerOrder.getOrderCode();
LOGGER.info("in queryAppraiseAddress find buyer OrderCode By Skup , orderCode {} skup {}", orderCode, skup);
}
buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
AddressInfo buyerAddress = buyerOrderMetaService.getAddressInfo(buyerOrder.getUid(), orderCode);
LOGGER.info("in queryAppraiseAddress get buyerAddress {} orderCode {}, skup {}", buyerAddress, orderCode, skup);
AddressInfo buyerAddress = findSellerAddressInfo(uid, skup);
LOGGER.info("in queryAppraiseAddress get Address {} orderCode {}, skup {}", buyerAddress, orderCode, skup);
// 根据用户id查询默认地址的省份
AppraiseAddressResp resp = null;
... ...
... ... @@ -19,6 +19,7 @@ import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohoufo.order.common.HbfqEnum;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
... ... @@ -237,11 +238,17 @@ public class PaymentServiceImpl implements IPaymentService {
AbstractPayService payService = getPayService(request.getPayment());
long orderCode = orderInfo.getOrderCode();
String tradeNo = String.valueOf(orderInfo.getOrderCode());
// 花呗分期的场合 用于退款的 out_trade_no = 支付时传给第三方的 out_trade_no = order_code + 花呗分期期数
if (payment == Payment.ALIPAY_HBFQ){
tradeNo = tradeNo + request.getHbfqNums();
HbfqEnum hbfqEnum = HbfqEnum.getByfqTerms(request.getHbfqNums());
if(hbfqEnum == null) {
logger.warn("fqNums from req invalid, fqNums: {}, orderCode: {}", request.getHbfqNums(), tradeNo);
throw new ServiceException(ServiceError.ORDER_FQNUM_INVALID);
}
tradeNo = tradeNo + hbfqEnum.getTradeNoPostfix();
}
PayQueryBo payQueryBo = payService.payQuery(tradeNo);
... ... @@ -251,7 +258,7 @@ public class PaymentServiceImpl implements IPaymentService {
return PaymentConfirmRsp.builder().orderCode(orderInfo.getOrderCode()).isPaid(OrderConstant.N_STR).build();
}
PaymentData paymentData = convertQueryPaymentData(payQueryBo);
PaymentData paymentData = convertQueryPaymentData(payQueryBo, orderCode);
paySuccess(paymentData);
... ... @@ -432,10 +439,10 @@ public class PaymentServiceImpl implements IPaymentService {
}
private PaymentData convertQueryPaymentData(PayQueryBo payQueryBo) {
private PaymentData convertQueryPaymentData(PayQueryBo payQueryBo, long orderCode) {
PaymentData paymentData = new PaymentData();
paymentData.setOrderCode(String.valueOf(payQueryBo.getOrderCode()));
paymentData.setOutTradeNo(payQueryBo.getOrderCode());
paymentData.setOrderCode(String.valueOf(orderCode));
paymentData.setOutTradeNo(payQueryBo.getPayOrderCode());
paymentData.setTotalFee(payQueryBo.getAmount());
paymentData.setBankCode(payQueryBo.getBankCode());
paymentData.setBankName(payQueryBo.getBankName());
... ...
... ... @@ -152,11 +152,12 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
fromCache = false;
BuildNode buildNode = super.prepareBuild(orderRequest);
orderDetailInfo = super.buildOrderDetail(buildNode);
BuyerOrder buyerOrder = buildNode.buyerOrder;
SellerOrderGoods sellerOrderGoods = buildNode.sellerOrderGoods;
AddressInfo buyerAddress = buyerOrderMetaService.getHiddenAddressInfo(buyerOrder.getUid(), orderCode);
// 收货地址 and 用户信息
if(Objects.nonNull(buildNode.userAddress)){
//卖家订单详情里才会有,买家没有
orderDetailInfo.setAppraiseAddress(appraiseAddressService.findAppraiseAddress(sellerOrderGoods.getDepotNo(), buyerAddress.getAreaCode()));
orderDetailInfo.setAppraiseAddress(appraiseAddressService.findAppraiseAddress(sellerOrderGoods.getDepotNo(), buildNode.userAddress.getAreaCode()));
}
//cache
orderCacheService.cacheOrderDetailInfo(uid, orderCode, TabType.SELL, orderDetailInfo);
}
... ...
... ... @@ -134,7 +134,7 @@ public class ShoppingServiceImpl implements IShoppingService {
PaymentResponse response = new PaymentResponse();
response.setPaymentWay(shoppingSupport.getPaymentWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeResult));
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeResult, request.getAppVersion()));
response.setGood(shoppingSupport.getGoodsInfo(skupGood));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
... ... @@ -237,10 +237,10 @@ public class ShoppingServiceImpl implements IShoppingService {
checkSkupIsChangePrice(uid, skup);
//构建算费
ChargeContext chargeContext = buildChargeContext(request, skupGood);
if (StringUtils.isNoneBlank(request.getAddressId())){
/*if (StringUtils.isNoneBlank(request.getAddressId())){
Pair<AddressInfo, AddressInfo> addressInfoPair = getAndCheckAddressInfo(request);
chargeContext.setUserAddressPair(addressInfoPair);
}
}*/
//算费
chargeService.charge(chargeContext);
//算费结果
... ...
... ... @@ -111,7 +111,8 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
PayQueryBo payQueryBo = new PayQueryBo();
if ("10000".equals(queryBo.getCode())){
payQueryBo.setOrderCode(queryBo.getOut_trade_no());
// 订单支付时的商户号
payQueryBo.setPayOrderCode(queryBo.getOut_trade_no());
payQueryBo.setTradeNo(queryBo.getTrade_no());
if ("TRADE_SUCCESS".equals(queryBo.getTrade_status())) {
... ... @@ -266,36 +267,6 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
private PayQueryBo queryOpenApiConvert(String orderCode, String respText) {
PayQueryBo queryBo = new PayQueryBo();
if(StringUtils.isEmpty(respText)) {
return queryBo;
}
JSONObject respJson = JSON.parseObject(respText);
JSONObject tradeJson = respJson.getJSONObject("alipay_trade_query_response");
if(tradeJson == null) {
logger.error("[{}] trade query failed", orderCode);
return queryBo;
}
if(!AlipayConfig.OPENAPI_BIZ_SUCCESS.equals(tradeJson.getString("code"))) {
logger.error("[{}] trade query failed: {}", orderCode, tradeJson.getString("sub_code"));
return queryBo;
}
if("TRADE_SUCCESS".equals(tradeJson.getString("trade_status"))) {
queryBo.setPayStatus(true);
queryBo.setOrderCode(tradeJson.getString("out_trade_no"));
queryBo.setAmount(tradeJson.getDoubleValue("total_amount"));
queryBo.setPayOrderCode(tradeJson.getString("out_trade_no"));
queryBo.setTradeNo(tradeJson.getString("trade_no"));
queryBo.setPaymentTime(tradeJson.getString("send_pay_date"));
queryBo.setCallbackTime(tradeJson.getString("send_pay_date"));
}
return queryBo;
}
/**
... ... @@ -452,6 +423,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
// 记录分期
recordOrdersPayHbfq(outTradeNo, tradeNo, uid);
tradeNo = outTradeNo;
}
... ...
... ... @@ -120,7 +120,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
if (index >= 0) {
out_trade_no = out_trade_no.substring(index + WeixinPayConfig.WECHAT_TRADE_NO_PREFIX.length());
}
queryBo.setOrderCode(out_trade_no);
// queryBo.setOrderCode(out_trade_no);
queryBo.setPayOrderCode(out_trade_no);
double total_fee = Double.valueOf(queryMap.get("total_fee"));
queryBo.setAmount(YHMath.mul(total_fee, 0.01));
... ...
... ... @@ -15,6 +15,7 @@ import com.yohoufo.order.model.response.PromotionFormula;
import com.yohoufo.order.model.response.RecommendedCouponInfo;
import com.yohoufo.order.utils.MathUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
... ... @@ -40,16 +41,32 @@ public class ShoppingSupport {
* 配送方式
* @return
*/
public PaymentResponse.DeliveryWay getDeliverWay(final ChargeResult chargeResult) {
public PaymentResponse.DeliveryWay getDeliverWay(final ChargeResult chargeResult, String appVersion) {
// 快递方式
PaymentResponse.DeliveryWay deliveryWay = new PaymentResponse.DeliveryWay();
deliveryWay.setDeliveryWayId(chargeResult.getDeliveryWay());
deliveryWay.setDeliveryWayCost(OrderConstant.MONEY_SIGN + chargeResult.getShippingAmount());
deliveryWay.setDeliveryWayCost(MathUtils.formatCurrencyStr(chargeResult.getShippingAmount()));
deliveryWay.setDeliveryWayName(getDeliveryWayStr(chargeResult.getDeliveryWay()));
return deliveryWay;
}
String buildDeliveryWayCost(String appVersion, double shippingAmount){
if (isLowerVersion(appVersion, "6.9.3")){
return "以实际提交订单金额为准";
}else{
String currencyAmount = MathUtils.formatCurrencyStr( shippingAmount );
return currencyAmount;
}
}
boolean isLowerVersion(String appVersion, String comparedVersion){
return StringUtils.isNotBlank(appVersion) && appVersion.compareTo(comparedVersion) < 0;
}
private String getDeliveryWayStr(int deliveryWay) {
return deliveryWay == OrderConstant.DELIVERY_WAY_STORE ? OrderConstant.DELIVERY_WAY_STORE_NAME : OrderConstant.DELIVERY_WAY_SF_NAME;
}
... ... @@ -97,7 +114,9 @@ public class ShoppingSupport {
//运费
PromotionFormula expressFormula = new PromotionFormula();
expressFormula.setPromotion(OrderConstant.DELIVERY_DESC);
expressFormula.setPromotionAmount(OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount()));
String shipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount());
expressFormula.setPromotionAmount(shipFee);
formulas.add(expressFormula);
... ...
package com.yohoufo.order.service.code;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.support.codegenerator.impl.OrderCodeGeneratorImpl;
public class CodeTest {
... ... @@ -8,12 +9,15 @@ public class CodeTest {
public static void main(String[] args){
com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator orderCodeGenerator = new OrderCodeGeneratorImpl();
//
// for (int i =0; i <10 ; i++){
// long result = orderCodeGenerator.generate(OrderCodeType.BUYER_TYPE);
// System.out.print(result);
// System.out.println(" 反解结果: "+ orderCodeGenerator.expId(result));
// }
for (int i =0; i <10 ; i++){
long result = orderCodeGenerator.generate(OrderCodeType.BUYER_TYPE);
System.out.print(result);
System.out.println(" 反解结果: "+ orderCodeGenerator.expId(result));
}
CodeMeta meta = orderCodeGenerator.expId(9926176890695l);
System.out.println(meta);
// System.out.println(1<<3);
... ...