Merge branch 'master' of https://gitee.com/op-souls/ghy-all
This commit is contained in:
commit
fa7c2765ac
|
|
@ -100,7 +100,7 @@ public class OrderController extends BaseController {
|
||||||
// 计算剩余未分配的商品数量
|
// 计算剩余未分配的商品数量
|
||||||
for (OrderGoods detailGoods : orderDetailGoodsList) {
|
for (OrderGoods detailGoods : orderDetailGoodsList) {
|
||||||
for(OrderGoods masterGoods : orderGoodsList){
|
for(OrderGoods masterGoods : orderGoodsList){
|
||||||
if(masterGoods.getGoodsStandardId() == detailGoods.getGoodsStandardId()){
|
if(Objects.equals(masterGoods.getGoodsStandardId(), detailGoods.getGoodsStandardId())){
|
||||||
masterGoods.setGoodsNum(masterGoods.getGoodsNum() - detailGoods.getGoodsNum());
|
masterGoods.setGoodsNum(masterGoods.getGoodsNum() - detailGoods.getGoodsNum());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +297,7 @@ public class OrderController extends BaseController {
|
||||||
*/
|
*/
|
||||||
private void createFinancialDetail(Long deptGoodsCategoryId, Long deptId, Customer customer, BigDecimal payMoney, FinancialMaster financialMaster) {
|
private void createFinancialDetail(Long deptGoodsCategoryId, Long deptId, Customer customer, BigDecimal payMoney, FinancialMaster financialMaster) {
|
||||||
// 是否为0元购 是的话下面就不用多级分销了
|
// 是否为0元购 是的话下面就不用多级分销了
|
||||||
if (BigDecimal.ZERO.equals(payMoney)) {
|
if (BigDecimal.ZERO.compareTo(payMoney) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,20 @@ public class PayController {
|
||||||
private FinancialMasterService financialMasterService;
|
private FinancialMasterService financialMasterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撤销支付
|
* 确认支付
|
||||||
*
|
*
|
||||||
* @param orderMasterId 主订单ID
|
* @param orderMasterId 主订单ID
|
||||||
* @param refundAmt 退款金额 保留两位小数
|
*/
|
||||||
|
public AjaxResult confirm(Long orderMasterId) throws BaseAdaPayException {
|
||||||
|
orderMasterService.confirm(orderMasterId);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起退款
|
||||||
|
*
|
||||||
|
* @param orderMasterId 主订单ID
|
||||||
|
* @param refundAmt 退款金额 保留两位小数
|
||||||
*/
|
*/
|
||||||
@PostMapping("refund")
|
@PostMapping("refund")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|
@ -48,12 +58,12 @@ public class PayController {
|
||||||
OrderMaster orderMaster = orderMasterService.selectById(orderMasterId);
|
OrderMaster orderMaster = orderMasterService.selectById(orderMasterId);
|
||||||
Assert.notNull(orderMaster, "找不到对应的订单");
|
Assert.notNull(orderMaster, "找不到对应的订单");
|
||||||
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMasterId);
|
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMasterId);
|
||||||
|
Assert.notNull(financialMaster, "找不到订单");
|
||||||
PaymentDTO payment = financialMasterService.selectPaymentById(financialMaster.getPaymentId());
|
PaymentDTO payment = financialMasterService.selectPaymentById(financialMaster.getPaymentId());
|
||||||
Assert.notNull(payment, "找不到支付记录");
|
Assert.notNull(payment, "找不到支付记录");
|
||||||
Assert.notNull(financialMaster, "找不到订单");
|
|
||||||
Assert.isTrue(financialMaster.getPayStatus() == 1, "订单未支付");
|
Assert.isTrue(financialMaster.getPayStatus() == 1, "订单未支付");
|
||||||
Assert.hasText(financialMaster.getPaymentId(), "找不到订单的支付记录,请联系管理员");
|
Assert.hasText(financialMaster.getPaymentId(), "找不到订单的支付记录,请联系管理员");
|
||||||
JSONObject response = adapayService.refund(orderMaster.getDeptId(), financialMaster.getPaymentId(),payment.getOrderNo(), refundAmt);
|
JSONObject response = adapayService.refund(orderMaster.getDeptId(), financialMaster.getPaymentId(), payment.getOrderNo(), refundAmt);
|
||||||
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
|
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
package com.ghy.web.controller.pay;
|
package com.ghy.web.controller.pay;
|
||||||
|
|
||||||
import com.ghy.common.adapay.model.DivMember;
|
import com.ghy.common.adapay.model.DivMember;
|
||||||
import com.ghy.common.json.JSONObject;
|
|
||||||
import com.ghy.payment.domain.FinancialMaster;
|
|
||||||
import com.ghy.payment.service.AdapayService;
|
|
||||||
import com.ghy.common.adapay.model.PayParam;
|
import com.ghy.common.adapay.model.PayParam;
|
||||||
import com.ghy.common.adapay.model.WxpayExpend;
|
import com.ghy.common.adapay.model.WxpayExpend;
|
||||||
import com.ghy.common.config.WxConfig;
|
import com.ghy.common.config.WxConfig;
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.json.JSONObject;
|
||||||
import com.ghy.common.utils.ExceptionUtil;
|
import com.ghy.common.utils.ExceptionUtil;
|
||||||
import com.ghy.order.domain.OrderMaster;
|
import com.ghy.order.domain.OrderMaster;
|
||||||
import com.ghy.order.service.OrderMasterService;
|
import com.ghy.order.service.OrderMasterService;
|
||||||
|
import com.ghy.payment.domain.FinancialMaster;
|
||||||
|
import com.ghy.payment.service.AdapayService;
|
||||||
import com.ghy.payment.service.FinancialMasterService;
|
import com.ghy.payment.service.FinancialMasterService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -64,11 +64,8 @@ public class WxPayController extends BaseController {
|
||||||
String openId = request.getHeader("code");
|
String openId = request.getHeader("code");
|
||||||
String orderMasterCode = request.getHeader("orderMasterCode");
|
String orderMasterCode = request.getHeader("orderMasterCode");
|
||||||
OrderMaster orderMaster = orderMasterService.selectByCode(orderMasterCode);
|
OrderMaster orderMaster = orderMasterService.selectByCode(orderMasterCode);
|
||||||
|
Assert.notNull(orderMaster, "找不到对应的订单");
|
||||||
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
|
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
|
||||||
if (orderMaster == null) {
|
|
||||||
return AjaxResult.error("订单不存在");
|
|
||||||
}
|
|
||||||
//调用adapay微信公众号支付.
|
//调用adapay微信公众号支付.
|
||||||
WxpayExpend expend = new WxpayExpend();
|
WxpayExpend expend = new WxpayExpend();
|
||||||
expend.setOpenId(openId);
|
expend.setOpenId(openId);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.ghy.web.controller.tool;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ghy.common.config.BaiduConfig;
|
||||||
|
import com.ghy.common.core.controller.BaseController;
|
||||||
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.utils.ExceptionUtil;
|
||||||
|
import com.ghy.common.utils.http.HttpUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百度地图逆解析
|
||||||
|
* @author clunt
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/tool/baidu")
|
||||||
|
public class BaiduController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BaiduConfig baiduConfig;
|
||||||
|
|
||||||
|
@PostMapping("/getLocation")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult getLocationByLot(@RequestBody JSONObject jsonObject){
|
||||||
|
try {
|
||||||
|
String location = jsonObject.getString("location");
|
||||||
|
String url = baiduConfig.getUrl().replace("#AK#", baiduConfig.getAk()) + location;
|
||||||
|
String result = HttpUtils.sendGet(url);
|
||||||
|
return AjaxResult.success(result);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -125,3 +125,8 @@ jim:
|
||||||
appKey: ''
|
appKey: ''
|
||||||
masterSecret: ''
|
masterSecret: ''
|
||||||
maxRetryTimes: ''
|
maxRetryTimes: ''
|
||||||
|
|
||||||
|
# 百度地图应用api
|
||||||
|
baidu:
|
||||||
|
ak: 'ZQTgMW7W0GTuE7Ripb0HDp5TqRaOI6PZ'
|
||||||
|
url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=#AK#&output=json&coordtype=wgs84ll&location='
|
||||||
|
|
@ -14,6 +14,7 @@ public class PaymentDTO extends Payment {
|
||||||
*/
|
*/
|
||||||
@JSONField(name = "party_order_id")
|
@JSONField(name = "party_order_id")
|
||||||
private String partyOrderId;
|
private String partyOrderId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前交易状态
|
* 当前交易状态
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.ghy.common.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百度地图应用ak配置
|
||||||
|
* @author clunt
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "baidu")
|
||||||
|
public class BaiduConfig {
|
||||||
|
|
||||||
|
private String ak;
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public String getAk() {
|
||||||
|
return ak;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAk(String ak) {
|
||||||
|
this.ak = ak;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.ghy.common.enums;
|
||||||
|
|
||||||
|
public enum AdapayOrderType {
|
||||||
|
|
||||||
|
PAY("PAY", "支付"),
|
||||||
|
DRAW_CASH("DRAW_CASH", "提现"),
|
||||||
|
PAYMENT_CONFIRM("PAYMENT_CONFIRM", "确认支付");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
AdapayOrderType(String code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,13 +2,14 @@ package com.ghy.common.enums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 财务细单类型.所有类型合起来等于主订单实付金额
|
* 财务细单类型.所有类型合起来等于主订单实付金额
|
||||||
|
*
|
||||||
* @author clunt
|
* @author clunt
|
||||||
*/
|
*/
|
||||||
public enum FinancialDetailType {
|
public enum FinancialDetailType {
|
||||||
|
|
||||||
ORDER_FEE(0, "订单金额"),
|
ORDER_FEE(0, "结单金额"),
|
||||||
WORKER_FEE(1,"大师傅/店铺提成金额"),
|
WORKER_FEE(1, "大师傅/店铺提成金额"),
|
||||||
PLATFORM_FEE(2,"平台提成金额"),
|
PLATFORM_FEE(2, "平台提成金额"),
|
||||||
PLACE_FEE(3, "分销金额,可能存在多级"),
|
PLACE_FEE(3, "分销金额,可能存在多级"),
|
||||||
RETURN_FEE(4, "退款金额");
|
RETURN_FEE(4, "退款金额");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,24 @@
|
||||||
package com.ghy.common.utils;
|
package com.ghy.common.utils;
|
||||||
|
|
||||||
|
import com.ghy.common.enums.AdapayOrderType;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HH 2022/5/21
|
* @author HH 2022/5/21
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AdapayUtils {
|
public class AdapayUtils {
|
||||||
|
|
||||||
|
private static final AtomicLong INDEX = new AtomicLong(1L);
|
||||||
|
private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成 Adapay member_id
|
* 生成 Adapay member_id
|
||||||
*
|
*
|
||||||
|
|
@ -33,4 +43,19 @@ public class AdapayUtils {
|
||||||
return String.format("W%dD%d", workerId, deptId);
|
return String.format("W%dD%d", workerId, deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把BigDecimal格式的价格转为保留两位小数的String
|
||||||
|
*
|
||||||
|
* @param b BigDecimal
|
||||||
|
* @return 保留两位小数的String
|
||||||
|
*/
|
||||||
|
public static String bigDecimalToString(BigDecimal b) {
|
||||||
|
return b.setScale(2, RoundingMode.UNNECESSARY).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static String createOrderNo(AdapayOrderType type) {
|
||||||
|
INDEX.compareAndSet(9999L, 1L);
|
||||||
|
return type.getCode() + DATETIME_FORMATTER.format(LocalDateTime.now()) + INDEX.getAndIncrement();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ghy.order.mapper;
|
package com.ghy.order.mapper;
|
||||||
|
|
||||||
import com.ghy.order.domain.OrderGoods;
|
|
||||||
import com.ghy.order.domain.OrderMaster;
|
import com.ghy.order.domain.OrderMaster;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
|
@ -34,7 +33,7 @@ public interface OrderMasterMapper {
|
||||||
/**
|
/**
|
||||||
* @param orderMaster 主订单入参
|
* @param orderMaster 主订单入参
|
||||||
* @return 满足条件的主单单量
|
* @return 满足条件的主单单量
|
||||||
* */
|
*/
|
||||||
Long countOrderMasterList(OrderMaster orderMaster);
|
Long countOrderMasterList(OrderMaster orderMaster);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,4 +63,13 @@ public interface OrderMasterMapper {
|
||||||
* @return 主订单信息
|
* @return 主订单信息
|
||||||
*/
|
*/
|
||||||
OrderMaster selectByCode(String orderMasterCode);
|
OrderMaster selectByCode(String orderMasterCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改主订单状态
|
||||||
|
*
|
||||||
|
* @param orderMasterId 主订单ID
|
||||||
|
* @param orderStatus 主订单状态码
|
||||||
|
* @return 0失败 1成功
|
||||||
|
*/
|
||||||
|
int updateStatus(@Param("orderMasterId") Long orderMasterId, @Param("orderStatus") int orderStatus);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ghy.order.service;
|
||||||
|
|
||||||
import com.ghy.order.domain.OrderMaster;
|
import com.ghy.order.domain.OrderMaster;
|
||||||
import com.ghy.order.request.AppOrderRequest;
|
import com.ghy.order.request.AppOrderRequest;
|
||||||
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -37,7 +38,7 @@ public interface OrderMasterService {
|
||||||
/**
|
/**
|
||||||
* @param orderMaster 主订单入参
|
* @param orderMaster 主订单入参
|
||||||
* @return 满足条件的主单单量
|
* @return 满足条件的主单单量
|
||||||
* */
|
*/
|
||||||
Long countOrderMasterList(OrderMaster orderMaster);
|
Long countOrderMasterList(OrderMaster orderMaster);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,4 +69,28 @@ public interface OrderMasterService {
|
||||||
*/
|
*/
|
||||||
String checkOrderMasterCodeUnique(OrderMaster orderMaster);
|
String checkOrderMasterCodeUnique(OrderMaster orderMaster);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改主订单状态
|
||||||
|
*
|
||||||
|
* @param orderMasterId 主订单ID
|
||||||
|
* @param status 主订单状态码
|
||||||
|
* @return 0失败 1成功
|
||||||
|
*/
|
||||||
|
int updateStatus(Long orderMasterId, int status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认支付订单
|
||||||
|
*
|
||||||
|
* @param orderMasterId 主订单ID
|
||||||
|
*/
|
||||||
|
void confirm(Long orderMasterId) throws BaseAdaPayException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起提现
|
||||||
|
*
|
||||||
|
* @param deptId 公司ID
|
||||||
|
* @param memberId Adapay实名账户ID
|
||||||
|
* @param amount 提现金额
|
||||||
|
*/
|
||||||
|
void drawCash(Long deptId, String memberId, String amount) throws BaseAdaPayException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,35 @@
|
||||||
package com.ghy.order.service.impl;
|
package com.ghy.order.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ghy.common.adapay.model.AdapayStatusEnum;
|
||||||
|
import com.ghy.common.adapay.model.DivMember;
|
||||||
|
import com.ghy.common.adapay.model.PaymentDTO;
|
||||||
import com.ghy.common.constant.UserConstants;
|
import com.ghy.common.constant.UserConstants;
|
||||||
import com.ghy.common.core.text.Convert;
|
import com.ghy.common.core.text.Convert;
|
||||||
|
import com.ghy.common.enums.AdapayOrderType;
|
||||||
|
import com.ghy.common.enums.OrderStatus;
|
||||||
|
import com.ghy.common.utils.AdapayUtils;
|
||||||
import com.ghy.order.domain.OrderMaster;
|
import com.ghy.order.domain.OrderMaster;
|
||||||
import com.ghy.order.mapper.OrderDetailMapper;
|
|
||||||
import com.ghy.order.mapper.OrderMasterMapper;
|
import com.ghy.order.mapper.OrderMasterMapper;
|
||||||
import com.ghy.order.request.AppOrderRequest;
|
import com.ghy.order.request.AppOrderRequest;
|
||||||
import com.ghy.order.service.OrderMasterService;
|
import com.ghy.order.service.OrderMasterService;
|
||||||
|
import com.ghy.payment.domain.FinancialDetail;
|
||||||
|
import com.ghy.payment.domain.FinancialMaster;
|
||||||
|
import com.ghy.payment.service.AdapayService;
|
||||||
|
import com.ghy.payment.service.FinancialDetailService;
|
||||||
|
import com.ghy.payment.service.FinancialMasterService;
|
||||||
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
@ -23,11 +42,18 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
@Service
|
@Service
|
||||||
public class OrderMasterServiceImpl implements OrderMasterService {
|
public class OrderMasterServiceImpl implements OrderMasterService {
|
||||||
|
|
||||||
@Resource
|
private static final Logger logger = LoggerFactory.getLogger(OrderMasterServiceImpl.class);
|
||||||
private OrderMasterMapper orderMasterMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderDetailMapper orderDetailMapper;
|
private ThreadPoolTaskExecutor executor;
|
||||||
|
@Resource
|
||||||
|
private AdapayService adapayService;
|
||||||
|
@Resource
|
||||||
|
private OrderMasterMapper orderMasterMapper;
|
||||||
|
@Resource
|
||||||
|
private FinancialMasterService financialMasterService;
|
||||||
|
@Resource
|
||||||
|
private FinancialDetailService financialDetailService;
|
||||||
|
|
||||||
private static final AtomicLong INDEX = new AtomicLong(1L);
|
private static final AtomicLong INDEX = new AtomicLong(1L);
|
||||||
|
|
||||||
|
|
@ -90,4 +116,111 @@ public class OrderMasterServiceImpl implements OrderMasterService {
|
||||||
return UserConstants.ORDER_CODE_UNIQUE;
|
return UserConstants.ORDER_CODE_UNIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateStatus(Long orderMasterId, int status) {
|
||||||
|
return orderMasterMapper.updateStatus(orderMasterId, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void confirm(Long orderMasterId) throws BaseAdaPayException {
|
||||||
|
// 校验订单
|
||||||
|
OrderMaster orderMaster = selectById(orderMasterId);
|
||||||
|
Assert.notNull(orderMaster, "找不到对应的订单");
|
||||||
|
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMasterId);
|
||||||
|
Assert.notNull(financialMaster, "找不到订单");
|
||||||
|
Assert.isTrue(financialMaster.getPayStatus() == 1, "订单未支付");
|
||||||
|
PaymentDTO payment = financialMasterService.selectPaymentById(financialMaster.getPaymentId());
|
||||||
|
Assert.notNull(payment, "找不到支付记录");
|
||||||
|
|
||||||
|
// 修改主订单状态为已完成
|
||||||
|
int i = updateStatus(orderMasterId, OrderStatus.FINISH.code());
|
||||||
|
Assert.isTrue(i == 1, "更新订单状态失败");
|
||||||
|
|
||||||
|
if (BigDecimal.ZERO.compareTo(financialMaster.getPayMoney()) < 0) {
|
||||||
|
// 支付金额<=0的话 不需要走下面的流程了
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用子财务单组成分账信息
|
||||||
|
List<FinancialDetail> financialDetails = financialDetailService.selectByFinancialMasterId(financialMaster.getId());
|
||||||
|
// 分账账户
|
||||||
|
ArrayList<DivMember> divMembers = new ArrayList<>();
|
||||||
|
// 需要自动提现的账户
|
||||||
|
ArrayList<DivMember> autoDrawCashMembers = new ArrayList<>();
|
||||||
|
// 校验金额 主财务单的金额减去所有子财务单的金额是否=0
|
||||||
|
BigDecimal checkMoney = financialMaster.getPayMoney();
|
||||||
|
// 确认支付金额 = 主财务单付款金额 - 退款金额
|
||||||
|
BigDecimal confirmAmt = financialMaster.getPayMoney();
|
||||||
|
for (FinancialDetail financialDetail : financialDetails) {
|
||||||
|
checkMoney = checkMoney.subtract(financialDetail.getPayMoney());
|
||||||
|
String memberId, amount;
|
||||||
|
DivMember member;
|
||||||
|
switch (financialDetail.getFinancialDetailType()) {
|
||||||
|
case 0:
|
||||||
|
// 上门师傅结单 分账同下
|
||||||
|
case 1:
|
||||||
|
// 大师傅/店铺提成
|
||||||
|
memberId = AdapayUtils.getWorkerMemberId(financialDetail.getPayeeId(), orderMaster.getDeptId());
|
||||||
|
amount = AdapayUtils.bigDecimalToString(financialDetail.getPayMoney());
|
||||||
|
member = new DivMember(memberId, amount, false);
|
||||||
|
divMembers.add(member);
|
||||||
|
autoDrawCashMembers.add(member);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// 平台提成 并且是手续费承担方
|
||||||
|
amount = AdapayUtils.bigDecimalToString(financialDetail.getPayMoney());
|
||||||
|
divMembers.add(new DivMember("0", amount, true));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// 分销
|
||||||
|
memberId = AdapayUtils.getCustomerMemberId(financialDetail.getPayeeId(), orderMaster.getDeptId());
|
||||||
|
amount = AdapayUtils.bigDecimalToString(financialDetail.getPayMoney());
|
||||||
|
member = new DivMember(memberId, amount, false);
|
||||||
|
divMembers.add(member);
|
||||||
|
autoDrawCashMembers.add(member);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// 退款
|
||||||
|
confirmAmt = confirmAmt.subtract(financialDetail.getPayMoney());
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 这里校验一次主财务单的金额减去所有子财务单的金额是否=0
|
||||||
|
Assert.isTrue(BigDecimal.ZERO.compareTo(checkMoney) == 0, "订单异常,请稍后再试");
|
||||||
|
|
||||||
|
JSONObject response = adapayService.paymentConfirm(orderMaster.getDeptId(), payment.getId(), payment.getOrderNo(),
|
||||||
|
AdapayUtils.bigDecimalToString(confirmAmt), divMembers, null, null);
|
||||||
|
boolean status = AdapayStatusEnum.succeeded.code.equals(response.getString("status"));
|
||||||
|
// 如果确认支付失败 这里抛出异常 回滚前面修改主订单状态的操作
|
||||||
|
Assert.isTrue(status, response.getString("error_msg"));
|
||||||
|
|
||||||
|
// 走到这里确认支付和分账都成功了 异步进入自动提现流程
|
||||||
|
autoDrawCashMembers.forEach(member -> executor.execute(() -> {
|
||||||
|
String memberId = member.getMemberId();
|
||||||
|
String amount = member.getAmount();
|
||||||
|
try {
|
||||||
|
drawCash(orderMaster.getDeptId(), memberId, amount);
|
||||||
|
} catch (BaseAdaPayException e) {
|
||||||
|
logger.error("自动发起提现失败: orderMasterId={}, memberId={}, cashAmt={}", orderMasterId, memberId, amount, e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起提现
|
||||||
|
*
|
||||||
|
* @param deptId 公司ID
|
||||||
|
* @param memberId Adapay实名账户ID
|
||||||
|
* @param amount 提现金额
|
||||||
|
*/
|
||||||
|
public void drawCash(Long deptId, String memberId, String amount) throws BaseAdaPayException {
|
||||||
|
String orderNo = AdapayUtils.createOrderNo(AdapayOrderType.DRAW_CASH);
|
||||||
|
JSONObject response = adapayService.drawCash(deptId, orderNo, "T1", amount, memberId, "订单结算", null);
|
||||||
|
|
||||||
|
boolean status = AdapayStatusEnum.succeeded.code.equals(response.getString("status"));
|
||||||
|
Assert.isTrue(status, response.getString("error_msg"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,13 @@
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="updateStatus">
|
||||||
|
UPDATE order_master
|
||||||
|
SET order_status = #{orderStatus},
|
||||||
|
update_time = SYSDATE()
|
||||||
|
WHERE id = #{orderMasterId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<insert id="insertOrderMaster" parameterType="com.ghy.order.domain.OrderMaster" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertOrderMaster" parameterType="com.ghy.order.domain.OrderMaster" useGeneratedKeys="true" keyProperty="id">
|
||||||
INSERT INTO order_master(
|
INSERT INTO order_master(
|
||||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.ghy.payment.mapper;
|
package com.ghy.payment.mapper;
|
||||||
|
|
||||||
import com.ghy.payment.domain.FinancialDetail;
|
import com.ghy.payment.domain.FinancialDetail;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import com.ghy.payment.response.FinancialCountResponse;
|
import com.ghy.payment.response.FinancialCountResponse;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -48,6 +48,12 @@ public interface FinancialDetailMapper {
|
||||||
*/
|
*/
|
||||||
FinancialDetail selectById(Long financialDetailId);
|
FinancialDetail selectById(Long financialDetailId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param financialMasterId 主财务单ID
|
||||||
|
* @return 财务细单
|
||||||
|
*/
|
||||||
|
List<FinancialDetail> selectByFinancialMasterId(Long financialMasterId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除财务细单信息
|
* 批量删除财务细单信息
|
||||||
*
|
*
|
||||||
|
|
@ -76,4 +82,4 @@ public interface FinancialDetailMapper {
|
||||||
* @param reverseId 撤销支付ID
|
* @param reverseId 撤销支付ID
|
||||||
*/
|
*/
|
||||||
void payReverseSucceeded(String reverseId);
|
void payReverseSucceeded(String reverseId);
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +50,12 @@ public interface FinancialDetailService {
|
||||||
*/
|
*/
|
||||||
FinancialDetail selectById(Long financialDetailId);
|
FinancialDetail selectById(Long financialDetailId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param financialMasterId 主财务单id
|
||||||
|
* @return 财务细单
|
||||||
|
*/
|
||||||
|
List<FinancialDetail> selectByFinancialMasterId(Long financialMasterId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ids 财务细单ids
|
* @param ids 财务细单ids
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static java.time.temporal.ChronoField.*;
|
import static java.time.temporal.ChronoField.*;
|
||||||
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FinancialDetailServiceImpl implements FinancialDetailService {
|
public class FinancialDetailServiceImpl implements FinancialDetailService {
|
||||||
|
|
@ -42,14 +41,14 @@ public class FinancialDetailServiceImpl implements FinancialDetailService {
|
||||||
request.setFlag("true");
|
request.setFlag("true");
|
||||||
// 查询各月含有收入的费用
|
// 查询各月含有收入的费用
|
||||||
List<FinancialCountResponse> list = financialDetailMapper.count(request);
|
List<FinancialCountResponse> list = financialDetailMapper.count(request);
|
||||||
list.forEach(financialCountResponse->{
|
list.forEach(financialCountResponse -> {
|
||||||
// 查询指定月支出的
|
// 查询指定月支出的
|
||||||
request.setFlag("false");
|
request.setFlag("false");
|
||||||
request.setCreateTime(financialCountResponse.getCreateTime());
|
request.setCreateTime(financialCountResponse.getCreateTime());
|
||||||
List<FinancialCountResponse> payCountList = financialDetailMapper.count(request);
|
List<FinancialCountResponse> payCountList = financialDetailMapper.count(request);
|
||||||
if( payCountList != null && payCountList.size() != 0){
|
if (payCountList != null && payCountList.size() != 0) {
|
||||||
financialCountResponse.setPayCount(payCountList.get(0).getIncomeCount());
|
financialCountResponse.setPayCount(payCountList.get(0).getIncomeCount());
|
||||||
}else {
|
} else {
|
||||||
financialCountResponse.setPayCount("0");
|
financialCountResponse.setPayCount("0");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -82,6 +81,11 @@ public class FinancialDetailServiceImpl implements FinancialDetailService {
|
||||||
return financialDetailMapper.selectById(financialDetailId);
|
return financialDetailMapper.selectById(financialDetailId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FinancialDetail> selectByFinancialMasterId(Long financialMasterId) {
|
||||||
|
return financialDetailMapper.selectByFinancialMasterId(financialMasterId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int deleteFinancialDetailByIds(String ids) {
|
public int deleteFinancialDetailByIds(String ids) {
|
||||||
Long[] financialDetailIds = Convert.toLongArray(ids);
|
Long[] financialDetailIds = Convert.toLongArray(ids);
|
||||||
|
|
@ -113,10 +117,10 @@ public class FinancialDetailServiceImpl implements FinancialDetailService {
|
||||||
@Override
|
@Override
|
||||||
public Map<Long, FinancialDetail> byOrderIdInMap(List<Long> orderIdList) {
|
public Map<Long, FinancialDetail> byOrderIdInMap(List<Long> orderIdList) {
|
||||||
Map<Long, FinancialDetail> longFinancialDetailHashMap = new HashMap<>();
|
Map<Long, FinancialDetail> longFinancialDetailHashMap = new HashMap<>();
|
||||||
if(orderIdList != null && orderIdList.size() > 0){
|
if (orderIdList != null && orderIdList.size() > 0) {
|
||||||
List<FinancialDetail> financialDetailList = financialDetailMapper.getByOrderIdList(orderIdList);
|
List<FinancialDetail> financialDetailList = financialDetailMapper.getByOrderIdList(orderIdList);
|
||||||
if(financialDetailList != null && financialDetailList.size() > 0){
|
if (financialDetailList != null && financialDetailList.size() > 0) {
|
||||||
for(FinancialDetail financialDetail : financialDetailList){
|
for (FinancialDetail financialDetail : financialDetailList) {
|
||||||
longFinancialDetailHashMap.put(financialDetail.getOrderDetailId(), financialDetail);
|
longFinancialDetailHashMap.put(financialDetail.getOrderDetailId(), financialDetail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,10 @@
|
||||||
<include refid="selectFinancialDetail"/> WHERE id = #{financialDetailId}
|
<include refid="selectFinancialDetail"/> WHERE id = #{financialDetailId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByFinancialMasterId" resultMap="FinancialDetailResult">
|
||||||
|
<include refid="selectFinancialDetail"/> WHERE financial_master_id = #{financialMasterId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<delete id="deleteFinancialDetailByIds" parameterType="Long">
|
<delete id="deleteFinancialDetailByIds" parameterType="Long">
|
||||||
DELETE FROM financial_detail WHERE id IN
|
DELETE FROM financial_detail WHERE id IN
|
||||||
<foreach collection="array" item="financialDetailId" open="(" separator="," close=")">
|
<foreach collection="array" item="financialDetailId" open="(" separator="," close=")">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue