|
@@ -1,19 +1,24 @@
|
|
|
package com.szwl.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.szwl.constant.HuifuConstant;
|
|
|
import com.szwl.constant.JoinpayConstant;
|
|
|
+import com.szwl.constant.ResponseCodesEnum;
|
|
|
import com.szwl.feign.bean.OrderFeign;
|
|
|
-import com.szwl.model.entity.TOrder;
|
|
|
+import com.szwl.feign.bean.SzwlFeign;
|
|
|
+import com.szwl.model.bo.R;
|
|
|
+import com.szwl.model.entity.*;
|
|
|
import com.szwl.mapper.TOrderMapper;
|
|
|
-import com.szwl.model.entity.TOrderDetails;
|
|
|
-import com.szwl.model.entity.TWechatPayConfig;
|
|
|
import com.szwl.model.utils.HttpClientUtils;
|
|
|
+import com.szwl.model.utils.PushUtils;
|
|
|
import com.szwl.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.szwl.service.es.EsTOrderService;
|
|
|
import com.szwl.weixin.util.HttpUtils;
|
|
|
import com.wechat.pay.java.core.Config;
|
|
|
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
|
|
@@ -50,10 +55,19 @@ import static com.szwl.service.impl.TJoinpayMchServiceImpl.createHmacSign;
|
|
|
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
|
|
|
|
|
|
@Autowired
|
|
|
- private TWeixinPayConfigService weixinPayConfigService;
|
|
|
+ OrderFeign orderFeign;
|
|
|
|
|
|
@Autowired
|
|
|
- OrderFeign orderFeign;
|
|
|
+ SzwlFeign szwlFeign;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TOrderService orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EsTOrderService esTOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TEquipmentService equipmentService;
|
|
|
|
|
|
@Autowired
|
|
|
private TWechatPayConfigService wechatPayConfigService;
|
|
@@ -191,6 +205,197 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String joinpayNotifyRefund(HttpServletRequest request) {
|
|
|
+ String r6_Status = request.getParameter("ra_Status");
|
|
|
+
|
|
|
+ // 订单号
|
|
|
+ String sn = request.getParameter("r2_OrderNo");
|
|
|
+ // 退款订单号
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(sn)){
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TOrder::getSn,sn);
|
|
|
+ TOrder order = orderService.getOne(query);
|
|
|
+
|
|
|
+ if (order == null) {
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+ if (order.getStatus() == 3) {
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ // 订单商品数量
|
|
|
+ if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
|
|
|
+ if(order.getRefundQuantity() < order.getProductNumber()) {
|
|
|
+ order.setStatus(1);
|
|
|
+ } else {
|
|
|
+ order.setStatus(3);
|
|
|
+ }
|
|
|
+ // 更改订单明细表
|
|
|
+ LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TOrderDetails::getOrderSn, sn);
|
|
|
+ // 处理退款中状态的明细
|
|
|
+ queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
|
|
|
+ List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
|
|
|
+ for (TOrderDetails tOrderDetail : tOrderDetails) {
|
|
|
+ Integer refundQuantity = tOrderDetail.getRefundQuantity();
|
|
|
+ Integer productNumber = tOrderDetail.getProductNumber();
|
|
|
+ if(refundQuantity < productNumber) {
|
|
|
+ // 部分退款
|
|
|
+ tOrderDetail.setRefundStatus("2");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ } else {
|
|
|
+ // 全部退款
|
|
|
+ tOrderDetail.setRefundStatus("3");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // r4_refundAmount: 退款金额
|
|
|
+ BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
|
|
|
+ if(order.getRefundMarketingAmount()!=null){
|
|
|
+ r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
|
|
|
+ }
|
|
|
+ // price: 订单金额, refundAmount:已退款的金额
|
|
|
+ BigDecimal price = order.getPrice();
|
|
|
+ BigDecimal refundAmount = order.getRefundAmount();
|
|
|
+ TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
|
|
|
+ if(order.getRefundAmount() != null) {
|
|
|
+ BigDecimal newRefundAmount = refundAmount.add(r4_refundAmount);
|
|
|
+ order.setRefundAmount(refundAmount.add(r4_refundAmount));
|
|
|
+ // 如果小于订单金额
|
|
|
+ if(newRefundAmount.compareTo(price) < 0) {
|
|
|
+ JSONArray altInfo = getAltInfo(proportion, price.subtract(newRefundAmount));
|
|
|
+ order.setAltInfo(altInfo.toString());
|
|
|
+ } else {
|
|
|
+ JSONArray altInfo = getAltInfo(proportion, price);
|
|
|
+ order.setAltInfo(altInfo.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ order.setRefundAmount(r4_refundAmount);
|
|
|
+ if(r4_refundAmount.compareTo(price) < 0) {
|
|
|
+ JSONArray altInfo = getAltInfo(proportion, price.subtract(r4_refundAmount));
|
|
|
+ order.setAltInfo(altInfo.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付平台产生的退款流水号
|
|
|
+ String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
|
|
|
+ order.setRefundTrxNo(r5_RefundTrxNo);
|
|
|
+ order.setRefundDate(new Date());
|
|
|
+ order.setModifyDate(new Date());
|
|
|
+ String orderStatus = order.getOrderStatus();
|
|
|
+ if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
|
|
|
+ if(order.getStatus().toString().equals("3")){
|
|
|
+ TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ String s = order.getId().toString();
|
|
|
+ if(s.length()>6){
|
|
|
+ s = s.substring(s.length()-6,s.length());
|
|
|
+ }
|
|
|
+ kindData.put("mealCode", s);
|
|
|
+ equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ esTOrderService.updateDataById(order);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ orderService.updateById(order);
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String huifuNotifyRefund(HttpServletRequest request) {
|
|
|
+ String respData = request.getParameter("resp_data");
|
|
|
+ JSONObject data = JSONObject.parseObject(respData);
|
|
|
+ String transStat = data.getString("trans_stat");
|
|
|
+ // 订单号
|
|
|
+ String sn = data.getString("org_req_seq_id");
|
|
|
+ if(StrUtil.hasEmpty(sn)) {
|
|
|
+ return "订单号为空!";
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TOrder::getSn,sn);
|
|
|
+ TOrder order = orderService.getOne(wrapper);
|
|
|
+ if(order == null) {
|
|
|
+ return "订单不存在";
|
|
|
+ }
|
|
|
+ if(HuifuConstant.TRANS_STAT_S.equals(transStat)) {
|
|
|
+ if(order.getRefundQuantity() < order.getProductNumber()) {
|
|
|
+ order.setStatus(1);
|
|
|
+ } else {
|
|
|
+ order.setStatus(3);
|
|
|
+ }
|
|
|
+ String refundOrderNo = data.getString("req_seq_id");
|
|
|
+ String ordAmt = data.getString("ord_amt");
|
|
|
+ String refundTrxNo = data.getString("hf_seq_id");
|
|
|
+ order.setRefundOrderNo(refundOrderNo);
|
|
|
+ order.setRefundDate(new Date());
|
|
|
+ order.setRefundTrxNo(refundTrxNo);
|
|
|
+ // 更改订单明细表
|
|
|
+ LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TOrderDetails::getOrderSn, sn);
|
|
|
+ // 处理退款中状态的明细
|
|
|
+ queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
|
|
|
+ List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
|
|
|
+ for (TOrderDetails tOrderDetail : tOrderDetails) {
|
|
|
+ Integer refundQuantity = tOrderDetail.getRefundQuantity();
|
|
|
+ Integer productNumber = tOrderDetail.getProductNumber();
|
|
|
+ if(refundQuantity < productNumber) {
|
|
|
+ // 部分退款
|
|
|
+ tOrderDetail.setRefundStatus("2");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ } else {
|
|
|
+ // 全部退款
|
|
|
+ tOrderDetail.setRefundStatus("3");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String acctSplitBunch = "";
|
|
|
+ // 部分退款或全部退款
|
|
|
+ TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
|
|
|
+ if(order.getRefundAmount() != null) {
|
|
|
+ // 退款总额
|
|
|
+ BigDecimal newRefundAmount = order.getRefundAmount().add(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ order.setRefundAmount(newRefundAmount);
|
|
|
+ // 如果小于订单金额
|
|
|
+ if(newRefundAmount.compareTo(order.getPrice()) < 0) {
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice().subtract(newRefundAmount), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ } else {
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice(), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ order.setRefundAmount(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP));
|
|
|
+ if(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP).compareTo(order.getPrice()) < 0) {
|
|
|
+ // 重新设置分销
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice()
|
|
|
+ .subtract(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP)), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ esTOrderService.updateDataById(order);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ orderService.updateById(order);
|
|
|
+ }
|
|
|
+ return "退款成功";
|
|
|
+ }
|
|
|
+ return "退款失败";
|
|
|
+ }
|
|
|
+
|
|
|
public void processRefund(Map<String, Object> bodyMap) {
|
|
|
String decrypt = wechatPayConfigService.decryptFromResource(bodyMap);
|
|
|
Gson gson = new Gson();
|
|
@@ -260,4 +465,332 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 汇聚分销明细
|
|
|
+ * @param proportion
|
|
|
+ * @param price
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONArray getAltInfo(TProportion proportion, BigDecimal price) {
|
|
|
+ // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
|
|
|
+ Integer type = proportion.getType();
|
|
|
+ // 汇聚分账参数
|
|
|
+ JSONArray altInfo = new JSONArray();
|
|
|
+
|
|
|
+ BigDecimal agencyProportion = null,
|
|
|
+ merchantProportion = null,
|
|
|
+ selfProportion = null;
|
|
|
+
|
|
|
+ BigDecimal agencyAmount = null;
|
|
|
+ BigDecimal merchantAmount = null;
|
|
|
+ BigDecimal selfAmount = null;
|
|
|
+
|
|
|
+ TJoinpayMch agencyMch = null;
|
|
|
+ TJoinpayMch merchantMch = null;
|
|
|
+ TJoinpayMch selfMch = null;
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject agencyJson = null;
|
|
|
+ JSONObject merchantJson = null;
|
|
|
+ JSONObject selfJson = null;
|
|
|
+
|
|
|
+ //取消平台扣手续费
|
|
|
+ BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal refuseAmount = new BigDecimal(0.00);
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ // 汇聚平台
|
|
|
+ selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+ if (selfMch == null) {
|
|
|
+ return altInfo;
|
|
|
+ }
|
|
|
+ selfJson = new JSONObject();
|
|
|
+ selfJson.put("altMchNo", selfMch.getAltMchNo());
|
|
|
+ selfJson.put("altAmount", selfAmount.toString());
|
|
|
+ selfJson.put("isGuar", "12");
|
|
|
+ altInfo.add(selfJson);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 一级分销
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 汇聚平台
|
|
|
+ agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
|
|
|
+ selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+ if (selfMch == null || agencyMch == null) {
|
|
|
+ return altInfo;
|
|
|
+ }
|
|
|
+ if(!(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null)){
|
|
|
+ // 一级分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAltMchNo());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+ }
|
|
|
+ // 商家自己分销获得利润
|
|
|
+ selfJson = new JSONObject();
|
|
|
+ selfJson.put("altMchNo", selfMch.getAltMchNo());
|
|
|
+ selfJson.put("altAmount", selfAmount.toString());
|
|
|
+ selfJson.put("isGuar", "12");
|
|
|
+ altInfo.add(selfJson);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 一级分销
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ // 二级分销
|
|
|
+ merchantProportion = proportion.getMerchantProportion();
|
|
|
+ // 三级分销
|
|
|
+// personageProportion = proportion.getPersonageProportion();
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 汇聚
|
|
|
+ agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
|
|
|
+
|
|
|
+ merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
|
|
|
+
|
|
|
+ selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+
|
|
|
+ if (selfMch == null || agencyMch == null || merchantMch == null) {
|
|
|
+ return altInfo;
|
|
|
+ }
|
|
|
+ if(!(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null)){
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAltMchNo());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(!(merchantProportion.compareTo(refuseAmount) == 0||merchantProportion==null)){
|
|
|
+ // 经销商分销获得利润
|
|
|
+ merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", merchantMch.getAltMchNo());
|
|
|
+ merchantJson.put("altAmount", merchantAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+ }
|
|
|
+ // 商家自己分销获得利润
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", selfMch.getAltMchNo());
|
|
|
+ merchantJson.put("altAmount", selfAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Iterator<Object> iterator = altInfo.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ JSONObject jsonObject = (JSONObject) iterator.next();
|
|
|
+ String altAmount = jsonObject.getString("altAmount");
|
|
|
+ if (altAmount.equals("0.00")) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return altInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 汇付分销明细
|
|
|
+ * @param proportion
|
|
|
+ * @param price
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price, String companyType) {
|
|
|
+
|
|
|
+ // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
|
|
|
+ Integer type = proportion.getType();
|
|
|
+ // 汇付分账明细参数
|
|
|
+ JSONObject acctSplitBunch = new JSONObject();
|
|
|
+ JSONArray acctInfos = new JSONArray();
|
|
|
+
|
|
|
+ BigDecimal adminProportion = null,
|
|
|
+ agencyProportion = null,
|
|
|
+ merchantProportion = null,
|
|
|
+ selfProportion = null;
|
|
|
+
|
|
|
+ BigDecimal agencyAmount = null;
|
|
|
+ BigDecimal merchantAmount = null;
|
|
|
+ BigDecimal selfAmount = null;
|
|
|
+ BigDecimal adminAmount = null;
|
|
|
+
|
|
|
+ THuifuMch agencyHuifu = null;
|
|
|
+ THuifuMch merchantHuifu = null;
|
|
|
+ THuifuMch selfHuifu = null;
|
|
|
+
|
|
|
+ JSONObject agencyJson = null;
|
|
|
+ JSONObject merchantJson = null;
|
|
|
+ JSONObject selfJson = null;
|
|
|
+ JSONObject adminJson = null;
|
|
|
+
|
|
|
+ //取消平台扣手续费
|
|
|
+ BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal refuseAmount = new BigDecimal(0.00);
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ // 公司平台分销
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 平台分销获得利润
|
|
|
+ adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 汇付平台
|
|
|
+ // 商家汇付信息:agencyHuifu
|
|
|
+ selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
|
|
|
+ if (selfHuifu == null) {
|
|
|
+ return acctSplitBunch;
|
|
|
+ }
|
|
|
+ // 公司平台分销
|
|
|
+ adminJson = new JSONObject();
|
|
|
+ adminJson.put("div_amt", adminAmount.toString());
|
|
|
+ // 判断为申泽还是七云
|
|
|
+ if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
|
|
|
+ } else {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
|
|
|
+ }
|
|
|
+ acctInfos.add(adminJson);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfJson = new JSONObject();
|
|
|
+ selfJson.put("div_amt", selfAmount.toString());
|
|
|
+ selfJson.put("huifu_id", selfHuifu.getHuifuId());
|
|
|
+ acctInfos.add(selfJson);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ // 公司平台分销
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 一级分销
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ // 平台分销获得利润
|
|
|
+ adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ // 汇付平台
|
|
|
+ selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
|
|
|
+ agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
|
|
|
+ if (selfHuifu == null || agencyHuifu == null) {
|
|
|
+ return acctSplitBunch;
|
|
|
+ }
|
|
|
+ // 公司平台分销
|
|
|
+ adminJson = new JSONObject();
|
|
|
+ adminJson.put("div_amt", adminAmount.toString());
|
|
|
+ // 判断为申泽还是七云
|
|
|
+ if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
|
|
|
+ } else {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
|
|
|
+ }
|
|
|
+ acctInfos.add(adminJson);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfJson = new JSONObject();
|
|
|
+ selfJson.put("div_amt", selfAmount.toString());
|
|
|
+ selfJson.put("huifu_id", selfHuifu.getHuifuId());
|
|
|
+ acctInfos.add(selfJson);
|
|
|
+ if(!(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null)){
|
|
|
+ // 一级分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("div_amt", agencyAmount.toString());
|
|
|
+ agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
|
|
|
+ acctInfos.add(agencyJson);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // 公司平台分销
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ // 商家自己的分销
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ // 一级分销
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ // 二级分销
|
|
|
+ merchantProportion = proportion.getMerchantProportion();
|
|
|
+ // 平台分销获得利润
|
|
|
+ adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
|
|
|
+ agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
|
|
|
+ merchantHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getMerchantId()));
|
|
|
+ if (selfHuifu == null || agencyHuifu == null || merchantHuifu == null) {
|
|
|
+ return acctSplitBunch;
|
|
|
+ }
|
|
|
+ // 公司平台分销
|
|
|
+ adminJson = new JSONObject();
|
|
|
+ adminJson.put("div_amt", adminAmount.toString());
|
|
|
+ // 判断为申泽还是七云
|
|
|
+ if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
|
|
|
+ } else {
|
|
|
+ adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
|
|
|
+ }
|
|
|
+ acctInfos.add(adminJson);
|
|
|
+ // 商家分销获得利润
|
|
|
+ selfJson = new JSONObject();
|
|
|
+ selfJson.put("div_amt", selfAmount.toString());
|
|
|
+ selfJson.put("huifu_id", selfHuifu.getHuifuId());
|
|
|
+ acctInfos.add(selfJson);
|
|
|
+ if(!(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null)){
|
|
|
+ // 一级分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("div_amt", agencyAmount.toString());
|
|
|
+ agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
|
|
|
+ acctInfos.add(agencyJson);
|
|
|
+ }
|
|
|
+ if(!(merchantProportion.compareTo(refuseAmount) == 0||merchantProportion==null)){
|
|
|
+ // 二级分销获得利润
|
|
|
+ merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("div_amt", merchantAmount.toString());
|
|
|
+ merchantJson.put("huifu_id", merchantHuifu.getHuifuId());
|
|
|
+ acctInfos.add(merchantJson);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 计算div_amt的总和
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
+ for (int i = 0; i < acctInfos.size(); i++) {
|
|
|
+ JSONObject jsonObject = acctInfos.getJSONObject(i);
|
|
|
+ BigDecimal divAmt = new BigDecimal(jsonObject.getString("div_amt"));
|
|
|
+ totalAmount = totalAmount.add(divAmt);
|
|
|
+ }
|
|
|
+ // 如果总和超过原本金额,调整div_amt
|
|
|
+ if (totalAmount.compareTo(price) > 0) {
|
|
|
+ BigDecimal diffAmount = totalAmount.subtract(price);
|
|
|
+ for (int i = 0; i < acctInfos.size(); i++) {
|
|
|
+ JSONObject jsonObject = acctInfos.getJSONObject(i);
|
|
|
+ String huifuId = jsonObject.getString("huifu_id");
|
|
|
+ if (huifuId.equals(HuifuConstant.SZ_DIV_HUIFU_ID) || huifuId.equals(HuifuConstant.SC_DIV_HUIFU_ID)) {
|
|
|
+ BigDecimal currentDivAmt = new BigDecimal(jsonObject.getString("div_amt"));
|
|
|
+ BigDecimal adjustedDivAmt = currentDivAmt.subtract(diffAmount).max(BigDecimal.ZERO);
|
|
|
+ jsonObject.put("div_amt", adjustedDivAmt.toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ acctSplitBunch.put("acct_infos", acctInfos);
|
|
|
+ return acctSplitBunch;
|
|
|
+ }
|
|
|
+
|
|
|
}
|