|
@@ -39,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
@@ -96,7 +97,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Transactional
|
|
|
public boolean wxAddFenZhang(OrderInfo orderInfo) throws Exception {
|
|
|
//查询上级
|
|
|
- String account = getAccount(orderInfo);
|
|
|
+ Map<String, Object> accountMap = getAccount(orderInfo);
|
|
|
String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
|
|
|
|
|
|
String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
@@ -108,11 +109,16 @@ 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");
|
|
|
- if(StringUtils.isNotEmpty(account)) { //如果存在上级,分给上给
|
|
|
- receiverMap.put("account", account);
|
|
|
- } else { //如果不存在上级,分给固定的
|
|
|
- receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+
|
|
|
+ if (accountMap != null) {
|
|
|
+ String account = (String) accountMap.get("account");
|
|
|
+ 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);
|
|
@@ -127,7 +133,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
|
|
|
Map<String, String> resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
if (!"SUCCESS".equals(resMap.get("return_code")) || !"SUCCESS".equals(resMap.get("result_code"))) {
|
|
|
- // throw new CustomException("微信添加分账出错");
|
|
|
+ // throw new CustomException("微信添加分账出错");
|
|
|
log.info("微信添加分账出错");
|
|
|
log.info(resMap.toString());
|
|
|
return false;
|
|
@@ -138,8 +144,6 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -147,8 +151,6 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean wxProfitsharing(OrderInfo orderInfo) throws Exception {
|
|
|
- //查询上级
|
|
|
- String account = getAccount(orderInfo);
|
|
|
String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";
|
|
|
String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
|
//用于签名
|
|
@@ -161,16 +163,22 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
String orderCode = getOrderCode(orderInfo.getUserId()); //商户分账单号
|
|
|
sortMap.put("out_order_no", orderCode);
|
|
|
|
|
|
-
|
|
|
//扣除手续费后
|
|
|
double commission = orderInfo.getTotal() * 0.01;
|
|
|
double total = orderInfo.getTotal() - commission;
|
|
|
int amount = (int) Math.floor(total * 0.3);
|
|
|
-
|
|
|
Map<String, Object> receiverMap = new TreeMap<String, Object>();
|
|
|
receiverMap.put("type", "PERSONAL_OPENID");
|
|
|
|
|
|
- if(StringUtils.isNotEmpty(account)) { //如果存在上级,分给上给
|
|
|
+ //获取上级
|
|
|
+ Map<String, Object> accountMap = getAccount(orderInfo);
|
|
|
+ String account = null;
|
|
|
+ Integer openIdType = null;
|
|
|
+ if (accountMap != null) {
|
|
|
+ account = (String) accountMap.get("account");
|
|
|
+ openIdType = (Integer) accountMap.get("openIdType");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(account)) { //如果存在上级,分给上给
|
|
|
receiverMap.put("account", account);
|
|
|
} else { //如果不存在上级,分给固定的
|
|
|
receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
@@ -198,15 +206,19 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
return false;
|
|
|
}
|
|
|
//更新成交订单表
|
|
|
- // OrderInfo orderInfo = orderInfoService.getByOutTradeNo(wxOrder.getOutTradeNo());
|
|
|
orderInfo.setProfitSharing(2);
|
|
|
orderInfoService.updateById(orderInfo);
|
|
|
+
|
|
|
OrderSplit orderSplit = new OrderSplit();
|
|
|
orderSplit.setOutSplitNo(orderCode);
|
|
|
orderSplit.setOutTradeNo(orderInfo.getOutTradeNo());
|
|
|
orderSplit.setAmount(amount);
|
|
|
-
|
|
|
orderSplit.setOpenId(account);
|
|
|
+ if (openIdType!=null) {
|
|
|
+ orderSplit.setOpenIdType(openIdType);
|
|
|
+ } else {
|
|
|
+ orderSplit.setOpenIdType(2);
|
|
|
+ }
|
|
|
orderSplit.setDescription("分到个人");
|
|
|
return orderSplitService.save(orderSplit);
|
|
|
}
|
|
@@ -328,14 +340,15 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 查询出上级unionId
|
|
|
+ *
|
|
|
* @param orderInfo
|
|
|
* @return
|
|
|
*/
|
|
|
- private String getAccount(OrderInfo orderInfo) {
|
|
|
+ private Map<String, Object> getAccount(OrderInfo orderInfo) {
|
|
|
+ Map<String, Object> resultMap = new HashMap<String, Object>();
|
|
|
+
|
|
|
String account = null;
|
|
|
UserInfo userInfo = sysUserService.getStudentByUnionId(orderInfo.getUnionId());
|
|
|
UserInfo pUserInfo = null;
|
|
@@ -344,14 +357,22 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
if (pUserInfo != null) {
|
|
|
if (StringUtils.isNotEmpty(pUserInfo.getXcxOpenid())) {
|
|
|
- account = pUserInfo.getXcxOpenid();
|
|
|
+ account = pUserInfo.getXcxOpenid();
|
|
|
+ resultMap.put("account", account);
|
|
|
+ resultMap.put("openIdType", 2);
|
|
|
} else if (StringUtils.isNotEmpty(pUserInfo.getGzhOpenid())) {
|
|
|
account = pUserInfo.getGzhOpenid();
|
|
|
+ resultMap.put("account", account);
|
|
|
+ resultMap.put("openIdType", 3);
|
|
|
} else if (StringUtils.isNotEmpty(pUserInfo.getAppOpenid())) {
|
|
|
account = pUserInfo.getAppOpenid();
|
|
|
+ resultMap.put("account", account);
|
|
|
+ resultMap.put("openIdType", 1);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
- return account;
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
|
|
|
|