|
|
@@ -1,33 +1,85 @@
|
|
|
package com.fs.hisStore.service.impl;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alipay.api.AlipayClient;
|
|
|
+import com.alipay.api.DefaultAlipayClient;
|
|
|
+import com.alipay.api.diagnosis.DiagnosisUtils;
|
|
|
+import com.alipay.api.domain.AlipayTradeAppPayModel;
|
|
|
+import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
+import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
-import com.fs.common.utils.SnowflakeUtil;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
+import com.fs.common.utils.ip.IpUtils;
|
|
|
+import com.fs.core.config.WxPayProperties;
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
+import com.fs.his.domain.FsPayConfig;
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.domain.MerchantAppConfig;
|
|
|
+import com.fs.his.domain.FsUserWx;
|
|
|
+import com.fs.his.param.FsIntegralOrderDoPayParam;
|
|
|
+import com.fs.his.mapper.FsUserWxMapper;
|
|
|
+import com.fs.his.mapper.MerchantAppConfigMapper;
|
|
|
+import com.fs.his.service.IFsUserService;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.his.utils.qrcode.QRCodeUtils;
|
|
|
-import com.fs.hisStore.domain.FsStoreOrderPickItem;
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderItemScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderPick;
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
+import com.fs.hisStore.domain.FsStorePaymentScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.domain.FsUserAddressScrm;
|
|
|
import com.fs.hisStore.domain.FsUserScrm;
|
|
|
-import com.fs.hisStore.mapper.FsStoreOrderPickItemMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderPickMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsUserAddressScrmMapper;
|
|
|
+import com.fs.hisStore.param.FsStoreOrderPickAddParam;
|
|
|
+import com.fs.hisStore.param.FsStoreOrderPickComputeParam;
|
|
|
+import com.fs.hisStore.param.FsStoreOrderPickPayParam;
|
|
|
+import com.fs.hisStore.param.FsStoreOrderPickPaymentParam;
|
|
|
+import com.fs.hisStore.service.IFsStoreOrderPickService;
|
|
|
+import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
import com.fs.hisStore.service.IFsUserScrmService;
|
|
|
+import com.fs.hisStore.vo.FSUserVO;
|
|
|
+import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
+import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
|
|
|
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
+import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
-import java.util.List;
|
|
|
-import com.fs.common.utils.DateUtils;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fs.hisStore.param.FsStoreOrderPickAddParam;
|
|
|
+import com.fs.tzBankPay.TzBankService.TzBankService;
|
|
|
+import com.fs.tzBankPay.doman.PayCreateOrder;
|
|
|
+import com.fs.tzBankPay.doman.PayCreateOrderResult;
|
|
|
+import com.fs.tzBankPay.doman.TzBankResult;
|
|
|
+import com.fs.ybPay.domain.CreateWxOrderResult;
|
|
|
+import com.fs.ybPay.dto.WxJspayDTO;
|
|
|
+import com.fs.ybPay.service.IPayService;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import com.fs.hisStore.mapper.FsStoreOrderPickMapper;
|
|
|
-import com.fs.hisStore.domain.FsStoreOrderPick;
|
|
|
-import com.fs.hisStore.service.IFsStoreOrderPickService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 自提商品订单Service业务层处理
|
|
|
@@ -35,6 +87,7 @@ import java.util.ArrayList;
|
|
|
* @author fs
|
|
|
* @date 2026-06-24
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMapper, FsStoreOrderPick> implements IFsStoreOrderPickService {
|
|
|
@Autowired
|
|
|
@@ -42,7 +95,33 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
@Autowired
|
|
|
private IFsStoreProductScrmService fsStoreProductScrmService;
|
|
|
@Autowired
|
|
|
- private FsStoreOrderPickItemMapper fsStoreOrderPickItemMapper;
|
|
|
+ private IFsStoreOrderScrmService fsStoreOrderScrmService;
|
|
|
+ @Autowired
|
|
|
+ private FsStoreOrderScrmMapper fsStoreOrderScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsStoreOrderItemScrmMapper fsStoreOrderItemScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsUserAddressScrmMapper fsUserAddressScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private MerchantAppConfigMapper merchantAppConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsStorePaymentScrmMapper fsStorePaymentScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsUserWxMapper fsUserWxMapper;
|
|
|
+ @Autowired
|
|
|
+ private WxPayService wxPayService;
|
|
|
+ @Autowired
|
|
|
+ private IPayService payService;
|
|
|
+ @Autowired
|
|
|
+ private TzBankService tzBankService;
|
|
|
+ @Autowired
|
|
|
+ private HuiFuService huiFuService;
|
|
|
+ @Autowired
|
|
|
+ private IFsUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private WxPayProperties wxPayProperties;
|
|
|
|
|
|
/**
|
|
|
* 查询自提商品订单
|
|
|
@@ -51,8 +130,7 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 自提商品订单
|
|
|
*/
|
|
|
@Override
|
|
|
- public FsStoreOrderPick selectFsStoreOrderPickById(Long id)
|
|
|
- {
|
|
|
+ public FsStoreOrderPick selectFsStoreOrderPickById(Long id) {
|
|
|
return baseMapper.selectFsStoreOrderPickById(id);
|
|
|
}
|
|
|
|
|
|
@@ -63,8 +141,7 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 自提商品订单
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<FsStoreOrderPick> selectFsStoreOrderPickList(FsStoreOrderPick fsStoreOrderPick)
|
|
|
- {
|
|
|
+ public List<FsStoreOrderPick> selectFsStoreOrderPickList(FsStoreOrderPick fsStoreOrderPick) {
|
|
|
return baseMapper.selectFsStoreOrderPickList(fsStoreOrderPick);
|
|
|
}
|
|
|
|
|
|
@@ -75,8 +152,7 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertFsStoreOrderPick(FsStoreOrderPick fsStoreOrderPick)
|
|
|
- {
|
|
|
+ public int insertFsStoreOrderPick(FsStoreOrderPick fsStoreOrderPick) {
|
|
|
fsStoreOrderPick.setCreateTime(DateUtils.getNowDate());
|
|
|
return baseMapper.insertFsStoreOrderPick(fsStoreOrderPick);
|
|
|
}
|
|
|
@@ -88,8 +164,7 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateFsStoreOrderPick(FsStoreOrderPick fsStoreOrderPick)
|
|
|
- {
|
|
|
+ public int updateFsStoreOrderPick(FsStoreOrderPick fsStoreOrderPick) {
|
|
|
fsStoreOrderPick.setUpdateTime(DateUtils.getNowDate());
|
|
|
return baseMapper.updateFsStoreOrderPick(fsStoreOrderPick);
|
|
|
}
|
|
|
@@ -101,8 +176,7 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsStoreOrderPickByIds(Long[] ids)
|
|
|
- {
|
|
|
+ public int deleteFsStoreOrderPickByIds(Long[] ids) {
|
|
|
return baseMapper.deleteFsStoreOrderPickByIds(ids);
|
|
|
}
|
|
|
|
|
|
@@ -113,74 +187,471 @@ public class FsStoreOrderPickServiceImpl extends ServiceImpl<FsStoreOrderPickMap
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsStoreOrderPickById(Long id)
|
|
|
- {
|
|
|
+ public int deleteFsStoreOrderPickById(Long id) {
|
|
|
return baseMapper.deleteFsStoreOrderPickById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public int createFsStoreOrderPick(FsStoreOrderPickAddParam fsStoreOrderPickAddParam) {
|
|
|
- if (fsStoreOrderPickAddParam == null || fsStoreOrderPickAddParam.getUserId() == null || fsStoreOrderPickAddParam.getProductId() == null) {
|
|
|
- throw new RuntimeException("参数错误");
|
|
|
+ public R createFsStoreOrderPick(FsStoreOrderPickAddParam param) {
|
|
|
+ if (param == null || param.getUserId() == null || param.getProductId() == null) {
|
|
|
+ return R.error("参数错误");
|
|
|
}
|
|
|
-
|
|
|
- FsUserScrm user = fsUserScrmService.selectFsUserById(fsStoreOrderPickAddParam.getUserId());
|
|
|
- if (user == null || Integer.valueOf(1).equals(user.getIsDel())) {
|
|
|
- throw new RuntimeException("用户不存在");
|
|
|
+ FsUserScrm user = fsUserScrmService.selectFsUserById(param.getUserId());
|
|
|
+ if (user == null) {
|
|
|
+ return R.error("用户不存在");
|
|
|
}
|
|
|
- FsStoreProductScrm product = fsStoreProductScrmService.selectFsStoreProductById(fsStoreOrderPickAddParam.getProductId());
|
|
|
+ FsStoreProductScrm product = fsStoreProductScrmService.selectFsStoreProductById(param.getProductId());
|
|
|
if (product == null || Integer.valueOf(1).equals(product.getIsDel())) {
|
|
|
- throw new RuntimeException("商品不存在");
|
|
|
+ return R.error("商品不存在");
|
|
|
+ }
|
|
|
+ String orderCode = OrderCodeUtils.getOrderSn();
|
|
|
+ if (StringUtils.isEmpty(orderCode)) {
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
}
|
|
|
- String orderCode = SnowflakeUtil.nextIdStr();
|
|
|
- // 生成核销码
|
|
|
- String redeemQrUrl = generateRedeemedQrUrl(orderCode);
|
|
|
- FsStoreOrderPick orderPick = new FsStoreOrderPick();
|
|
|
- orderPick.setOrderCode(orderCode);
|
|
|
- orderPick.setUserId(user.getUserId());
|
|
|
- String nickName = StringUtils.isNotEmpty(user.getNickName()) ? user.getNickName() : user.getNickname();
|
|
|
- orderPick.setNickName(nickName);
|
|
|
- orderPick.setPhone(user.getPhone());
|
|
|
- orderPick.setTotalNum(1);
|
|
|
BigDecimal price = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
|
|
- orderPick.setTotalPrice(price);
|
|
|
- orderPick.setRedeemedCode(redeemQrUrl);
|
|
|
- orderPick.setRedeemedStatus(1);
|
|
|
- orderPick.setIsDel(0);
|
|
|
- orderPick.setCompanyId(fsStoreOrderPickAddParam.getCompanyId());
|
|
|
- orderPick.setCompanyUserId(fsStoreOrderPickAddParam.getCompanyUserId());
|
|
|
- orderPick.setDeptId(fsStoreOrderPickAddParam.getDeptId());
|
|
|
- orderPick.setUserRecordId(fsStoreOrderPickAddParam.getUserRecordId());
|
|
|
- orderPick.setCreateTime(DateUtils.getNowDate());
|
|
|
- int rows = baseMapper.insertFsStoreOrderPick(orderPick);
|
|
|
- if (rows <= 0 || orderPick.getId() == null) {
|
|
|
- throw new RuntimeException("创建自提订单失败");
|
|
|
- }
|
|
|
-
|
|
|
- FsStoreOrderPickItem orderPickItem = new FsStoreOrderPickItem();
|
|
|
- orderPickItem.setOrderId(orderPick.getId());
|
|
|
- orderPickItem.setOrderCode(orderCode);
|
|
|
- orderPickItem.setProductId(product.getProductId());
|
|
|
- orderPickItem.setNum(1);
|
|
|
+ String redeemQrUrl = generateRedeemedQrUrl(orderCode);
|
|
|
+ FsStoreOrderScrm order = new FsStoreOrderScrm();
|
|
|
+ order.setOrderCode(orderCode);
|
|
|
+ order.setUserId(user.getUserId());
|
|
|
+ String realName = StringUtils.isNotEmpty(user.getNickName()) ? user.getNickName() : user.getNickname();
|
|
|
+ order.setRealName(realName);
|
|
|
+ order.setUserPhone(user.getPhone());
|
|
|
+ order.setUserAddress(param.getPickupAddress());
|
|
|
+ order.setTotalNum(1L);
|
|
|
+ order.setTotalPrice(price);
|
|
|
+ order.setPayPrice(price);
|
|
|
+ order.setPayMoney(BigDecimal.ZERO);
|
|
|
+ order.setPaid(0);
|
|
|
+ order.setIsPay(0);
|
|
|
+ order.setPayType("1");
|
|
|
+ order.setStatus(0);
|
|
|
+ order.setIsDel(0);
|
|
|
+ order.setIsSysDel(0);
|
|
|
+ Integer productShippingType = product.getShippingType();
|
|
|
+ if (Integer.valueOf(1).equals(productShippingType)) {
|
|
|
+ order.setShippingType(2);
|
|
|
+ } else if (Integer.valueOf(2).equals(productShippingType)) {
|
|
|
+ order.setShippingType(1);
|
|
|
+ } else {
|
|
|
+ order.setShippingType(2);
|
|
|
+ }
|
|
|
+ order.setOrderType(8);
|
|
|
+ order.setIsPickup(1);
|
|
|
+ order.setRedeemedCode(redeemQrUrl);
|
|
|
+ order.setRedeemedStatus(1);
|
|
|
+ order.setCompanyId(param.getCompanyId());
|
|
|
+ order.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ order.setDeptId(param.getDeptId());
|
|
|
+ order.setUserRecordId(param.getUserRecordId());
|
|
|
+ order.setCreateTime(DateUtils.getNowDate());
|
|
|
+ int rows = fsStoreOrderScrmMapper.insertFsStoreOrder(order);
|
|
|
+ if (rows <= 0 || order.getId() == null) {
|
|
|
+ return R.error("创建自提订单失败");
|
|
|
+ }
|
|
|
+ FsStoreOrderItemScrm orderItem = new FsStoreOrderItemScrm();
|
|
|
+ orderItem.setOrderId(order.getId());
|
|
|
+ orderItem.setOrderCode(orderCode);
|
|
|
+ orderItem.setProductId(product.getProductId());
|
|
|
+ orderItem.setNum(1);
|
|
|
PickItemJsonInfo jsonInfo = new PickItemJsonInfo();
|
|
|
jsonInfo.setImage(product.getImage());
|
|
|
jsonInfo.setProductId(product.getProductId());
|
|
|
jsonInfo.setNum(1);
|
|
|
jsonInfo.setProductName(product.getProductName());
|
|
|
jsonInfo.setPrice(price);
|
|
|
- orderPickItem.setJsonInfo(JSONUtil.toJsonStr(jsonInfo));
|
|
|
- fsStoreOrderPickItemMapper.insertFsStoreOrderPickItem(orderPickItem);
|
|
|
-
|
|
|
- List<FsStoreOrderPickItem> itemList = new ArrayList<>();
|
|
|
- itemList.add(orderPickItem);
|
|
|
- FsStoreOrderPick updateOrder = new FsStoreOrderPick();
|
|
|
- updateOrder.setId(orderPick.getId());
|
|
|
+ orderItem.setJsonInfo(JSONUtil.toJsonStr(jsonInfo));
|
|
|
+ fsStoreOrderItemScrmMapper.insertFsStoreOrderItem(orderItem);
|
|
|
+ List<FsStoreOrderItemScrm> itemList = new ArrayList<>();
|
|
|
+ itemList.add(orderItem);
|
|
|
+ FsStoreOrderScrm updateOrder = new FsStoreOrderScrm();
|
|
|
+ updateOrder.setId(order.getId());
|
|
|
updateOrder.setItemJson(JSONUtil.toJsonStr(itemList));
|
|
|
- baseMapper.updateFsStoreOrderPick(updateOrder);
|
|
|
- return rows;
|
|
|
+ updateOrder.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ fsStoreOrderScrmMapper.updateFsStoreOrder(updateOrder);
|
|
|
+ return R.ok().put("order", order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R confirmFsStoreOrderPick(FsStoreOrderPickAddParam param) {
|
|
|
+ return buildPickOrderPreview(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R computeFsStoreOrderPick(Long userId, FsStoreOrderPickComputeParam param) {
|
|
|
+ if (param == null || param.getOrderId() == null) {
|
|
|
+ return R.error("订单号不能为空");
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if (order == null || !userId.equals(order.getUserId()) || !Integer.valueOf(1).equals(order.getIsPickup())) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ Map<String, Object> moneys = computeOrderMoney(order.getTotalPrice(), param);
|
|
|
+ return R.ok().put("moneys", moneys);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自提订单金额计算(对齐套餐包返回结构)
|
|
|
+ */
|
|
|
+ private Map<String, Object> computeOrderMoney(BigDecimal orderPrice, FsStoreOrderPickComputeParam param) {
|
|
|
+ Map<String, Object> moneys = new HashMap<>();
|
|
|
+ BigDecimal safeOrderPrice = orderPrice == null ? BigDecimal.ZERO : orderPrice;
|
|
|
+ BigDecimal payPrice = safeOrderPrice;
|
|
|
+ BigDecimal payMoney = safeOrderPrice;
|
|
|
+ BigDecimal payRemain = BigDecimal.ZERO;
|
|
|
+ BigDecimal payDelivery = BigDecimal.ZERO;
|
|
|
+ BigDecimal discountMoney = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 暂时没有优惠券
|
|
|
+
|
|
|
+ if (payPrice.compareTo(new BigDecimal(0)) > 0) {
|
|
|
+ if (param.getPayType().equals(1)) {
|
|
|
+ //全款支付
|
|
|
+ payMoney = payPrice;
|
|
|
+ payRemain = new BigDecimal(0);
|
|
|
+ payDelivery = new BigDecimal(0);
|
|
|
+ }
|
|
|
+ //
|
|
|
+ }
|
|
|
+ moneys.put("payPrice", payPrice);
|
|
|
+ moneys.put("payMoney", payMoney);
|
|
|
+ moneys.put("payRemain", payRemain);
|
|
|
+ moneys.put("payDelivery", payDelivery);
|
|
|
+ moneys.put("discountMoney", discountMoney);
|
|
|
+ return moneys;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R payFsStoreOrderPick(Long userId, FsStoreOrderPickPayParam param) {
|
|
|
+ if (param == null || param.getOrderId() == null) {
|
|
|
+ return R.error("订单号不能为空");
|
|
|
+ }
|
|
|
+ if (param.getPayType() == null) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if (order == null || !userId.equals(order.getUserId()) || !Integer.valueOf(1).equals(order.getIsPickup())) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ // 状态必须要是待支付
|
|
|
+ if (!Integer.valueOf(0).equals(order.getStatus())) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsStoreOrderPickComputeParam computeParam = new FsStoreOrderPickComputeParam();
|
|
|
+ computeParam.setOrderId(order.getId());
|
|
|
+ computeParam.setCompanyId(order.getCompanyId());
|
|
|
+ computeParam.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ computeParam.setPayType(param.getPayType());
|
|
|
+ Map<String, Object> moneys = computeOrderMoney(order.getTotalPrice(), computeParam);
|
|
|
+ FsStoreOrderScrm updateOrder = new FsStoreOrderScrm();
|
|
|
+ updateOrder.setId(order.getId());
|
|
|
+ updateOrder.setPayMoney((BigDecimal) moneys.get("payMoney"));
|
|
|
+ updateOrder.setPayPrice((BigDecimal) moneys.get("payPrice"));
|
|
|
+ updateOrder.setPayDelivery((BigDecimal) moneys.get("payDelivery"));
|
|
|
+ updateOrder.setDiscountMoney((BigDecimal) moneys.get("discountMoney"));
|
|
|
+ updateOrder.setPayType(String.valueOf(param.getPayType()));
|
|
|
+ updateOrder.setRemark(param.getRemark());
|
|
|
+
|
|
|
+ if (param.getAddressId() == null) {
|
|
|
+ return R.error("收货地址不能为空");
|
|
|
+ }
|
|
|
+ FsUserAddressScrm address = fsUserAddressScrmMapper.selectFsUserAddressById(param.getAddressId());
|
|
|
+ if (address == null || !userId.equals(address.getUserId())) {
|
|
|
+ return R.error("收货地址不存在");
|
|
|
+ }
|
|
|
+ updateOrder.setRealName(address.getRealName());
|
|
|
+ updateOrder.setUserPhone(address.getPhone());
|
|
|
+ updateOrder.setUserAddress(address.getProvince() + " " + address.getCity() + " " + address.getDistrict() + " " + address.getDetail());
|
|
|
+
|
|
|
+ updateOrder.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ fsStoreOrderScrmMapper.updateFsStoreOrder(updateOrder);
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R paymentFsStoreOrderPick(FsStoreOrderPickPaymentParam param, HttpServletRequest request) {
|
|
|
+ if (param == null || param.getOrderId() == null || param.getUserId() == null) {
|
|
|
+ return R.error("参数错误");
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if (order == null || !param.getUserId().equals(order.getUserId()) || !Integer.valueOf(1).equals(order.getIsPickup())) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (!Integer.valueOf(0).equals(order.getStatus())) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney() == null || order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ return R.error("支付金额须大于0");
|
|
|
+ }
|
|
|
+// FsUserScrm user = fsUserScrmService.selectFsUserById(param.getUserId());
|
|
|
+ FsUser user= userService.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null) {
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(param.getAppId())) {
|
|
|
+ throw new IllegalArgumentException("appId不能为空");
|
|
|
+ }
|
|
|
+ FsCoursePlaySourceConfig sourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(param.getAppId());
|
|
|
+ if (sourceConfig == null) {
|
|
|
+ throw new ServiceException("未找到appId对应的小程序配置: " + param.getAppId());
|
|
|
+ }
|
|
|
+ Long merchantConfigId = sourceConfig.getMerchantConfigId();
|
|
|
+ if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
+ throw new ServiceException("小程序没有配置商户信息");
|
|
|
+ }
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(merchantConfigId);
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
+
|
|
|
+ String openId = null;
|
|
|
+ String appId = param.getAppId();
|
|
|
+ if (request.getHeader("sourcetype") != null && "APP".equals(request.getHeader("sourcetype"))) {
|
|
|
+// FsUser fsUser = fsUserService.selectFsUserByUserId(param.getUserId().longValue());
|
|
|
+ openId = user.getAppOpenId();
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotBlank(appId)) {
|
|
|
+ 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 = sourceConfig.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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (user != null
|
|
|
+ && (
|
|
|
+ StringUtils.isNotEmpty(openId)
|
|
|
+ || "appPay".equals(merchantAppConfig.getMerchantType())
|
|
|
+ || ("hf".equals(merchantAppConfig.getMerchantType()) && "ali".equals(param.getPayType()))
|
|
|
+ )) {
|
|
|
+
|
|
|
+ }
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
+ if (StringUtils.isEmpty(payCode)) {
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ String payType = normalizePayType(param.getPayType());
|
|
|
+ FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(merchantAppConfig.getMerchantType());
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode(!"appPay".equals(merchantAppConfig.getMerchantType()) ? "weixin" : param.getPayType());
|
|
|
+ storePayment.setBusinessType(8);
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+ storePayment.setRemark("商城自提订单支付");
|
|
|
+ storePayment.setOpenId(openId);
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setStoreId(order.getStoreId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ storePayment.setAppId(param.getAppId());
|
|
|
+ storePayment.setMerConfigId(merchantAppConfig.getId());
|
|
|
+ if (fsStorePaymentScrmMapper.insertFsStorePayment(storePayment) <= 0) {
|
|
|
+ return R.error("支付失败");
|
|
|
+ }
|
|
|
+ if ("wx".equals(merchantAppConfig.getMerchantType())) {
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(param.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(wxPayProperties.getNotifyUrl());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(openId);
|
|
|
+ orderRequest.setBody("商城自提订单支付");
|
|
|
+ orderRequest.setOutTradeNo("storePick-" + 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("data", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ throw new ServiceException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ } else if ("yb".equals(merchantAppConfig.getMerchantType())) {
|
|
|
+ WxJspayDTO p = new WxJspayDTO();
|
|
|
+ p.setPayMoney(storePayment.getPayMoney().toString());
|
|
|
+ p.setLowOrderId("storePick-" + storePayment.getPayCode());
|
|
|
+ p.setBody("商城自提订单支付");
|
|
|
+ p.setIsMinipg("1");
|
|
|
+ p.setOpenId(openId);
|
|
|
+ p.setAttach("");
|
|
|
+ p.setStoreid("0");
|
|
|
+ CreateWxOrderResult wxOrder = payService.createWxOrder(p);
|
|
|
+ log.info("易宝返回{}", wxOrder);
|
|
|
+ if ("100".equals(wxOrder.getStatus())) {
|
|
|
+ FsStorePaymentScrm mt = new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(wxOrder.getUpOrderId());
|
|
|
+ fsStorePaymentScrmMapper.updateFsStorePayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", wxOrder).put("type", "yb");
|
|
|
+ }
|
|
|
+ throw new ServiceException("支付失败");
|
|
|
+ } else if ("tz".equals(merchantAppConfig.getMerchantType())) {
|
|
|
+ PayCreateOrder o = new PayCreateOrder();
|
|
|
+ o.setOrderNo("storePick" + storePayment.getPayCode());// 业务系统订单号
|
|
|
+ o.setTrxAmt(storePayment.getPayMoney().doubleValue());// 交易金额
|
|
|
+ o.setBusinessCstNo(order.getUserId().toString());// 业务平台客户号
|
|
|
+ String phone = "";
|
|
|
+ if (user.getPhone()!=null&&user.getPhone().length()>4){
|
|
|
+ phone=user.getPhone().substring(user.getPhone().length()-4);
|
|
|
+ if (user.getPhone().length()>11){
|
|
|
+ o.setPayerMobileNo(PhoneUtil.decryptPhone(user.getPhone()));
|
|
|
+ }else {
|
|
|
+ o.setPayerMobileNo(user.getPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ o.setPayerName("微信用户"+phone);
|
|
|
+ o.setGoodsInfo("商城自提订单支付");
|
|
|
+ o.setOpenId(openId);
|
|
|
+ o.setOrderType(8);
|
|
|
+ o.setOrderId(order.getId().toString());
|
|
|
+ TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(o);
|
|
|
+ FsStorePaymentScrm mt = new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getBody().getOrderFlowNo());
|
|
|
+ fsStorePaymentScrmMapper.updateFsStorePayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "tz");
|
|
|
+ } else if ("hf".equals(merchantAppConfig.getMerchantType())) {
|
|
|
+ boolean shareAmount = false;
|
|
|
+ log.info("创建汇付订单.....");
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType(StringUtils.isEmpty(param.getPayType()) || param.getPayType().equals("wx") ? "T_MINIAPP" : "A_NATIVE");
|
|
|
+ o.setOpenid(openId);
|
|
|
+ o.setReqSeqId("storePick-" + storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("商城自提订单支付");
|
|
|
+ o.setAppId(appId);
|
|
|
+
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ log.info("创建汇付支付{}:", result);
|
|
|
+ FsStorePaymentScrm mt = new FsStorePaymentScrm();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ mt.setAppId(param.getAppId());
|
|
|
+ fsStorePaymentScrmMapper.updateFsStorePayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
+ } else if ("appPay".equals(merchantAppConfig.getMerchantType()) && "wx".equals(payType)) {
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(param.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxAppMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxAppMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getWxAppNotifyUrl());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setBody("商城自提订单支付");
|
|
|
+ orderRequest.setOutTradeNo("storePick-" + storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));
|
|
|
+ orderRequest.setTradeType("APP");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ orderRequest.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ try {
|
|
|
+ Object result = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("data", result).put("type", "wxApp").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ throw new ServiceException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ } else if ("appPay".equals(merchantAppConfig.getMerchantType()) && "ali".equals(payType)) {
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", fsPayConfig.getAliAppId(), fsPayConfig.getAliPrivateKey(), "json", "utf-8", fsPayConfig.getAliPublicKey(), "RSA2");
|
|
|
+ AlipayTradeAppPayRequest aliRequest = new AlipayTradeAppPayRequest();
|
|
|
+ AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
|
|
+ model.setOutTradeNo("storePick-" + storePayment.getPayCode());
|
|
|
+ model.setTotalAmount(storePayment.getPayMoney().toString());
|
|
|
+ model.setSubject("商城自提订单支付");
|
|
|
+ aliRequest.setBizModel(model);
|
|
|
+ aliRequest.setNotifyUrl(fsPayConfig.getAliNotifyUrl());
|
|
|
+ try {
|
|
|
+ AlipayTradeAppPayResponse result = alipayClient.sdkExecute(aliRequest);
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(result);
|
|
|
+ log.error("支付宝支付调用失败 诊断链接:{}", diagnosisUrl);
|
|
|
+ throw new ServiceException(result.getSubMsg() + " " + diagnosisUrl);
|
|
|
+ }
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "aliPay");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("支付宝支付异常: {}", e);
|
|
|
+ throw new ServiceException("支付失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.error("无支付类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String normalizePayType(String rawType) {
|
|
|
+ if (StringUtils.isBlank(rawType)) {
|
|
|
+ return "wx";
|
|
|
+ }
|
|
|
+ String type = rawType.toLowerCase();
|
|
|
+ if (type.contains("ali")) {
|
|
|
+ return "ali";
|
|
|
+ }
|
|
|
+ return "wx";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getFsStoreOrderPickDetail(Long userId, Long orderId) {
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(orderId);
|
|
|
+ if (order == null || !userId.equals(order.getUserId()) || !Integer.valueOf(1).equals(order.getIsPickup())) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ List<FsStoreOrderItemVO> items = fsStoreOrderItemScrmMapper.selectFsStoreOrderItemListByOrderId(orderId);
|
|
|
+ return R.ok().put("order", order).put("items", items);
|
|
|
+ }
|
|
|
+
|
|
|
+ private R buildPickOrderPreview(FsStoreOrderPickAddParam param) {
|
|
|
+ if (param == null || param.getUserId() == null || param.getProductId() == null) {
|
|
|
+ return R.error("参数错误");
|
|
|
+ }
|
|
|
+ FsStoreProductScrm product = fsStoreProductScrmService.selectFsStoreProductById(param.getProductId());
|
|
|
+ if (product == null || Integer.valueOf(1).equals(product.getIsDel())) {
|
|
|
+ return R.error("商品不存在");
|
|
|
+ }
|
|
|
+ BigDecimal price = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
|
|
+ FsStoreOrderPick preview = new FsStoreOrderPick();
|
|
|
+ preview.setUserId(param.getUserId());
|
|
|
+ preview.setCompanyId(param.getCompanyId());
|
|
|
+ preview.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ preview.setDeptId(param.getDeptId());
|
|
|
+ preview.setUserRecordId(param.getUserRecordId());
|
|
|
+ preview.setTotalNum(1);
|
|
|
+ preview.setTotalPrice(price);
|
|
|
+ PickItemJsonInfo jsonInfo = new PickItemJsonInfo();
|
|
|
+ jsonInfo.setImage(product.getImage());
|
|
|
+ jsonInfo.setProductId(product.getProductId());
|
|
|
+ jsonInfo.setNum(1);
|
|
|
+ jsonInfo.setProductName(product.getProductName());
|
|
|
+ jsonInfo.setPrice(price);
|
|
|
+ preview.setItemJson(JSONUtil.toJsonStr(jsonInfo));
|
|
|
+ return R.ok().put("data", preview);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成核销二维码
|
|
|
+ * @param orderCode 订单号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private String generateRedeemedQrUrl(String orderCode) {
|
|
|
try {
|
|
|
String qrContent = "pickOrderCode=" + orderCode;
|