|
@@ -9,17 +9,16 @@ import com.github.wxpay.sdk.WXPayConstants;
|
|
|
import com.github.wxpay.sdk.WXPayUtil;
|
|
|
import com.miaxis.common.config.WxPayXcxConfigImpl;
|
|
|
import com.miaxis.common.config.WxpayConfig;
|
|
|
+import com.miaxis.common.core.domain.entity.SysUser;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
-import com.miaxis.common.utils.DateUtils;
|
|
|
-import com.miaxis.common.utils.RSAUtils;
|
|
|
-import com.miaxis.common.utils.SecurityUtils;
|
|
|
-import com.miaxis.common.utils.XmlUtil;
|
|
|
+import com.miaxis.common.utils.*;
|
|
|
import com.miaxis.order.domain.OrderInfo;
|
|
|
import com.miaxis.order.domain.OrderSplit;
|
|
|
import com.miaxis.order.service.IOrderInfoService;
|
|
|
import com.miaxis.order.service.IOrderSplitService;
|
|
|
import com.miaxis.system.service.ISysConfigService;
|
|
|
+import com.miaxis.system.service.ISysUserService;
|
|
|
import com.miaxis.user.service.IUserInfoService;
|
|
|
import com.miaxis.wx.domain.WxExtract;
|
|
|
import com.miaxis.wx.domain.WxExtractBank;
|
|
@@ -69,6 +68,8 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Autowired
|
|
|
private IOrderSplitService orderSplitService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
|
|
@Autowired
|
|
|
private RSAUtils rsaUtils;
|
|
@@ -93,7 +94,9 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void wxAddFenZhang() throws Exception {
|
|
|
+ public void wxAddFenZhang(WxOrder wxOrder) throws Exception {
|
|
|
+ //查询上级
|
|
|
+ String account = getAccount(wxOrder);
|
|
|
String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
|
|
|
|
|
|
String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
@@ -105,7 +108,11 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
sortMap.put("sign_type", "HMAC-SHA256");
|
|
|
Map<String, String> receiverMap = new TreeMap<String, String>();
|
|
|
receiverMap.put("type", "PERSONAL_OPENID");
|
|
|
- receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ if(StringUtils.isNotEmpty(account)) { //如果存在上级,分给上给
|
|
|
+ receiverMap.put("account", account);
|
|
|
+ } else { //如果不存在上级,分给固定的
|
|
|
+ receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ }
|
|
|
receiverMap.put("relation_type", "SERVICE_PROVIDER"); //合作合伙
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
String receiverMapJson = objectMapper.writeValueAsString(receiverMap);
|
|
@@ -126,6 +133,8 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -133,6 +142,8 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean wxProfitsharing(WxOrder wxOrder) throws Exception {
|
|
|
+ //查询上级
|
|
|
+ String account = getAccount(wxOrder);
|
|
|
String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";
|
|
|
String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
|
//用于签名
|
|
@@ -145,6 +156,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
String orderCode = getOrderCode(wxOrder.getUserId()); //商户分账单号
|
|
|
sortMap.put("out_order_no", orderCode);
|
|
|
|
|
|
+
|
|
|
//扣除手续费后
|
|
|
double commission = wxOrder.getTotal() * 0.01;
|
|
|
double total = wxOrder.getTotal() - commission;
|
|
@@ -152,7 +164,13 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
|
|
|
Map<String, Object> receiverMap = new TreeMap<String, Object>();
|
|
|
receiverMap.put("type", "PERSONAL_OPENID");
|
|
|
- receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(account)) { //如果存在上级,分给上给
|
|
|
+ receiverMap.put("account", account);
|
|
|
+ } else { //如果不存在上级,分给固定的
|
|
|
+ receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ }
|
|
|
+
|
|
|
receiverMap.put("amount", amount);
|
|
|
receiverMap.put("description", "分到个人"); //合作合伙
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
@@ -166,6 +184,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
WXPay pay = new WXPay(config);
|
|
|
String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
Map<String, String> resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
+ System.out.println(resMap);
|
|
|
if (!"SUCCESS".equals(resMap.get("return_code")) || !"SUCCESS".equals(resMap.get("result_code"))) {
|
|
|
//throw new CustomException("微信分账出错");
|
|
|
log.info("微信分账出错");
|
|
@@ -178,7 +197,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
OrderSplit orderSplit = new OrderSplit();
|
|
|
orderSplit.setOutSplitNo(orderCode);
|
|
|
orderSplit.setAmount(amount);
|
|
|
- // orderSplit.setOpenId("o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ // orderSplit.setOpenId("o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
orderSplit.setOpenId("obYLX6C7ln62silx-KP73Nd9jUB0");
|
|
|
orderSplit.setDescription("分到个人");
|
|
|
return orderSplitService.save(orderSplit);
|
|
@@ -306,7 +325,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
// 获取当前时间
|
|
|
Date currentDate = new Date();
|
|
|
// 添加5分钟
|
|
|
- long fiveMinutesInMillis = 5 * 60 * 1000; // 5分钟的毫秒数
|
|
|
+ long fiveMinutesInMillis = 1 * 60 * 1000; // 5分钟的毫秒数
|
|
|
Date nowDate = new Date(currentDate.getTime() - fiveMinutesInMillis);
|
|
|
|
|
|
WxOrderProfitDTO wxOrderProfitDTO = new WxOrderProfitDTO();
|
|
@@ -319,4 +338,29 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询出上级unionId
|
|
|
+ * @param wxOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getAccount(WxOrder wxOrder) {
|
|
|
+ String account = null;
|
|
|
+ UserInfo userInfo = sysUserService.getStudentByUnionId(wxOrder.getUnionId());
|
|
|
+ UserInfo pUserInfo = null;
|
|
|
+ if (userInfo.getPUnionId() != null) {
|
|
|
+ pUserInfo = sysUserService.getStudentByUnionId(userInfo.getPUnionId());
|
|
|
+ }
|
|
|
+ if (pUserInfo != null) {
|
|
|
+ if (StringUtils.isNotEmpty(pUserInfo.getXcxOpenid())) {
|
|
|
+ account = pUserInfo.getXcxOpenid();
|
|
|
+ } else if (StringUtils.isNotEmpty(pUserInfo.getGzhOpenid())) {
|
|
|
+ account = pUserInfo.getGzhOpenid();
|
|
|
+ } else if (StringUtils.isNotEmpty(pUserInfo.getAppOpenid())) {
|
|
|
+ account = pUserInfo.getAppOpenid();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return account;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|