|
@@ -1,7 +1,5 @@
|
|
|
package com.caimei.modules.order.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei.modules.order.constant.Constant;
|
|
|
import com.caimei.modules.order.dao.NewOrderDao;
|
|
|
import com.caimei.modules.order.dao.NewShopOrderDao;
|
|
@@ -11,28 +9,19 @@ import com.caimei.modules.order.service.PayShopService;
|
|
|
import com.caimei.modules.order.util.OrderUtils;
|
|
|
import com.caimei.modules.shiro.entity.CmMallAdminUser;
|
|
|
import com.caimei.utils.*;
|
|
|
-import com.caimei.utils.payUtil.MyBeanUtils;
|
|
|
-import com.caimei.utils.payUtil.RSA;
|
|
|
-import com.caimei.utils.payUtil.SettlePostFormUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.*;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.IOException;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -42,12 +31,6 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class PayShopServiceImpl implements PayShopService {
|
|
|
|
|
|
- public static OkHttpClient client = new OkHttpClient.Builder()
|
|
|
- .connectTimeout(3, TimeUnit.SECONDS)
|
|
|
- .readTimeout(20, TimeUnit.SECONDS)
|
|
|
- .build();
|
|
|
-
|
|
|
-
|
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
|
@Resource
|
|
@@ -76,22 +59,20 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
public OrderPayShopDetail getPayShopDetail(Integer id) {
|
|
|
OrderPayShopDetail detail = payShopDao.findPayShopDetail(id);
|
|
|
List<NewShopOrder> shopOrders = payShopDao.findPayShopOrders(detail.getPayShopId());
|
|
|
- shopOrders.forEach(s -> {
|
|
|
- s.setShopOrderNos(payShopDao.findShopOrderNos(s.getOrderId()));
|
|
|
- s.setNewOrderProducts(payShopDao.findPayOrderProducts(s.getShopOrderId()));
|
|
|
- });
|
|
|
+ shopOrders.forEach(s -> orderUtils.getShouldPay(s));
|
|
|
detail.setShopOrders(shopOrders);
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public ResponseJson checkPass(Integer id, Integer payType, Integer passCode) throws Exception {
|
|
|
+ public ResponseJson checkPass(Integer id, Integer payType, Integer passCode, String reason) throws Exception {
|
|
|
OrderPayShop orderPayShop = new OrderPayShop();
|
|
|
CmMallAdminUser user = (CmMallAdminUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
orderPayShop.setReviewer(user.getId());
|
|
|
orderPayShop.setReviewTime(DateUtils.getDateTime());
|
|
|
orderPayShop.setPayShopId(id);
|
|
|
+ orderPayShop.setReason(reason);
|
|
|
if (1 == passCode) {
|
|
|
// 通过审核
|
|
|
List<OrderPayShopRecord> records = payShopDao.findPayShopRecords(id);
|
|
@@ -99,7 +80,7 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
//修改每一条子订单的已付款金额
|
|
|
for (OrderPayShopRecord record : records) {
|
|
|
NewShopOrder shopOrder = newShopOrderDao.get(record.getShopOrderId());
|
|
|
-
|
|
|
+ orderUtils.getShouldPay(shopOrder);
|
|
|
// 本次付款金额 + 付采美 + 原来已经付过的金额
|
|
|
BigDecimal payedFee = MathUtil.add(MathUtil.add(record.getPayAmount(), record.getPayAmount()), shopOrder.getPayedShopAmount());
|
|
|
// 总共要付的金额
|
|
@@ -158,6 +139,7 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
payShopDao.insertPayShop(payShop);
|
|
|
|
|
|
payShopDao.updateShopAccount(payShop.getShopId(), payShop.getBankAccount(), payShop.getBankAccountName(), payShop.getBankName());
|
|
|
+ payShopDao.updateCmShopAccount(payShop.getCmBankAccount(), payShop.getCmBankAccountName(), payShop.getCmBankName());
|
|
|
shopOrders.forEach(s -> {
|
|
|
OrderPayShopRecord record = new OrderPayShopRecord();
|
|
|
record.setShopId(payShop.getShopId());
|
|
@@ -175,23 +157,25 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
// 运费付款单作用不明,暂时取消生成
|
|
|
|
|
|
} else {
|
|
|
- //修改
|
|
|
- if (1 == payShop.getStatus()) {
|
|
|
- throw new Exception("该付款单已被审核,无需再申请付款");
|
|
|
- }
|
|
|
- if (2 == payShop.getStatus()) {
|
|
|
- //付款记录 修改状态
|
|
|
- payShopDao.updatePayRecordById(2, payShop.getPayShopId());
|
|
|
- //子订单退出付款状态
|
|
|
- newShopOrderDao.inPaying(payShop.getPayShopId());
|
|
|
- payShop.setReviewer(null);
|
|
|
- payShop.setReviewTime(null);
|
|
|
- payShop.setReason(null);
|
|
|
- payShop.setStatus(0);
|
|
|
+ if (null == payShop.getOperateMode()) {
|
|
|
+ //修改
|
|
|
+ if (1 == payShop.getStatus()) {
|
|
|
+ return ResponseJson.error("该付款单已被审核,无需再申请付款");
|
|
|
+ }
|
|
|
+ if (2 == payShop.getStatus()) {
|
|
|
+ //付款记录 修改状态
|
|
|
+ payShopDao.updatePayRecordById(2, payShop.getPayShopId());
|
|
|
+ //子订单退出付款状态
|
|
|
+ newShopOrderDao.inPaying(payShop.getPayShopId());
|
|
|
+ payShop.setReviewer(null);
|
|
|
+ payShop.setReviewTime(null);
|
|
|
+ payShop.setReason(null);
|
|
|
+ payShop.setStatus(0);
|
|
|
+ }
|
|
|
+ shopOrders.forEach(s -> {
|
|
|
+ payShopDao.updateRecordById(s.getShopOrderId(), s.getWaitPayShop(), s.getWaitPayCmAmount(), payShop.getPayShopId());
|
|
|
+ });
|
|
|
}
|
|
|
- shopOrders.forEach(s -> {
|
|
|
- payShopDao.updateRecordById(s.getShopOrderId(), s.getWaitPayShop(), s.getWaitPayCmAmount(), payShop.getPayShopId());
|
|
|
- });
|
|
|
payShopDao.updatePayShopDetail(payShop);
|
|
|
}
|
|
|
return ResponseJson.success(payShop.getPayShopId());
|
|
@@ -206,6 +190,7 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
}
|
|
|
newShopOrderDao.outPaying(id);
|
|
|
payShopDao.deleteRecords(id);
|
|
|
+ payShopDao.deletePayShop(id);
|
|
|
return ResponseJson.success();
|
|
|
}
|
|
|
|
|
@@ -347,66 +332,7 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
*/
|
|
|
splitBillDetail.removeIf(sp -> sp.getSubUserNo().equals(shopOrder.getSplitCode()));
|
|
|
if (null != splitBillRules && splitBillRules.size() > 0) {
|
|
|
- //第三方分账接口
|
|
|
- try {
|
|
|
- AccountPayOrder accountPayOrder = new AccountPayOrder();
|
|
|
- accountPayOrder.setP1_bizType("AccountPaySub");
|
|
|
- accountPayOrder.setP2_signType("MD5");
|
|
|
- String format1 = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS").format(new Date());
|
|
|
- accountPayOrder.setP3_timestamp(format1);
|
|
|
- String substring = format1.substring(20);
|
|
|
- // fz+当前微秒时间+原唯一订单号
|
|
|
- accountPayOrder.setP4_orderId("FZ" + substring + orderRelation.getOrderRequestNo());
|
|
|
- //付款账户子订单绑定商户号
|
|
|
- accountPayOrder.setP5_customerNumber(shopOrder.getSplitCode());
|
|
|
- AccountPayOrder.AccountPayOrderExt accountPayOrderExt = new AccountPayOrder.AccountPayOrderExt();
|
|
|
- //收款账户商编 填写splitBillRules时候不填写MerchantNo,Amount并且即使填写这两个参数不生效!!
|
|
|
- //accountPayOrderExt.setInMerchantNo(splitMoneyVo.getName());
|
|
|
- //accountPayOrderExt.setAmount(splitMoneyVo.getSplitMoney());
|
|
|
- accountPayOrderExt.setOrderType(AccountPayOrderType.TRANSFER);
|
|
|
- accountPayOrderExt.setServerCallbackUrl(Constant.prodSplit);
|
|
|
- accountPayOrderExt.setGoodsName("分账");
|
|
|
- if (null != splitBillRules && splitBillRules.size() > 0) {
|
|
|
- accountPayOrderExt.setSplitBillRules(splitBillRules);
|
|
|
- }
|
|
|
- String ext = JSON.toJSONString(accountPayOrderExt);
|
|
|
- log.info("分账规则串json串:" + ext);
|
|
|
- accountPayOrder.setP6_ext(ext);
|
|
|
- // 生成签名
|
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
- builder.append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP1_bizType()).append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP2_signType()).append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP3_timestamp()).append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP4_orderId()).append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP5_customerNumber()).append(Constant.SPLIT)
|
|
|
- .append(accountPayOrder.getP6_ext()).append(Constant.SPLIT)
|
|
|
- .append(Constant.XUNI);
|
|
|
- String sign = Disguiser.disguiseMD5(builder.toString().trim());
|
|
|
- Map<String, String> bean = convertBean(accountPayOrder);
|
|
|
- log.info("--------------------> 发送分账参数: " + bean);
|
|
|
- Map<String, String> map = postForm(bean, Constant.FZ, sign, Map.class);
|
|
|
- log.info("----------------分账返回数据: " + map.toString());
|
|
|
- if (map != null) {
|
|
|
- String code = map.get("rt5_retCode");
|
|
|
- if (!"0000".equals(code)) {
|
|
|
- String msg = map.get("rt6_retMsg");
|
|
|
- log.info("【手动分账】>>>>>>>>>>手动分账失败>>>>>>>msg:" + msg);
|
|
|
- } else {
|
|
|
- for (SplitAccountPo splitAccount : splitBillDetail) {
|
|
|
- splitAccount.setMbOrderId(orderRelation.getMbOrderId());
|
|
|
- splitAccount.setOrderRequestNo(orderRelation.getOrderRequestNo());
|
|
|
- splitAccount.setPayStatus(1);
|
|
|
- // 保存分账详情
|
|
|
- newOrderDao.insertSplitAccount(splitAccount);
|
|
|
- }
|
|
|
- redisService.remove("XSFZMDS");
|
|
|
- log.info("【手动分账】>>>>>>>>>>此订单分账结束");
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("【手动分账】>>>>>>>>>>错误信息", e);
|
|
|
- }
|
|
|
+ orderUtils.splitAccount(splitBillRules, orderRelation.getOrderRequestNo(), orderRelation.getMbOrderId(), shopOrder, splitBillDetail);
|
|
|
} else {
|
|
|
// 没有佣金分账,全是成本,本笔交易已分帐
|
|
|
newOrderDao.updateBySplitStatus(orderRelation.getMbOrderId());
|
|
@@ -452,10 +378,7 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
public OrderPayShopDetail applyPayList(List<Integer> shopOrderIds) {
|
|
|
OrderPayShopDetail detail = new OrderPayShopDetail();
|
|
|
List<NewShopOrder> shopOrders = payShopDao.findPayShopOrderByShopOrderIds(shopOrderIds);
|
|
|
- shopOrders.forEach(s -> {
|
|
|
- s.setShopOrderNos(payShopDao.findShopOrderNos(s.getOrderId()));
|
|
|
- s.setNewOrderProducts(payShopDao.findPayOrderProducts(s.getShopOrderId()));
|
|
|
- });
|
|
|
+ shopOrders.forEach(s -> orderUtils.getShouldPay(s));
|
|
|
detail.setShopId(shopOrders.get(0).getShopId());
|
|
|
detail.setShopName(shopOrders.get(0).getShopName());
|
|
|
detail.setShopOrders(shopOrders);
|
|
@@ -466,7 +389,8 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
public ResponseJson<PageInfo<NewOrder>> orderPayInfoList(OrderPayShop orderPayShop, Integer pageNum, Integer pageSize) {
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
List<NewOrder> orderList = newOrderDao.findListByPayShop(orderPayShop);
|
|
|
- return null;
|
|
|
+ orderUtils.setOrderListValue(orderList);
|
|
|
+ return ResponseJson.success(new PageInfo<NewOrder>(orderList));
|
|
|
}
|
|
|
|
|
|
public void setSplitAccountDetail(NewShopOrder shopOrder, PayParamBo payParam, List<SplitAccountPo> list) {
|
|
@@ -564,70 +488,4 @@ public class PayShopServiceImpl implements PayShopService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public Map<String, String> convertBean(Object bean) {
|
|
|
- Class clazz = bean.getClass();
|
|
|
- Field[] fields = clazz.getDeclaredFields();
|
|
|
- for (Field f : fields) {
|
|
|
- f.setAccessible(true);
|
|
|
- }
|
|
|
- try {
|
|
|
- Map<String, String> retMap = new LinkedHashMap<>();
|
|
|
- for (Field f : fields) {
|
|
|
- String key = f.toString().substring(f.toString().lastIndexOf(".") + 1);
|
|
|
- Object value = f.get(bean);
|
|
|
- if (value == null) {
|
|
|
- value = "";
|
|
|
- }
|
|
|
- retMap.put(key, (String) value);
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("分账", e);
|
|
|
- throw new IllegalStateException("分账异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public <T> T postForm(Map<String, String> params, String url, String sign, Class<T> clazz) {
|
|
|
- FormBody.Builder builder = new FormBody.Builder();
|
|
|
- for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
- builder.add(entry.getKey(), entry.getValue());
|
|
|
- }
|
|
|
- builder.add("sign", sign);
|
|
|
-
|
|
|
- Request request = new Request.Builder() // okHttp post
|
|
|
- .url(url)
|
|
|
- .post(builder.build())
|
|
|
- .build();
|
|
|
-
|
|
|
- Response response = null;
|
|
|
- try {
|
|
|
- response = client.newCall(request).execute();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new IllegalStateException("请求出错", e);
|
|
|
- }
|
|
|
- if (!response.isSuccessful()) {
|
|
|
- try {
|
|
|
- log.info(response.body().string());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- throw new RuntimeException("请求失败了: http response code: " + response.code());
|
|
|
- }
|
|
|
-
|
|
|
- ResponseBody body = response.body();
|
|
|
- String content = null;
|
|
|
- try {
|
|
|
- content = body.string();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new IllegalStateException("IO异常", e);
|
|
|
- }
|
|
|
- JSONObject res = JSON.parseObject(content);
|
|
|
- if (!res.getBooleanValue("rt4_success")) {
|
|
|
- log.error("error: " + res.getString("rt6_retMsg"));
|
|
|
- }
|
|
|
- /** rt4_success 为 true,需验签 **/
|
|
|
- return res.toJavaObject(clazz);
|
|
|
- }
|
|
|
-
|
|
|
}
|