|
@@ -24,9 +24,12 @@ import com.fs.common.annotation.DataScope;
|
|
|
import com.fs.common.config.FSSysConfig;
|
|
import com.fs.common.config.FSSysConfig;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.CloudHostUtils;
|
|
import com.fs.common.utils.CloudHostUtils;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
|
|
+import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyConfigMapper;
|
|
import com.fs.company.mapper.CompanyConfigMapper;
|
|
@@ -35,13 +38,15 @@ import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
|
import com.fs.course.config.RedPacketConfig;
|
|
import com.fs.course.config.RedPacketConfig;
|
|
|
|
|
+import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
import com.fs.course.domain.FsCourseRedPacketLog;
|
|
import com.fs.course.domain.FsCourseRedPacketLog;
|
|
|
|
|
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
-import com.fs.his.domain.FsUser;
|
|
|
|
|
-import com.fs.his.domain.FsUserWx;
|
|
|
|
|
|
|
+import com.fs.his.domain.*;
|
|
|
import com.fs.his.mapper.FsUserWxMapper;
|
|
import com.fs.his.mapper.FsUserWxMapper;
|
|
|
|
|
+import com.fs.his.mapper.MerchantAppConfigMapper;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.service.IFsUserWxService;
|
|
import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
@@ -70,6 +75,7 @@ import com.fs.ybPay.domain.CreateWxOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
|
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayTransferBatchesNotifyV3Result;
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayTransferBatchesNotifyV3Result;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.*;
|
|
import com.github.binarywang.wxpay.bean.transfer.*;
|
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
@@ -105,11 +111,12 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
{
|
|
{
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private WxMaProperties properties;
|
|
|
|
|
|
|
+ private WxPayService wxPayService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private IPayService payService;
|
|
|
|
|
|
|
+ private FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private FSSysConfig sysConfig;
|
|
|
|
|
|
|
+ private MerchantAppConfigMapper merchantAppConfigMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsStorePaymentScrmMapper fsStorePaymentMapper;
|
|
private FsStorePaymentScrmMapper fsStorePaymentMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -886,7 +893,19 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
return R.error("注册失败客服已停用,或不存在!");
|
|
return R.error("注册失败客服已停用,或不存在!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(param.getAppId())) {
|
|
|
|
|
+ throw new IllegalArgumentException("appId不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(param.getAppId());
|
|
|
|
|
+ if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
+ throw new CustomException("未找到appId对应的小程序配置: " + param.getAppId());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
+ if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
|
|
+ throw new CustomException("小程序没有配置商户信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
+ FsPayConfig fsPayConfig = com.hc.openapi.tool.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
//生成支付流水
|
|
//生成支付流水
|
|
|
String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
|
|
|
|
@@ -927,37 +946,74 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
storePayment.setPayMode("hf");//目前微信收款仅支持汇付
|
|
storePayment.setPayMode("hf");//目前微信收款仅支持汇付
|
|
|
storePayment.setAppId(param.getAppId());
|
|
storePayment.setAppId(param.getAppId());
|
|
|
fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
-
|
|
|
|
|
- //汇付支付
|
|
|
|
|
- HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
|
|
- o.setTradeType("T_MINIAPP");
|
|
|
|
|
- o.setOpenid(openId);
|
|
|
|
|
- o.setReqSeqId("payment-"+storePayment.getPayCode());
|
|
|
|
|
- o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
|
|
- o.setGoodsDesc("商城订单支付");
|
|
|
|
|
- o.setAppId(param.getAppId());
|
|
|
|
|
- //公司分账
|
|
|
|
|
- try {
|
|
|
|
|
- HuiFuUtils.doDiv(o,company.getCompanyId());
|
|
|
|
|
- //存储分账明细
|
|
|
|
|
- HuiFuUtils.saveDivItem(o, storePayment.getPayCode(), storePayment.getPayCode());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- logger.error("-------------微信收款分账出错:{}", e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- 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);
|
|
|
|
|
- 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());
|
|
|
|
|
|
|
+ if (fsStorePaymentMapper.insertFsStorePayment(storePayment) > 0) {
|
|
|
|
|
+ if (merchantAppConfig.getMerchantType().equals("wx")) {
|
|
|
|
|
+ //创建微信订单
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(appId);
|
|
|
|
|
+ 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(openId);//公众号支付提供用户openid
|
|
|
|
|
+ orderRequest.setBody("拍商品订单支付");
|
|
|
|
|
+ orderRequest.setOutTradeNo("product-" + 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("data", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (merchantAppConfig.getMerchantType().equals("hf")) {
|
|
|
|
|
+
|
|
|
|
|
+ //汇付支付
|
|
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
|
|
+ o.setOpenid(openId);
|
|
|
|
|
+ o.setReqSeqId("payment-"+storePayment.getPayCode());
|
|
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
|
|
+ o.setGoodsDesc("商城订单支付");
|
|
|
|
|
+ o.setAppId(appId);
|
|
|
|
|
+ //公司分账
|
|
|
|
|
+ try {
|
|
|
|
|
+ HuiFuUtils.doDiv(o,company.getCompanyId());
|
|
|
|
|
+ //存储分账明细
|
|
|
|
|
+ HuiFuUtils.saveDivItem(o, storePayment.getPayCode(), storePayment.getPayCode());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("-------------微信收款分账出错:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ 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(appId);
|
|
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
|
|
+ Map<String, Object> resultMap = com.alibaba.fastjson.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 {
|
|
|
|
|
+ return R.error("新增订单失败!");
|
|
|
}
|
|
}
|
|
|
|
|
+ return R.error("支付失败!");
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|