|
@@ -1,14 +1,20 @@
|
|
|
package com.gree.mall.miniapp.logic.material;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.gree.mall.miniapp.bean.PayDetail;
|
|
|
import com.gree.mall.miniapp.bean.material.*;
|
|
|
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
|
|
|
import com.gree.mall.miniapp.commonmapper.MaterialMapper;
|
|
|
+import com.gree.mall.miniapp.constant.SybConstants;
|
|
|
import com.gree.mall.miniapp.enums.IsYesNoEnum;
|
|
|
import com.gree.mall.miniapp.enums.OrderInfoSourceEnum;
|
|
|
+import com.gree.mall.miniapp.enums.PayOrderTypeEnum;
|
|
|
+import com.gree.mall.miniapp.enums.PayTypeEnum;
|
|
|
import com.gree.mall.miniapp.enums.material.WebsitGoodsTypeEnum;
|
|
|
import com.gree.mall.miniapp.exception.RemoteServiceException;
|
|
|
import com.gree.mall.miniapp.logic.common.AllInPayLogic;
|
|
@@ -19,7 +25,9 @@ import com.gree.mall.miniapp.plus.service.*;
|
|
|
import com.gree.mall.miniapp.utils.DateUtils;
|
|
|
import com.gree.mall.miniapp.utils.IpUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -35,6 +43,9 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class WebsitSalesLogic {
|
|
|
|
|
|
+ @Value("${share.mall.appid}")
|
|
|
+ private String mallAppid;
|
|
|
+
|
|
|
@Resource
|
|
|
MaterialMapper materialMapper;
|
|
|
@Resource
|
|
@@ -59,6 +70,8 @@ public class WebsitSalesLogic {
|
|
|
AllInPayLogic allInPayLogic;
|
|
|
@Resource
|
|
|
AdminWebsitPayConfigService adminWebsitPayConfigService;
|
|
|
+ @Resource
|
|
|
+ WebsitSalesPayMapService websitSalesPayMapService;
|
|
|
|
|
|
public IPage<SalesOrderBean> buyList(String flag, Integer pageNum, Integer pageSize, HttpServletRequest request) {
|
|
|
CurrentCompanyWechat wechat = commonLogic.getCurrentCompanyWechat(request);
|
|
@@ -435,4 +448,101 @@ public class WebsitSalesLogic {
|
|
|
log.info("未定义交易状态:" + trxstatus);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public List<AdminWebsitPayConfig> getPayConfig(String websitId, String goodsType, HttpServletRequest request) {
|
|
|
+ CurrentCompanyWechat wechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
+ return adminWebsitPayConfigService.lambdaQuery()
|
|
|
+ .eq(AdminWebsitPayConfig::getCompanyWechatId, wechat.getCompanyWechatId())
|
|
|
+ .eq(AdminWebsitPayConfig::getWebsitId, websitId)
|
|
|
+ .eq(AdminWebsitPayConfig::getType, goodsType)
|
|
|
+ .eq(AdminWebsitPayConfig::getStatus, true)
|
|
|
+ .list();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public WebsitSalesPayMapBean saveSheetPayMap(WebsitSalesPayMapBean sheetPayMap) {
|
|
|
+ if (StringUtils.isBlank(sheetPayMap.getSalesId())) {
|
|
|
+ throw new RemoteServiceException("订单号不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(sheetPayMap.getPayConfigId())) {
|
|
|
+ throw new RemoteServiceException("支付配置不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取支付记录
|
|
|
+ List<WebsitSalesPayOrder> payList = websitSalesPayOrderService.lambdaQuery()
|
|
|
+ .eq(WebsitSalesPayOrder::getOrderId, sheetPayMap.getSalesId())
|
|
|
+ .orderByAsc(WebsitSalesPayOrder::getId)
|
|
|
+ .list();
|
|
|
+ // 判断是否存在一个或以上支付记录
|
|
|
+ if (CollectionUtil.isNotEmpty(payList)) {
|
|
|
+ WebsitSalesPayOrder salesPayList = payList.get(payList.size() - 1);
|
|
|
+ // 判断是否支付
|
|
|
+ if (salesPayList.getPayFlag().equals(IsYesNoEnum.YES.getKey())) {
|
|
|
+ throw new RemoteServiceException(salesPayList.getOrderId() + " 订单已支付,请刷新界面!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sheetPayMap.setId(null);
|
|
|
+ sheetPayMap.setAppid(mallAppid);
|
|
|
+ sheetPayMap.setAppOrderId(sheetPayMap.getId());
|
|
|
+ websitSalesPayMapService.save(sheetPayMap);
|
|
|
+
|
|
|
+ return sheetPayMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成支付记录
|
|
|
+ * @param key
|
|
|
+ * @param openid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PayDetail generatePayRecord(String key, String openid) {
|
|
|
+ PayDetail payDetail = null;
|
|
|
+ final WebsitSalesPayMap payMap = websitSalesPayMapService.getById(key);
|
|
|
+
|
|
|
+ final AdminWebsitPayConfig payConfig = adminWebsitPayConfigService.getById(payMap.getPayConfigId());
|
|
|
+
|
|
|
+ final WebsitSales sales = websitSalesService.getById(payMap.getSalesId());
|
|
|
+
|
|
|
+ if (Objects.nonNull(sales)) {
|
|
|
+ WebsitSalesPayOrder payOrder = new WebsitSalesPayOrder();
|
|
|
+ payOrder.setId(IdWorker.getIdStr())
|
|
|
+ .setCompanyWechatId(sales.getCompanyWechatId())
|
|
|
+ .setCompanyWechatName(sales.getCompanyWechatName())
|
|
|
+ .setGoodsType(sales.getGoodsType())
|
|
|
+ .setWebsitId(sales.getWebsitId())
|
|
|
+ .setWebsitName(sales.getWebsitName())
|
|
|
+ .setOrderId(sales.getSalesId())
|
|
|
+ .setOutTradeNo(payOrder.getId())
|
|
|
+ .setOpenid(openid)
|
|
|
+ .setPayType(PayTypeEnum.ALLINPAY.getKey())
|
|
|
+ .setOrderCreateTime(sales.getCreateTime())
|
|
|
+ .setPayValue(sales.getTotalAmount())
|
|
|
+ .setOrgId(payConfig.getOrgId())
|
|
|
+ .setMchNo(payConfig.getMchNo())
|
|
|
+ .setAppid(payConfig.getAppid())
|
|
|
+ .setOrderType(PayOrderTypeEnum.S.getKey())
|
|
|
+ .setRunTime(DateUtil.offsetSecond(DateUtil.date(), 10))
|
|
|
+ .setOrderSource(sales.getGoodsType().equals(WebsitGoodsTypeEnum.M.toString()) ? "M_SALES" : "P_SALES")
|
|
|
+ .setIsDeliver(false);
|
|
|
+
|
|
|
+
|
|
|
+ // 请求通联得到结果
|
|
|
+ Map<String, String> resMap = allInPayLogic.serviceUnifiedOrder(payOrder, SybConstants.PAY_TYPE_W06);
|
|
|
+
|
|
|
+ if (!resMap.get("trxstatus").equals("0000")) {
|
|
|
+ throw new RemoteServiceException("通联统一支付接口执行失败:" + resMap.get("errmsg"));
|
|
|
+ }
|
|
|
+
|
|
|
+ payOrder.setOrderNo(resMap.get("trxid"))
|
|
|
+ .insert();
|
|
|
+
|
|
|
+ payDetail = new PayDetail();
|
|
|
+ payDetail.setCodeUrl(resMap.get("payinfo"));
|
|
|
+ payDetail.setId(payOrder.getId());
|
|
|
+ log.info("通联支付payDetail:{}", JSONObject.toJSONString(payDetail));
|
|
|
+ }
|
|
|
+
|
|
|
+ return payDetail;
|
|
|
+ }
|
|
|
}
|