Commit 081ee143 by ping.wu

代码优化

parent 3cff900e
......@@ -3,6 +3,8 @@ package cn.freemud.adapter;
import cn.freemud.base.util.DateUtil;
import cn.freemud.entities.Active;
import cn.freemud.entities.dto.delivery.WeixinDeliveryAddressDto;
import cn.freemud.entities.dto.order.FacePayResponseDto;
import cn.freemud.entities.dto.pay.PayOrderDto;
import cn.freemud.entities.dto.pay.PayProductDto;
import cn.freemud.entities.dto.pay.UnifiedOrderRequestDto;
import cn.freemud.entities.dto.product.pointsmall.IntegralProductType;
......@@ -10,6 +12,7 @@ import cn.freemud.entities.dto.product.pointsmall.PointMallListProductInfoReques
import cn.freemud.entities.dto.product.pointsmall.ProductStockRequest;
import cn.freemud.entities.dto.product.pointsmall.UpdatePointsMallStocksRequest;
import cn.freemud.entities.dto.user.UseScoreRequest;
import cn.freemud.entities.vo.CreateOrderResponseVo;
import com.alibaba.fastjson.JSONObject;
import com.freemud.api.assortment.datamanager.entity.vo.AssortmentCustomerInfoVo;
import com.freemud.application.sdk.api.log.LogThreadLocal;
......@@ -290,4 +293,20 @@ public class PointsMallOrderAdapter {
userScoreRequest.setAppId(appId);
return userScoreRequest;
}
public void convent2CreateOrderResponseVo(CreateOrderResponseVo createOrderResponseVo, String appId, FacePayResponseDto response){
createOrderResponseVo.setWxappId(appId);
createOrderResponseVo.setFmId(response.getFmId());
createOrderResponseVo.setPaySuccess(false);
String payOrderDto = response.getPayOrder();
PayOrderDto payOrder = JSONObject.parseObject(payOrderDto, PayOrderDto.class);
if (payOrder != null) {
createOrderResponseVo.setTimestamp(payOrder.getTimestamp());
createOrderResponseVo.setNonceStr(payOrder.getNonceStr());
createOrderResponseVo.setPackageX(payOrder.getPackageX());
createOrderResponseVo.setSignType(payOrder.getSignType());
createOrderResponseVo.setSign(payOrder.getPaySign());
createOrderResponseVo.setOrderStr(payOrder.getAliPayOrder());
}
}
}
......@@ -4,7 +4,7 @@ import lombok.Data;
@Data
public class StatislScoreResponse {
public class StatisticalScoreResponse {
// @ApiModelProperty("当前可用积分")
private Integer currentScore;
......
......@@ -11,11 +11,10 @@ import cn.freemud.entities.dto.BatchQueryActivityInfoRequestDto;
import cn.freemud.entities.dto.BatchQueryActivityInfoResponseDto;
import cn.freemud.entities.dto.delivery.WeixinDeliveryAddressDto;
import cn.freemud.entities.dto.order.FacePayResponseDto;
import cn.freemud.entities.dto.pay.PayOrderDto;
import cn.freemud.entities.dto.pay.UnifiedOrderRequestDto;
import cn.freemud.entities.dto.product.pointsmall.*;
import cn.freemud.entities.dto.user.CustomerPropertyBaseResponse;
import cn.freemud.entities.dto.user.StatislScoreResponse;
import cn.freemud.entities.dto.user.StatisticalScoreResponse;
import cn.freemud.entities.dto.user.StatisticalScoreRequestVo;
import cn.freemud.entities.dto.user.UseScoreRequest;
import cn.freemud.entities.vo.*;
......@@ -32,7 +31,6 @@ import cn.freemud.service.thirdparty.PointMallProductClient;
import cn.freemud.utils.AppLogUtil;
import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSONObject;
import com.freemud.api.assortment.datamanager.entity.db.AssortmentOpenPlatformIappWxappStore;
import com.freemud.api.assortment.datamanager.entity.db.AssortmentOpenPlatformPartnerConfig;
import com.freemud.api.assortment.datamanager.entity.vo.AssortmentCustomerInfoVo;
......@@ -92,7 +90,6 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
private AssortmentOpenPlatformPartnerConfigManager openPlatformPartnerConfigManager;
@Autowired
private AssortmentOpenPlatformIappWxappStoreManager assortmentOpenPlatformIappWxappStoreManager;
@Autowired
private PointsMallOrderAdapter pointsMallOrderAdapter;
......@@ -120,7 +117,7 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
}
//查询商品信息并且校验用户是否能购买 /product/listProductInfo 查询积分商品详情,可根据入参校验商品
PointMallListProductInfoRequest productInfoRequest = pointsMallOrderAdapter.convent2PointMallListProductInfoRequest(partnerId,memberId,skuId);
PointMallListProductInfoRequest productInfoRequest = pointsMallOrderAdapter.convent2PointMallListProductInfoRequest(partnerId, memberId, skuId);
PointMallListProductInfoResponse<List<IntegralProductType>> productInfosDto = pointMallProductClient.listProductInfo(productInfoRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS, productInfosDto.getStatusCode()) || CollectionUtils.isEmpty(productInfosDto.getResult())) {
return ResponseUtil.error(ResponseCodeConstant.RESPONSE_ERROR_STR, "商品异常");
......@@ -141,10 +138,10 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
}
String storeId = "99999";
AssortmentOpenPlatformIappWxappStore wxAppStore = getPointProductPayStoreInfo(appId);
if(wxAppStore == null && !ExchangeTypeEnum.TYPE_1.getCode().equals(exchangeType)){
if ((wxAppStore == null && !ExchangeTypeEnum.TYPE_1.getCode().equals(exchangeType))) {
return ResponseUtil.error(ResponseCodeConstant.RESPONSE_ERROR_STR, "支付门店未配置");
}
if(wxAppStore != null){
if (wxAppStore != null) {
storeId = wxAppStore.getStoreId();
}
Active active = null;
......@@ -166,12 +163,12 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
StatisticalScoreRequestVo statisticalScoreRequest = new StatisticalScoreRequestVo();
statisticalScoreRequest.setPartnerId(userLoginInfoDto.getPartnerId());
statisticalScoreRequest.setMemberId(userLoginInfoDto.getMemberId());
CustomerPropertyBaseResponse<StatislScoreResponse> statislScoreResponseBaseResponse = customerPropertyClient.statisticalScore(statisticalScoreRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, statislScoreResponseBaseResponse.getCode())) {
return ResponseUtil.error(statislScoreResponseBaseResponse.getCode(), "查询积分异常");
CustomerPropertyBaseResponse<StatisticalScoreResponse> statisticalScoreResponse = customerPropertyClient.statisticalScore(statisticalScoreRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, statisticalScoreResponse.getCode())) {
return ResponseUtil.error(statisticalScoreResponse.getCode(), "查询积分异常");
}
if (statislScoreResponseBaseResponse.getData() != null && statislScoreResponseBaseResponse.getData().getCurrentScore() < points) {
return ResponseUtil.error(statislScoreResponseBaseResponse.getCode(), "积分不足");
if (statisticalScoreResponse.getData() != null && statisticalScoreResponse.getData().getCurrentScore() < points) {
return ResponseUtil.error(statisticalScoreResponse.getCode(), "积分不足");
}
}
//创建订单
......@@ -185,12 +182,13 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
String orderCode = result.getOrderCode();
CreateOrderResponseVo createOrderResponseVo = new CreateOrderResponseVo();
createOrderResponseVo.setOid(orderCode);
//线上现金支付,创建预支付订单,唤起支付
com.freemud.application.sdk.api.base.BaseResponse<FacePayResponseDto> response = null;
if (!Objects.equals(ExchangeTypeEnum.TYPE_1.getCode(), exchangeType) && cashPrice != null && cashPrice > 0) {
Long payClientCode = Long.parseLong(wxAppStore.getClientCode());
UnifiedOrderRequestDto requestDto = pointsMallOrderAdapter.convert2UnifiedOrderRequestDto(result,openId,cashPrice,
payClientCode,reverseNotifyiDcUrl,getPartnerPayOvertime(partnerId));
UnifiedOrderRequestDto requestDto = pointsMallOrderAdapter.convert2UnifiedOrderRequestDto(result, openId, cashPrice,
payClientCode, reverseNotifyiDcUrl, getPartnerPayOvertime(partnerId));
response = paymentNewClient.unifiedOrder(requestDto);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, response.getCode())) {
return ResponseUtil.error(createOrderResponseDto.getCode(), "支付异常");
......@@ -198,59 +196,36 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS, response.getData().getResultCode())) {
return ResponseUtil.error(createOrderResponseDto.getCode(), "支付异常," + response.getData().getResultMsg());
}
createOrderResponseVo.setOid(orderCode);
createOrderResponseVo.setWxappId(result.getAppId());
createOrderResponseVo.setFmId(response.getData().getFmId());
createOrderResponseVo.setPaySuccess(false);
String payOrderDto = response.getData().getPayOrder();
PayOrderDto payOrder = JSONObject.parseObject(payOrderDto,PayOrderDto.class);
if(payOrder != null){
createOrderResponseVo.setTimestamp(payOrder.getTimestamp());
createOrderResponseVo.setNonceStr(payOrder.getNonceStr());
createOrderResponseVo.setPackageX(payOrder.getPackageX());
createOrderResponseVo.setSignType(payOrder.getSignType());
createOrderResponseVo.setSign(payOrder.getPaySign());
createOrderResponseVo.setOrderStr(payOrder.getAliPayOrder());
}
//唤起支付返回参数
pointsMallOrderAdapter.convent2CreateOrderResponseVo(createOrderResponseVo,appId,response.getData());
}
//保存支付信息
BaseResponse baseResponse1 = updateOrder(orderCode,points, cashPrice,partnerId,storeId,createOrderResponseVo.getFmId(),channel);
BaseResponse baseResponse1 = updateOrder(orderCode, points, cashPrice, partnerId, storeId, createOrderResponseVo.getFmId(), channel);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse1.getCode())) {
return ResponseUtil.error(createOrderResponseDto.getCode(), "更新订单异常");
}
//扣减积分商品商品库存
UpdatePointsMallStocksRequest updatePointsMallStocksRequest = pointsMallOrderAdapter.convent2UpdatePointsMallStocksRequest(partnerId,memberId,skuId,orderCode);
UpdatePointsMallStocksRequest updatePointsMallStocksRequest = pointsMallOrderAdapter.convent2UpdatePointsMallStocksRequest(partnerId, memberId, skuId, orderCode);
PointMallListProductInfoResponse pointMallListProductInfoResponse = pointMallProductClient.updateStock(updatePointsMallStocksRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS, pointMallListProductInfoResponse.getStatusCode())) {
return ResponseUtil.error(pointMallListProductInfoResponse.getStatusCode().toString(), "扣减库存失败");
}
//全积分支付商品,订单完成
if(ExchangeTypeEnum.TYPE_1.getCode().equals(exchangeType)){
//扣减积分 (失败:失败冲正活动库存)
if (points != null && points > 0 ) {
UseScoreRequest userScoreRequest = pointsMallOrderAdapter.convent2UseScoreRequest(partnerId, memberId, appId, orderCode,points);
CustomerPropertyBaseResponse baseResponse = customerPropertyClient.useScore(userScoreRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse.getCode())) {
createOrderFail(true, false, partnerId, memberId, orderCode, skuId, points, appId);
return ResponseUtil.error(baseResponse.getCode(), "扣减积分失败");
}
}
BaseResponse response1 = orderPaySuccess(createOrderResponseDto.getResult(),false);
if(!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, response1.getCode())){
if (ExchangeTypeEnum.TYPE_1.getCode().equals(exchangeType)) {
BaseResponse response1 = orderPaySuccess(createOrderResponseDto.getResult(), points,false);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, response1.getCode())) {
return response1;
}
createOrderResponseVo.setOid(orderCode);
}
return ResponseUtil.success(createOrderResponseVo);
}
private BaseResponse updateOrder(String orderCode,Integer integralPrice,Integer cashPrice,String partnerId,
String shopId,String fmId,String channel) {
private BaseResponse updateOrder(String orderCode, Integer integralPrice, Integer cashPrice, String partnerId,
String shopId, String fmId, String channel) {
BaseResponse response = new BaseResponse();
if(integralPrice > 0 || cashPrice > 0){
if (integralPrice > 0 || cashPrice > 0) {
List<PayItem> orderPayItemList = new ArrayList<>();
if(integralPrice > 0){
if (integralPrice > 0) {
PayItem payItem = new PayItem();
payItem.setPartnerId(partnerId);
payItem.setStoreId(shopId);
......@@ -259,17 +234,17 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
payItem.setPayAmount(new BigDecimal(integralPrice));
orderPayItemList.add(payItem);
}
if(cashPrice > 0){
if (cashPrice > 0) {
PayItem payItem = new PayItem();
payItem.setPartnerId(partnerId);
payItem.setStoreId(shopId);
if(ChannelEnum.TYPE_1.getCode().equals(channel)){
if (ChannelEnum.TYPE_1.getCode().equals(channel)) {
payItem.setPayChannelType(PayChannelType.WECHAT.getIndex().intValue());
payItem.setPayChannelName(PayChannelType.WECHAT.getName());
}else if(ChannelEnum.TYPE_5.getCode().equals(channel)){
} else if (ChannelEnum.TYPE_5.getCode().equals(channel)) {
payItem.setPayChannelType(PayChannelType.TIKTOKPAY.getIndex().intValue());
payItem.setPayChannelName(PayChannelType.TIKTOKPAY.getName());
}else {
} else {
payItem.setPayChannelType(PayChannelType.ALIPAY.getIndex().intValue());
payItem.setPayChannelName(PayChannelType.ALIPAY.getName());
}
......@@ -285,7 +260,7 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
// request.setPayChannelName(orderEdit.getPayChannelName());
// request.setPayChannelType(orderEdit.getPayChannelType());
com.freemud.application.sdk.api.ordercenter.response.BaseResponse baseResponse = orderSdkService.editOrder(request, LogThreadLocal.getTrackingNo());
if(baseResponse != null){
if (baseResponse != null) {
response.setCode(baseResponse.getCode());
response.setMessage(baseResponse.getMessage());
}
......@@ -295,7 +270,7 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
@Override
public String paySuccessCallback(PaysuccessNoticeMessage message,Map<String, OrderBeanV1> orderBeans) {
public String paySuccessCallback(PaysuccessNoticeMessage message, Map<String, OrderBeanV1> orderBeans) {
OrderBeanV1 orderBean = orderBeans.get(OrderBeanType.SAASORDER.getCode());
OrderInfoReqs orderInfo = new OrderInfoReqs();
orderInfo.setUserName(orderBean.getUserName());
......@@ -305,14 +280,14 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
orderInfo.setOrderPayItemCreateReqList(orderBean.getOrderPayItem());
orderInfo.setAppId(orderBean.getAppId());
List<OrderItemResp> orderItemList = new ArrayList<>();
for (ProductBeanV1 productBean : orderBean.getProductList()){
for (ProductBeanV1 productBean : orderBean.getProductList()) {
OrderItemResp orderItemResp = new OrderItemResp();
BeanUtil.convertBean(productBean,orderItemResp);
BeanUtil.convertBean(productBean, orderItemResp);
orderItemList.add(orderItemResp);
}
orderInfo.setOrderItemList(orderItemList);
BaseResponse baseResponse = orderPaySuccess(orderInfo,true);
if(!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse.getCode())){
BaseResponse baseResponse = orderPaySuccess(orderInfo, 0,true);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse.getCode())) {
return refundFaileMessage(baseResponse.getMessage());
}
return newSendPaySuccessNoticeMessage();
......@@ -500,16 +475,6 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
}
/**
* 获取商户支付超时时间
*
......@@ -527,39 +492,47 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
}
private Long getPayClientCode(String wxAppId, String storeId, String payCode,String orderClient){
//抖音支付的payCode = 10066
if (Objects.equals(OrderClientType.TIKTOKPAY.getIndex().toString(),orderClient)) {
payCode = PayChannelType.TIKTOKPAY.getEbcode();
}
AssortmentOpenPlatformIappWxappStore wxAppStore = assortmentOpenPlatformIappWxappStoreManager.selectWxappStoreByWxAppIdAndStoreId(wxAppId, storeId,payCode);
// payCode = wxAppStore != null && StringUtils.isNotBlank(wxAppStore.getPayCode())?wxAppStore.getPayCode():null;
String clientCode = wxAppStore != null && StringUtils.isNotBlank(wxAppStore.getClientCode()) ? wxAppStore.getClientCode() : "0";
return Long.parseLong(clientCode);
}
// private Long getPayClientCode(String wxAppId, String storeId, String payCode, String orderClient) {
// //抖音支付的payCode = 10066
// if (Objects.equals(OrderClientType.TIKTOKPAY.getIndex().toString(), orderClient)) {
// payCode = PayChannelType.TIKTOKPAY.getEbcode();
// }
// AssortmentOpenPlatformIappWxappStore wxAppStore = assortmentOpenPlatformIappWxappStoreManager.selectWxappStoreByWxAppIdAndStoreId(wxAppId, storeId, payCode);
// String clientCode = wxAppStore != null && StringUtils.isNotBlank(wxAppStore.getClientCode()) ? wxAppStore.getClientCode() : "0";
// return Long.parseLong(clientCode);
// }
private AssortmentOpenPlatformIappWxappStore getPointProductPayStoreInfo(String wxAppId){
/**
* 获取门店支付信息
*/
private AssortmentOpenPlatformIappWxappStore getPointProductPayStoreInfo(String wxAppId) {
AssortmentOpenPlatformIappWxappStore wxAppStore = assortmentOpenPlatformIappWxappStoreManager.selectIappWxappStoreByWxAppIdAndAggregationType(wxAppId, "9");
return wxAppStore;
}
//共用支付成功方法
private BaseResponse orderPaySuccess(OrderInfoReqs orderInfo,Boolean isCash){
String nickName= orderInfo.getUserName();
private BaseResponse orderPaySuccess(OrderInfoReqs orderInfo, Integer points,Boolean isCash) {
String nickName = orderInfo.getUserName();
String orderCode = orderInfo.getOrderCode();
String partnerId =orderInfo.getPartnerId();
String partnerId = orderInfo.getPartnerId();
String memberId = orderInfo.getUserId();
String skuId = orderInfo.getOrderItemList().get(0).getProductId();
boolean isCoupon = orderInfo.getOrderItemList().get(0).getProductType() == 1;
String appId =orderInfo.getAppId();
//订单完成 (失败:失败冲正活动库存)
String appId = orderInfo.getAppId();
//扣减积分 (失败:失败冲正活动库存)
if (!isCash && points != null && points > 0) {
UseScoreRequest userScoreRequest = pointsMallOrderAdapter.convent2UseScoreRequest(partnerId, memberId, appId, orderCode, points);
CustomerPropertyBaseResponse baseResponse = customerPropertyClient.useScore(userScoreRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse.getCode())) {
createOrderFail(true, false, partnerId, memberId, orderCode, skuId, points, appId);
return ResponseUtil.error(baseResponse.getCode(), "扣减积分失败");
}
}
//订单完成 (失败:失败冲正活动库存)
com.freemud.application.sdk.api.ordercenter.response.BaseResponse updateOrderStateResp = null;
if (isCoupon) {
OrderAffirmReq request = new OrderAffirmReq();
......@@ -578,14 +551,13 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
updateOrderStateResp = orderSdkService.paySuccess(request, LogThreadLocal.getTrackingNo());
}
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, updateOrderStateResp.getCode())) {
Integer points = orderInfo.getOrderPayItemCreateReqList().get(0).getPayAmount().intValue();
createOrderFail(false, true, partnerId, memberId, orderCode, skuId, points, appId);
return ResponseUtil.error(updateOrderStateResp.getCode(), "更新订单异常");
}
//有现金支付,扣减积分
if (isCash) {
Integer points = orderInfo.getOrderPayItemCreateReqList().get(0).getPayAmount().intValue();
UseScoreRequest userScoreRequest = pointsMallOrderAdapter.convent2UseScoreRequest(partnerId, memberId, appId, orderCode,points);
points = orderInfo.getOrderPayItemCreateReqList().get(0).getPayAmount().intValue();
UseScoreRequest userScoreRequest = pointsMallOrderAdapter.convent2UseScoreRequest(partnerId, memberId, appId, orderCode, points);
CustomerPropertyBaseResponse baseResponse = customerPropertyClient.useScore(userScoreRequest);
if (!Objects.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, baseResponse.getCode())) {
return ResponseUtil.error(baseResponse.getCode(), "扣减积分失败");
......
......@@ -19,6 +19,6 @@ public interface CustomerPropertyClient {
@LogIgnoreFeign(logMessage="statisticalScore")
@PostMapping({"/propertyservice/score/statisticalScore"})
CustomerPropertyBaseResponse<StatislScoreResponse> statisticalScore(StatisticalScoreRequestVo request);
CustomerPropertyBaseResponse<StatisticalScoreResponse> statisticalScore(StatisticalScoreRequestVo request);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment