|
|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.hisStore.service.impl;
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.hutool.core.net.URLDecoder;
|
|
|
@@ -11,6 +12,7 @@ import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.fs.api.param.OrderListParam;
|
|
|
import com.fs.api.vo.OrderListVO;
|
|
|
import com.fs.api.vo.ProductListVO;
|
|
|
@@ -25,8 +27,12 @@ import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.CloudHostUtils;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.IpUtil;
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
+import com.fs.common.utils.ip.IpUtils;
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyDept;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
@@ -37,6 +43,7 @@ import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.company.service.ICompanyDeptService;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.core.config.WxPayProperties;
|
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
|
@@ -64,6 +71,7 @@ import com.fs.his.vo.FsStoreOrderExcelVO;
|
|
|
import com.fs.his.vo.*;
|
|
|
import com.fs.his.vo.FsPrescribeVO;
|
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
|
+import com.fs.hisStore.constants.ErpTypeEnum;
|
|
|
import com.fs.hisStore.dto.*;
|
|
|
import com.fs.hisStore.mapper.*;
|
|
|
import com.fs.hisStore.param.*;
|
|
|
@@ -78,9 +86,12 @@ import com.fs.hisapi.domain.ApiResponse;
|
|
|
import com.fs.hisapi.param.CreateOrderParam;
|
|
|
import com.fs.hisapi.param.RecipeDetailParam;
|
|
|
import com.fs.hisapi.service.HisApiService;
|
|
|
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
+import com.fs.pay.pay.dto.OrderQueryDTO;
|
|
|
import com.fs.pay.pay.dto.RefundDTO;
|
|
|
import com.fs.pay.service.IPayService;
|
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
|
@@ -90,7 +101,10 @@ import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.enums.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
+import com.fs.ybPay.domain.OrderResult;
|
|
|
import com.fs.ybPay.domain.RefundResult;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
|
|
|
@@ -100,7 +114,10 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import lombok.Synchronized;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
|
+import org.apache.http.util.Asserts;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.aop.framework.AopContext;
|
|
|
@@ -146,6 +163,7 @@ import static com.fs.hisStore.constants.StoreConstants.DELIVERY;
|
|
|
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
|
|
|
@Slf4j
|
|
|
public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
+ private static final String STORE_PAY_CONF = "his.pay";
|
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
@Autowired
|
|
|
@@ -171,7 +189,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
private IFsUserBillScrmService billService;
|
|
|
|
|
|
@Autowired
|
|
|
- RedisCache redisCache;
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
|
@Autowired
|
|
|
private IFsStoreCartScrmService cartService;
|
|
|
@@ -202,13 +220,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Autowired
|
|
|
private ConfigUtil configUtil;
|
|
|
@Autowired
|
|
|
- IFsStorePaymentScrmService paymentService;
|
|
|
+ private IFsStorePaymentScrmService paymentService;
|
|
|
|
|
|
@Autowired
|
|
|
- IFsStoreProductPackageScrmService productPackageService;
|
|
|
+ private IFsStoreProductPackageScrmService productPackageService;
|
|
|
|
|
|
@Autowired
|
|
|
- ICompanyUserService companyUserService;
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
@Autowired
|
|
|
private IFsStoreProductAttrValueScrmService attrValueService;
|
|
|
@Autowired
|
|
|
@@ -237,15 +255,15 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
private FsStorePaymentScrmMapper fsStorePaymentMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- ICompanyDeptService companyDeptService;
|
|
|
+ private ICompanyDeptService companyDeptService;
|
|
|
@Autowired
|
|
|
- IFsPrescribeScrmService prescribeService;
|
|
|
+ private IFsPrescribeScrmService prescribeService;
|
|
|
|
|
|
@Autowired
|
|
|
- IPayService ybPayService;
|
|
|
+ private IPayService ybPayService;
|
|
|
|
|
|
@Autowired
|
|
|
- HuiFuService huiFuService;
|
|
|
+ private HuiFuService huiFuService;
|
|
|
@Autowired
|
|
|
private WxPayService wxPayService;
|
|
|
@Autowired
|
|
|
@@ -304,6 +322,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
|
|
|
@Autowired
|
|
|
private FsStoreProductAttrValueScrmMapper fsStoreProductAttrValueMapper;
|
|
|
+ @Autowired
|
|
|
+ private CloudHostProper cloudHostProper;
|
|
|
|
|
|
@Autowired
|
|
|
//fsStoreMapper
|
|
|
@@ -327,6 +347,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Autowired
|
|
|
private FsPackageOrderMapper fsPackageOrderMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxMaProperties properties;
|
|
|
+
|
|
|
//ERP 类型到服务的映射
|
|
|
private Map<Integer, IErpOrderService> erpServiceMap;
|
|
|
@PostConstruct
|
|
|
@@ -591,10 +614,16 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
BigDecimal payPrice = getOrderSumPrice(carts, "truePrice");
|
|
|
if (StringUtils.isNotEmpty(param.getCreateOrderKey())) {
|
|
|
- BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
- if (money != null) {
|
|
|
- payPrice = money;
|
|
|
+ Integer payType = redisCache.getCacheObject("createOrderPayType:" + param.getCreateOrderKey());
|
|
|
+ if (payType != null && payType == 3) {
|
|
|
+ payPrice = redisCache.getCacheObject("createOrderAmount:" + param.getCreateOrderKey());
|
|
|
+ } else {
|
|
|
+ BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
+ if (money != null) {
|
|
|
+ payPrice = money;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
BigDecimal serviceFee = BigDecimal.ZERO;
|
|
|
String configJson = configService.selectConfigByKey("store.config");
|
|
|
@@ -682,6 +711,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
//计算金额
|
|
|
FsStoreOrderComputeDTO dto = this.computedOrder(userId, computedParam);
|
|
|
String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
+ Integer payType = redisCache.getCacheObject("createOrderPayType:" + param.getCreateOrderKey());
|
|
|
+ if (payType != null) {
|
|
|
+ param.setPayType(payType.toString());
|
|
|
+ }
|
|
|
// Integer totalNum = 0;
|
|
|
BigDecimal integral = BigDecimal.ZERO;
|
|
|
if (cartIds != null) {
|
|
|
@@ -2113,7 +2146,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if(ObjectUtils.equals(order.getStatus(),2)){
|
|
|
FsStoreAfterSalesParam fsStoreAfterSalesParam = new FsStoreAfterSalesParam();
|
|
|
fsStoreAfterSalesParam.setOrderCode(order.getOrderCode());
|
|
|
- fsStoreAfterSalesParam.setRefundAmount(order.getRefundMoney());
|
|
|
+ fsStoreAfterSalesParam.setRefundAmount(order.getPayMoney());
|
|
|
fsStoreAfterSalesParam.setServiceType(1);
|
|
|
fsStoreAfterSalesParam.setReasons("后台手动退款流程");
|
|
|
fsStoreAfterSalesParam.setExplainImg(null);
|
|
|
@@ -2187,9 +2220,25 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
|
}
|
|
|
} else if (payment.getPayMode() != null && payment.getPayMode().equals("hf")) {
|
|
|
+ String huifuId="";
|
|
|
+ FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
+ if (payment.getAppId() != null) {
|
|
|
+ FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
+ huifuId = fsHfpayConfig.getHuifuId();
|
|
|
+ } else {
|
|
|
+ if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
|
|
|
+
|
|
|
+ FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
+ huifuId = fsPayConfig2.getHuifuId();
|
|
|
+ }else {
|
|
|
+ huifuId=fsPayConfig.getHuifuId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
request.setOrgHfSeqId(payment.getTradeNo());
|
|
|
- request.setHuifuId(fsPayConfig.getHuifuId());
|
|
|
+ request.setHuifuId(huifuId);
|
|
|
request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
|
@@ -2248,7 +2297,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
ErpOrderQueryRequert request = new ErpOrderQueryRequert();
|
|
|
request.setCode(order.getExtendOrderId());
|
|
|
- ErpOrderQueryResponse response = erpOrderService.getOrder(request);
|
|
|
+ ErpOrderQueryResponse response = erpOrderService.getScrmOrder(request);
|
|
|
if (response.getOrders() != null && response.getOrders().size() > 0) {
|
|
|
for (ErpOrderQuery orderQuery : response.getOrders()) {
|
|
|
if (orderQuery.getDeliverys() != null && orderQuery.getDeliverys().size() > 0) {
|
|
|
@@ -2354,10 +2403,15 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
String key = redisCache.getCacheObject("createOrderKey:" + createOrderKey);
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + createOrderKey);
|
|
|
+ Integer payType = redisCache.getCacheObject("createOrderPayType:" + createOrderKey);
|
|
|
+ //展示代收金额
|
|
|
+ if (payType != null && payType == 3) {
|
|
|
+ money = redisCache.getCacheObject("createOrderAmount:" + createOrderKey);
|
|
|
+ }
|
|
|
if (StringUtils.isEmpty(key)) {
|
|
|
throw new CustomException("订单已过期", 501);
|
|
|
}
|
|
|
- return R.ok().put("carts", carts).put("totalMoney", money);
|
|
|
+ return R.ok().put("carts", carts).put("totalMoney", money).put("payType", payType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -2393,7 +2447,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount) {
|
|
|
+ public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount,Integer payType) {
|
|
|
//货到付款自定义金额
|
|
|
if (payAmount == null) {
|
|
|
String configJson = configService.selectConfigByKey("store.config");
|
|
|
@@ -2433,6 +2487,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
redisCache.setCacheObject("createOrderMoney:" + createOrderKey, money, 24, TimeUnit.HOURS);
|
|
|
redisCache.setCacheObject("createOrderAmount:" + createOrderKey, payAmount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
+ redisCache.setCacheObject("createOrderPayType:" + createOrderKey, payType, 24, TimeUnit.HOURS);//支付类型 1-全付款 3-物流代收(货到付款)
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
@@ -3004,6 +3059,20 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return fsStoreOrderMapper.selectFsStoreOrderStatisticsByUserId(fsUserIdList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前ERP类型
|
|
|
+ * @return ERP类型
|
|
|
+ */
|
|
|
+ public ErpTypeEnum getErpType(){
|
|
|
+ FsSysConfig erpConfig = configUtil.getSysConfig();
|
|
|
+ Integer erpType = erpConfig.getErpType();
|
|
|
+ ErpTypeEnum byCode = ErpTypeEnum.getByCode(erpType);
|
|
|
+ Asserts.notNull(byCode,String.format("当前ERP 类型: %d 未找到!",erpType));
|
|
|
+ return byCode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private IErpOrderService getErpService() {
|
|
|
//判断是否开启erp
|
|
|
IErpOrderService erpOrderService = null;
|
|
|
@@ -3756,6 +3825,552 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R pay(FsStoreOrderPayParam param) {
|
|
|
+ FsStoreOrderScrm order=this.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
|
|
|
+ return R.error("订单状态不正确");
|
|
|
+ }
|
|
|
+ String orderId=redisCache.getCacheObject("isPaying:"+param.getOrderId());
|
|
|
+ if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+
|
|
|
+ FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
+ if(user!=null){
|
|
|
+ //已改价处理
|
|
|
+ if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
+ //改过价不做处理
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ String config=configService.selectConfigByKey("his.store");
|
|
|
+ com.fs.store.config.StoreConfig storeConfig= JSONUtil.toBean(config, com.fs.store.config.StoreConfig.class);
|
|
|
+ if(param.getPayType().equals(1)){
|
|
|
+ order.setPayType("1");
|
|
|
+ order.setPayMoney(order.getPayPrice());
|
|
|
+ order.setPayDelivery(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ else if(param.getPayType().equals(2)){
|
|
|
+ order.setPayType("2");
|
|
|
+ BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
+ payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
+ }
|
|
|
+ else if(param.getPayType().equals(3)){
|
|
|
+ //货到付款
|
|
|
+ order.setPayType("3");
|
|
|
+ BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getId());
|
|
|
+ BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
+ if (amount != null){
|
|
|
+ payMoney=amount;
|
|
|
+ }
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
+ }
|
|
|
+ this.updateFsStoreOrder(order);
|
|
|
+ }
|
|
|
+ String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+ if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
+ String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(2);
|
|
|
+ storePayment.setRemark("商城订单支付");
|
|
|
+ storePayment.setOpenId(user.getRealName());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+
|
|
|
+ if (fsPayConfig.getType().equals("hf")){
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("商城订单支付");
|
|
|
+ o.setAppId(param.getAppId());
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+ FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ mt.setAppId(param.getAppId());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
+ redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+ String s = (String) resultMap.get("package");
|
|
|
+ resultMap.put("packageValue",s);
|
|
|
+ return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error(result.getResp_desc());
|
|
|
+ }
|
|
|
+ }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setBody("商城订单支付");
|
|
|
+ orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+ try {
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType",param.getPayType());
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
+ //货到付款
|
|
|
+ IFsStoreOrderScrmService fsStoreOrderScrmService = (IFsStoreOrderScrmService) AopContext.currentProxy();
|
|
|
+ fsStoreOrderScrmService.payConfirm(2,order.getId(),null,null,null,null);
|
|
|
+ return R.ok().put("payType",param.getPayType());
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cancelPay(FsStoreOrderPayParam param) {
|
|
|
+ redisCache.deleteObject("isPaying:"+param.getOrderId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R otherPaymentRemain(FsStoreOrderOtherPayParam param) {
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(properties.getConfigs().get(0).getAppid());
|
|
|
+ try {
|
|
|
+ String ip = IpUtil.getRequestIp();
|
|
|
+ WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
|
|
|
+ FsUserScrm user=userService.selectFsUserByMaOpenId(session.getOpenid());
|
|
|
+ if(user==null){
|
|
|
+ //创建
|
|
|
+ user=new FsUserScrm();
|
|
|
+ user.setUsername("");
|
|
|
+ user.setNickname("微信用户");
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setMaOpenId(session.getOpenid());
|
|
|
+ user.setUnionId(session.getUnionid());
|
|
|
+ user.setIsWeixinAuth(0);
|
|
|
+ user.setLastIp(ip);
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ userService.insertFsUser(user);
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm order=this.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(order.getStatus()!= OrderInfoEnum.STATUS_2.getValue()){
|
|
|
+ return R.error("待收货订单可申请支付尾款");
|
|
|
+ }
|
|
|
+ if(order.getPayType().equals(1)){
|
|
|
+ return R.error("此订单已支付");
|
|
|
+ }
|
|
|
+ //只有顺风才可以付尾
|
|
|
+ if(!order.getDeliverySn().trim().equals("SF")){
|
|
|
+ return R.error("只有顺丰物流支持尾款支付");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!order.getIsPayRemain().equals(0)){
|
|
|
+ return R.error("此订单已支付");
|
|
|
+ }
|
|
|
+ String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+ String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(order.getPayDelivery());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(2);
|
|
|
+ storePayment.setRemark("商城订单尾款支付");
|
|
|
+ storePayment.setOpenId(user.getRealName());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ storePayment.setIsPayRemain(1);
|
|
|
+ fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+
|
|
|
+ if (fsPayConfig.getType().equals("hf")){
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("商城订单支付");
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+
|
|
|
+ FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
+ redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+ String s = (String) resultMap.get("package");
|
|
|
+ resultMap.put("packageValue",s);
|
|
|
+ return R.ok().put("result",resultMap);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error(result.getResp_desc());
|
|
|
+ }
|
|
|
+ }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+ //创建微信订单
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setBody("商城订单支付");
|
|
|
+ orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+ //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+ try {
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return R.error("无支付类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R otherPayment(FsStoreOrderOtherPayParam param) {
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(properties.getConfigs().get(0).getAppid());
|
|
|
+ try {
|
|
|
+ String ip = IpUtil.getRequestIp();
|
|
|
+ WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
|
|
|
+ FsUserScrm user=userService.selectFsUserByMaOpenId(session.getOpenid());
|
|
|
+ if(user==null){
|
|
|
+ //创建
|
|
|
+ user=new FsUserScrm();
|
|
|
+ user.setUsername("");
|
|
|
+ user.setNickname("微信用户");
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setMaOpenId(session.getOpenid());
|
|
|
+ user.setUnionId(session.getUnionid());
|
|
|
+ user.setIsWeixinAuth(0);
|
|
|
+ user.setLastIp(ip);
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ userService.insertFsUser(user);
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm order=selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(!Objects.equals(order.getStatus(), OrderInfoEnum.STATUS_0.getValue())){
|
|
|
+ return R.error("此订单不能支付");
|
|
|
+ }
|
|
|
+ if(order.getPayMoney().compareTo(new BigDecimal(0))<1){
|
|
|
+ return R.error("此订单没有可支付的金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderId=redisCache.getCacheObject("isPaying:"+order.getId());
|
|
|
+ if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+ //易宝支付
|
|
|
+ FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(2);
|
|
|
+ storePayment.setRemark("商城订单支付");
|
|
|
+ storePayment.setOpenId(session.getOpenid());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+
|
|
|
+ if (fsPayConfig.getType().equals("hf")){
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("商城订单支付");
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+
|
|
|
+ FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
+ redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+ String s = (String) resultMap.get("package");
|
|
|
+ resultMap.put("packageValue",s);
|
|
|
+ return R.ok().put("result",resultMap);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error(result.getResp_desc());
|
|
|
+ }
|
|
|
+ }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+ //创建微信订单
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setBody("商城订单支付");
|
|
|
+ orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+ try {
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return R.error("无支付类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R payRemain(FsStoreOrderPayParam param) {
|
|
|
+ FsStoreOrderScrm order=selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(order.getStatus()!= OrderInfoEnum.STATUS_2.getValue()){
|
|
|
+ return R.error("待收货订单可申请支付尾款");
|
|
|
+ }
|
|
|
+ if(order.getPayType().equals(1)){
|
|
|
+ return R.error("此订单已支付");
|
|
|
+ }
|
|
|
+ //只有顺风才可以付尾
|
|
|
+ if(!order.getDeliverySn().trim().equals("SF")){
|
|
|
+ return R.error("只有顺丰物流支持尾款支付");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!order.getIsPayRemain().equals(0)){
|
|
|
+ return R.error("此订单已支付");
|
|
|
+ }
|
|
|
+ FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
+ if(user!=null){
|
|
|
+ String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+ String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(order.getPayDelivery());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(2);
|
|
|
+ storePayment.setRemark("商城订单尾款支付");
|
|
|
+ storePayment.setOpenId(user.getRealName());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ storePayment.setIsPayRemain(1);
|
|
|
+ fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+
|
|
|
+ if (fsPayConfig.getType().equals("hf")){
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("store_remain-"+storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("商城订单尾款支付");
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ //创建订单
|
|
|
+ if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+
|
|
|
+ FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
+ redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+ String s = (String) resultMap.get("package");
|
|
|
+ resultMap.put("packageValue",s);
|
|
|
+ return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error(result.getResp_desc());
|
|
|
+ }
|
|
|
+ }else if(fsPayConfig.getType().equals("wx")) {
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setBody("商城订单支付");
|
|
|
+ orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+ //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+ try {
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
+ }
|
|
|
+ return R.error("无支付类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R editPayType(FsStoreOrderPayParam param) {
|
|
|
+ FsStoreOrderScrm order=this.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(!Objects.equals(order.getStatus(), OrderInfoEnum.STATUS_0.getValue())){
|
|
|
+ return R.error("订单状态不正确");
|
|
|
+ }
|
|
|
+ String orderId=redisCache.getCacheObject("isPaying:"+order.getId());
|
|
|
+ if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+ List<FsStorePaymentScrm> payments=fsStorePaymentMapper.selectFsStorePaymentByOrder(order.getId());
|
|
|
+ if(CollectionUtils.isNotEmpty(payments)){
|
|
|
+ for(FsStorePaymentScrm payment : payments){
|
|
|
+ OrderQueryDTO orderQueryDTO = new OrderQueryDTO();
|
|
|
+ orderQueryDTO.setLowOrderId("store-"+payment.getPayCode());
|
|
|
+ OrderResult orderResult = ybPayService.getOrder(orderQueryDTO);
|
|
|
+ if(orderResult.getStatus()!= null&&orderResult.getStatus().equals("100")){
|
|
|
+ if(orderResult.getState()!=null&&orderResult.getState().equals("0")){
|
|
|
+ return R.error("订单已支付");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
+ if(user!=null){
|
|
|
+ //已改价处理
|
|
|
+ if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
+ //改过价不做处理
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ String config=configService.selectConfigByKey("his.store");
|
|
|
+ com.fs.store.config.StoreConfig storeConfig= JSONUtil.toBean(config, com.fs.store.config.StoreConfig.class);
|
|
|
+ if(param.getPayType().equals(1)){
|
|
|
+ order.setPayType("1");
|
|
|
+ order.setPayMoney(order.getPayPrice());
|
|
|
+ order.setPayDelivery(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ else if(param.getPayType().equals(2)){
|
|
|
+
|
|
|
+ order.setPayType("2");
|
|
|
+ BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
+ payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
+ }
|
|
|
+ else if(param.getPayType().equals(3)){
|
|
|
+ //货到付款
|
|
|
+ order.setPayType("3");
|
|
|
+ BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getId());
|
|
|
+ BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
+ if (amount != null){
|
|
|
+ payMoney=amount;
|
|
|
+ }
|
|
|
+ order.setPayMoney(payMoney);
|
|
|
+ order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
+ }
|
|
|
+ IFsStoreOrderScrmService fsStoreOrderScrmService = (IFsStoreOrderScrmService) AopContext.currentProxy();
|
|
|
+ fsStoreOrderScrmService.updateFsStoreOrder(order);
|
|
|
+ }
|
|
|
+ return R.ok().put("order",order);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<FsStoreOrderVO> selectFsStoreOrderListVOByErpAccount(FsStoreOrderParam param) {
|
|
|
List<FsStoreOrderVO> list = fsStoreOrderMapper.selectFsStoreOrderListVOByErpAccount(param);
|