|
|
@@ -7,12 +7,13 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.service.impl.SmsServiceImpl;
|
|
|
import com.fs.common.utils.CloudHostUtils;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.domain.CompanyVoiceCaller;
|
|
|
@@ -21,6 +22,7 @@ import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.vo.QwIpadTotalVo;
|
|
|
import com.fs.company.vo.RedPacketMoneyVO;
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
import com.fs.course.dto.BatchSendCourseAllDTO;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
@@ -58,7 +60,10 @@ import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
|
|
|
import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
import com.fs.hisStore.service.IFsStorePaymentScrmService;
|
|
|
import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
|
|
|
+import com.fs.huifuPay.domain.HuifuOrderConfirm;
|
|
|
+import com.fs.huifuPay.domain.HuifuOrderConfirmResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
|
|
|
+import com.fs.huifuPay.sdk.opps.core.utils.DateTools;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.im.dto.*;
|
|
|
import com.fs.im.service.IImService;
|
|
|
@@ -87,6 +92,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -243,6 +249,14 @@ public class Task {
|
|
|
private FsUserCompanyUserMapper fsUserCompanyUserMapper;
|
|
|
@Autowired
|
|
|
private FsStoreOrderScrmMapper fsStoreOrderScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsStorePaymentMapper fsStorePaymentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsSubMerchantMapper fsSubMerchantMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsShareAmountDetailService shareAmountDetailService;
|
|
|
|
|
|
@Autowired
|
|
|
private ConversationSyncService syncService;
|
|
|
@@ -2019,4 +2033,131 @@ public class Task {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ public void shareAmount(){
|
|
|
+ List<FsStorePayment> payments = fsStorePaymentMapper.selectSharePaymentList();
|
|
|
+ if (CollectionUtil.isEmpty(payments)) return;
|
|
|
+ logger.info("开始处理分享金额");
|
|
|
+ for (FsStorePayment storePayment : payments) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ //查询订单确认金额
|
|
|
+ V2TradePaymentScanpayQueryRequest request = new V2TradePaymentScanpayQueryRequest();
|
|
|
+ request.setOrgReqDate(DateTools.formatYYYYMMDD(storePayment.getPayTime()));
|
|
|
+ request.setOrgReqSeqId(storePayment.getShareCode()+"-"+storePayment.getPayCode());
|
|
|
+ request.setAppId(storePayment.getAppId());
|
|
|
+ HuiFuQueryOrderResult queryOrderResult = huiFuService.queryOrder(request);
|
|
|
+ logger.info("汇付订单查询返回:{}" , queryOrderResult);
|
|
|
+ if (queryOrderResult != null && "00000000".equals(queryOrderResult.getResp_code())) {
|
|
|
+ //未开启延迟支付的跳出当前循环 执行下次循环
|
|
|
+ if (queryOrderResult.getDelay_acct_flag().equals("N")) {
|
|
|
+ FsStorePayment mapPayment = new FsStorePayment();
|
|
|
+ mapPayment.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mapPayment.setIsShare(0);
|
|
|
+ fsStorePaymentService.updateFsStorePayment(mapPayment);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ logger.info("分账订单号:{}",storePayment.getBusinessCode());
|
|
|
+
|
|
|
+ //待确认金额
|
|
|
+ BigDecimal unConfirmAmt = new BigDecimal(queryOrderResult.getUnconfirm_amt());
|
|
|
+ //分账金额
|
|
|
+ BigDecimal divAmount = null;
|
|
|
+ //默认全部进入收款主账户
|
|
|
+ BigDecimal mainAmount = unConfirmAmt;
|
|
|
+
|
|
|
+
|
|
|
+ FsSubMerchant fsSubMerchant = null;
|
|
|
+ FsPackageOrder order = null;
|
|
|
+
|
|
|
+ //是否分账到合作人
|
|
|
+ boolean isDiv = false;
|
|
|
+ HuifuOrderConfirm confirm = new HuifuOrderConfirm();
|
|
|
+ confirm.setAppId(storePayment.getAppId());
|
|
|
+
|
|
|
+ //支付金额大于等于0.1的进行分账 最低分账金额为0.1
|
|
|
+ if (storePayment.getPayMoney().compareTo(new BigDecimal("0.1")) > -1) {
|
|
|
+ //分账订单
|
|
|
+ order = fsPackageOrderMapper.selectFsPackageOrderByOrderSn(storePayment.getBusinessCode());
|
|
|
+ if (order != null && order.getPackageId() != null && order.getCompanyId() != null) {
|
|
|
+ //获取套餐包信息
|
|
|
+ FsPackage fsPackage = fsPackageMapper.selectFsPackageByPackageId(order.getPackageId());
|
|
|
+ //公司信息
|
|
|
+ Company company = companyMapper.selectCompanyById(order.getCompanyId());
|
|
|
+ //分账比列大于0且公司有分账商户
|
|
|
+ if (fsPackage != null && (fsPackage.getShareRate() != null && fsPackage.getShareRate() > 0)
|
|
|
+ && company != null && company.getSubMerchantId() != null) {
|
|
|
+ //分账商户
|
|
|
+ fsSubMerchant = fsSubMerchantMapper.selectFsSubMerchantById(company.getSubMerchantId());
|
|
|
+ if (fsSubMerchant != null && fsSubMerchant.getMerchantNo() != null) {
|
|
|
+ //金额全部进入分账商户 分账比列为100
|
|
|
+ if (fsPackage.getShareRate() == 100) {
|
|
|
+ divAmount = unConfirmAmt;
|
|
|
+ mainAmount = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ //金额进行分账
|
|
|
+ divAmount = unConfirmAmt.multiply(BigDecimal.valueOf(fsPackage.getShareRate())).divide(new BigDecimal(100));
|
|
|
+ mainAmount = unConfirmAmt.subtract(divAmount);
|
|
|
+ }
|
|
|
+ isDiv = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("开始确认订单分账..........");
|
|
|
+ String orderCode = OrderCodeUtils.getOrderSn();
|
|
|
+ if (StringUtils.isEmpty(orderCode)) {
|
|
|
+ throw new CustomException("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ confirm.setReqSeqId(orderCode);
|
|
|
+ if (isDiv) {
|
|
|
+ //合作人分账金额和商户号
|
|
|
+ confirm.setDivAmt(divAmount);
|
|
|
+ confirm.setDivHfId(fsSubMerchant.getMerchantNo());
|
|
|
+ //分账明细数据
|
|
|
+ FsShareAmountDetail shareAmountDetail = new FsShareAmountDetail();
|
|
|
+ shareAmountDetail.setShareAmount(divAmount);
|
|
|
+ shareAmountDetail.setMerchantId(fsSubMerchant.getId());
|
|
|
+ shareAmountDetail.setOrderCode(order.getOrderSn());
|
|
|
+ shareAmountDetail.setOrderId(order.getOrderId());
|
|
|
+ //添加分账明细
|
|
|
+ shareAmountDetailService.insertFsShareAmountDetail(shareAmountDetail);
|
|
|
+ }
|
|
|
+ confirm.setMainDivAmt(mainAmount);
|
|
|
+ confirm.setOrgReqDate(queryOrderResult.getOrg_req_date());
|
|
|
+ confirm.setOrgReqSeqId(queryOrderResult.getOrg_req_seq_id());
|
|
|
+ confirm.setMainHfId(queryOrderResult.getHuifu_id());
|
|
|
+ confirm.setTotalAmount(storePayment.getPayMoney());
|
|
|
+
|
|
|
+ //执行分账
|
|
|
+ HuifuOrderConfirmResult result = huiFuService.confirmOrder(confirm);
|
|
|
+ if (result != null && result.getResp_code().equals("00000000") && (result.getTrans_stat().equals("S") || result.getTrans_stat().equals("P"))) {
|
|
|
+ logger.info("分账成功,订单号:{}",storePayment.getBusinessCode());
|
|
|
+ FsStorePayment mapPayment = new FsStorePayment();
|
|
|
+ //分账标识
|
|
|
+ mapPayment.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mapPayment.setShareStatus(1);
|
|
|
+ mapPayment.setShareDate(result.getReq_date());
|
|
|
+ mapPayment.setShareCode(result.getReq_seq_id());
|
|
|
+ logger.info("更新支付记录");
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mapPayment);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("分账失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (queryOrderResult != null) {
|
|
|
+ throw new CustomException(queryOrderResult.getResp_desc());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ FsStorePayment mapPayment = new FsStorePayment();
|
|
|
+ //分账标识
|
|
|
+ mapPayment.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mapPayment.setShareStatus(1);
|
|
|
+ mapPayment.setShareCode(e.getMessage());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mapPayment);
|
|
|
+ logger.info("分账失败,订单号:{},原因:{}", storePayment.getBusinessCode(),e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|