|
@@ -2,6 +2,7 @@ package com.fs.his.service.impl;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
@@ -9,10 +10,12 @@ import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -49,10 +52,17 @@ import com.fs.his.vo.FsPackageOrderExcelVO;
|
|
|
import com.fs.his.vo.FsPackageOrderListUVO;
|
|
import com.fs.his.vo.FsPackageOrderListUVO;
|
|
|
import com.fs.his.vo.FsPackageOrderListVO;
|
|
import com.fs.his.vo.FsPackageOrderListVO;
|
|
|
import com.fs.his.vo.FsPackageOrderVO;
|
|
import com.fs.his.vo.FsPackageOrderVO;
|
|
|
|
|
+import com.fs.hisStore.domain.FsPayConfigScrm;
|
|
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
|
|
+import com.fs.hisStore.domain.FsStorePaymentScrm;
|
|
|
|
|
+import com.fs.hisStore.enums.OrderInfoEnum;
|
|
|
|
|
+import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
|
|
|
|
|
+import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
|
|
import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
|
|
+import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
import com.fs.system.oss.OSSFactory;
|
|
@@ -168,6 +178,14 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CloudHostProper cloudHostProper;
|
|
private CloudHostProper cloudHostProper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStoreOrderScrmService orderService;
|
|
|
|
|
+
|
|
|
|
|
+ private static final String STORE_PAY_CONF = "his.pay";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStorePaymentScrmMapper fsStorePaymentScrmMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询套餐订单
|
|
* 查询套餐订单
|
|
|
*
|
|
*
|
|
@@ -1830,4 +1848,225 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
}
|
|
}
|
|
|
return R.ok().put("package", fsPackage).put("money", money).put("payType", payType);
|
|
return R.ok().put("package", fsPackage).put("money", money).put("payType", payType);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public R aliPaymentCombinationId(FsPackageOrderDoPayParam param) {
|
|
|
|
|
+ FsStoreOrderScrm fsStoreOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ BigDecimal payPrice = BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal payMoneyTotal = BigDecimal.ZERO;
|
|
|
|
|
+ FsUser fsUser = new FsUser();
|
|
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
|
|
+ List<FsStoreOrderScrm> orders = orderService.getStoreOrderByCombinationId(param.getCombinationOrderId());
|
|
|
|
|
+// //更新订单状态
|
|
|
|
|
+// FsPackageOrder fsPackageOrder=fsPackageOrderMapper.selectFsPackageOrderByOrderId(param.getOrderId());
|
|
|
|
|
+// if(!fsPackageOrder.getStatus().equals(FsPackageOrderStatusEnum.STATUS_1.getValue())){
|
|
|
|
|
+// return R.error("非法操作");
|
|
|
|
|
+// }
|
|
|
|
|
+ String errorMsg = checkPrescriptionOrders(orders);
|
|
|
|
|
+ if (errorMsg != null) {
|
|
|
|
|
+ return R.error(errorMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
|
|
+ PayConfigDTO payConfigDTO = JSONUtil.toBean(json, PayConfigDTO.class);
|
|
|
|
|
+ String openId = null;
|
|
|
|
|
+ String appId = param.getAppId();
|
|
|
|
|
+ ArrayList<Long> paymentIds = new ArrayList<>();
|
|
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ return R.error("订单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getStatus() != OrderInfoEnum.STATUS_0.getValue()) {
|
|
|
|
|
+ return R.error("订单状态不正确");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsUser user = userService.selectFsUserById(order.getUserId());
|
|
|
|
|
+ fsUser = user;
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(appId)) {
|
|
|
|
|
+ //查询fs_user_wx的openId
|
|
|
|
|
+ Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
|
|
|
|
|
+ .eq(FsUserWx::getFsUserId, param.getUserId())
|
|
|
|
|
+ .eq(FsUserWx::getAppId, appId);
|
|
|
|
|
+ FsUserWx fsUserWx = fsUserWxMapper.selectOne(queryWrapper);
|
|
|
|
|
+ if (fsUserWx != null) {
|
|
|
|
|
+ openId = fsUserWx.getOpenId();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ appId = payConfigDTO.getAppId();
|
|
|
|
|
+ openId = Objects.isNull(user) ? "" : user.getMaOpenId();
|
|
|
|
|
+ if (StringUtils.isBlank(openId)){
|
|
|
|
|
+ Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
|
|
|
|
|
+ .eq(FsUserWx::getFsUserId, param.getUserId())
|
|
|
|
|
+ .eq(FsUserWx::getAppId, appId);
|
|
|
|
|
+ FsUserWx fsUserWx = fsUserWxMapper.selectOne(queryWrapper);
|
|
|
|
|
+ if (Objects.nonNull(fsUserWx)){
|
|
|
|
|
+ openId = fsUserWx.getOpenId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ payPrice = NumberUtil.add(payPrice, order.getPayPrice());
|
|
|
|
|
+ if (user != null && StringUtils.isNotEmpty(user.getMaOpenId())) {
|
|
|
|
|
+ //已改价处理
|
|
|
|
|
+ if (order.getIsEditMoney() != null && order.getIsEditMoney() == 1) {
|
|
|
|
|
+ //改过价不做处理
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String config = configService.selectConfigByKey("store.config");
|
|
|
|
|
+ StoreConfig storeConfig = JSONUtil.toBean(config, StoreConfig.class);
|
|
|
|
|
+ if (param.getPayType().equals(1)) {
|
|
|
|
|
+ order.setPayType("1");
|
|
|
|
|
+ order.setPayMoney(order.getPayPrice());
|
|
|
|
|
+ order.setPayDelivery(BigDecimal.ZERO);
|
|
|
|
|
+ payMoneyTotal = NumberUtil.add(payMoneyTotal, order.getPayPrice());
|
|
|
|
|
+ } 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);
|
|
|
|
|
+
|
|
|
|
|
+ payMoneyTotal = NumberUtil.add(payMoneyTotal, payMoney);
|
|
|
|
|
+
|
|
|
|
|
+ } else if (param.getPayType().equals(3)) {
|
|
|
|
|
+ //货到付款
|
|
|
|
|
+ order.setPayType("3");
|
|
|
|
|
+ order.setPayDelivery(order.getPayPrice());
|
|
|
|
|
+ order.setPayMoney(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+ orderService.updateFsStoreOrder(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (order.getPayType().equals("1") || order.getPayType().equals("2")) {
|
|
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
|
|
+ String paySubCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
|
|
+ FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
|
|
+ storePayment.setStatus(0);
|
|
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
|
|
+ storePayment.setPaySubCode(paySubCode);
|
|
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
|
|
+ storePayment.setPayTypeCode("alipay");
|
|
|
|
|
+ storePayment.setBusinessType(3);
|
|
|
|
|
+ storePayment.setRemark("商城订单支付");
|
|
|
|
|
+ storePayment.setOpenId(order.getRealName());
|
|
|
|
|
+ storePayment.setUserId(fsUser.getUserId());
|
|
|
|
|
+ //换成唯一标识
|
|
|
|
|
+// storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
|
|
+ storePayment.setBusinessOrderId(order.getCombinationOrderId());
|
|
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
|
|
+ fsStorePaymentScrmMapper.insertFsStorePayment(storePayment);
|
|
|
|
|
+ paymentIds.add(storePayment.getPaymentId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ fsStoreOrder.setPayType(orders.get(0).getPayType());
|
|
|
|
|
+ fsStoreOrder.setCompanyId(orders.get(0).getCompanyId());
|
|
|
|
|
+ fsStoreOrder.setCompanyUserId(orders.get(0).getCompanyUserId());
|
|
|
|
|
+ fsStoreOrder.setPayMoney(payMoneyTotal);
|
|
|
|
|
+ fsStoreOrder.setRealName(orders.get(0).getRealName());
|
|
|
|
|
+ fsStoreOrder.setCombinationOrderId(orders.get(0).getCombinationOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ if(fsStoreOrder.getPayMoney().compareTo(new BigDecimal(0))==1){
|
|
|
|
|
+ if(StringUtils.isEmpty(payCode)){
|
|
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
|
|
|
+ storePayment.setCompanyId(fsStoreOrder.getCompanyId());
|
|
|
|
|
+ storePayment.setCompanyUserId(fsStoreOrder.getCompanyUserId());
|
|
|
|
|
+ storePayment.setStatus(0);
|
|
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
|
|
+ storePayment.setPayMoney(fsStoreOrder.getPayMoney());
|
|
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
|
|
+ storePayment.setPayTypeCode("alipay");
|
|
|
|
|
+ storePayment.setBusinessType(3);
|
|
|
|
|
+ storePayment.setRemark("商城订单支付");
|
|
|
|
|
+ storePayment.setOpenId(fsStoreOrder.getRealName());
|
|
|
|
|
+ storePayment.setUserId(fsUser.getUserId());
|
|
|
|
|
+
|
|
|
|
|
+ if (payConfigDTO.getType().equals("yb")) {
|
|
|
|
|
+ return R.error("支付暂不可用!");
|
|
|
|
|
+ } else if (payConfigDTO.getType().equals("tz")) {
|
|
|
|
|
+ PayCreateOrder o = new PayCreateOrder();
|
|
|
|
|
+ o.setOrderNo("package" + storePayment.getPayCode()); // 业务系统订单号
|
|
|
|
|
+ o.setTrxAmt(storePayment.getPayMoney().doubleValue()); // 交易金额
|
|
|
|
|
+ o.setBusinessCstNo(fsStoreOrder.getUserId().toString()); // 业务平台客户号
|
|
|
|
|
+ String phone="";
|
|
|
|
|
+ if (fsUser.getPhone()!=null&&fsUser.getPhone().length()>4){
|
|
|
|
|
+ phone=fsUser.getPhone().substring(fsUser.getPhone().length()-4);
|
|
|
|
|
+ }
|
|
|
|
|
+ o.setPayerName("微信用户"+phone);
|
|
|
|
|
+ o.setGoodsInfo("套餐包订单支付"); // 订单信息
|
|
|
|
|
+// o.setOpenId(user.getMpOpenId());
|
|
|
|
|
+ o.setOrderType(3);
|
|
|
|
|
+ o.setOrderId(fsStoreOrder.getId().toString());
|
|
|
|
|
+ o.setPayType(Arrays.asList(PayType.ALIPAY_BARCODE_PAYMENT.getCode()));
|
|
|
|
|
+ TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(o);
|
|
|
|
|
+ FsStorePayment mt=new FsStorePayment();
|
|
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
|
|
+ mt.setTradeNo(result.getBody().getOrderFlowNo());
|
|
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "tz");
|
|
|
|
|
+ }else if (payConfigDTO.getType().equals("hf")) {
|
|
|
|
|
+ logger.info("创建汇付订单");
|
|
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
|
|
+ o.setTradeType("A_NATIVE");
|
|
|
|
|
+ o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
|
|
+ o.setGoodsDesc("套餐包订单支付");
|
|
|
|
|
+ o.setAppId(appId);
|
|
|
|
|
+ o.setOpenid(openId);
|
|
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("创建汇付支付:"+result);
|
|
|
|
|
+ //创建订单
|
|
|
|
|
+ if (result.getBank_code() != null && result.getBank_code().equals("00000000")) {
|
|
|
|
|
+ for (Long paymentId : paymentIds) {
|
|
|
|
|
+ FsStorePayment mt = new FsStorePayment();
|
|
|
|
|
+ mt.setPaymentId(paymentId);
|
|
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
|
|
+ mt.setAppId(appId);
|
|
|
|
|
+ storePaymentService.updateFsStorePayment(mt);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else{
|
|
|
|
|
+ this.payConfirm(fsStoreOrder.getOrderCode(),"","","",2,null,null);
|
|
|
|
|
+ return R.ok().put("isPay",1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.error();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String checkPrescriptionOrders(List<FsStoreOrderScrm> orders) {
|
|
|
|
|
+ if (orders == null || orders.isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> orderIds = orders.stream()
|
|
|
|
|
+ .map(FsStoreOrderScrm::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+// for (FsStoreOrderScrm order : orders) {
|
|
|
|
|
+// if (order.getIsPrescribe() == 1 && order.getPrescribeId() == null) {
|
|
|
|
|
+// return "处方订单未开具,无法支付!";
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, Long> prescriptionCountMap = orderService.batchGetPrescriptionDrugCount(orderIds);
|
|
|
|
|
+ if(prescriptionCountMap != null){
|
|
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
|
|
+ if (prescriptionCountMap.containsKey(BigInteger.valueOf(order.getId()))) {
|
|
|
|
|
+ return "处方订单不是已审核状态,无法支付!";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|