From 443a61e2ecb83381708ef075d426f13da056e940 Mon Sep 17 00:00:00 2001 From: "kuang.yife" Date: Tue, 2 Jan 2024 22:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6=E8=B4=B9=E7=94=A8=E5=8A=A0?= =?UTF-8?q?=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderAttachmentRecordController.java | 136 ++++++++++++++++++ .../web/controller/pay/AlipayController.java | 21 ++- .../order/domain/OrderAttachmentRecord.java | 45 ++++++ .../mapper/OrderAttachmentRecordMapper.java | 61 ++++++++ .../IOrderAttachmentRecordService.java | 61 ++++++++ .../OrderAttachmentRecordServiceImpl.java | 94 ++++++++++++ .../service/impl/OrderDetailServiceImpl.java | 51 ++++++- .../order/OrderAttachmentRecordMapper.xml | 74 ++++++++++ .../ghy/payment/domain/PaymentRelation.java | 1 + 9 files changed, 539 insertions(+), 5 deletions(-) create mode 100644 ghy-admin/src/main/java/com/ghy/web/controller/order/OrderAttachmentRecordController.java create mode 100644 ghy-order/src/main/java/com/ghy/order/domain/OrderAttachmentRecord.java create mode 100644 ghy-order/src/main/java/com/ghy/order/mapper/OrderAttachmentRecordMapper.java create mode 100644 ghy-order/src/main/java/com/ghy/order/service/IOrderAttachmentRecordService.java create mode 100644 ghy-order/src/main/java/com/ghy/order/service/impl/OrderAttachmentRecordServiceImpl.java create mode 100644 ghy-order/src/main/resources/mapper/order/OrderAttachmentRecordMapper.xml diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderAttachmentRecordController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderAttachmentRecordController.java new file mode 100644 index 00000000..9ccc9a93 --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderAttachmentRecordController.java @@ -0,0 +1,136 @@ +package com.ghy.web.controller.order; + +import java.util.List; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; +import com.ghy.common.annotation.Log; +import com.ghy.common.enums.BusinessType; +import com.ghy.order.domain.OrderAttachmentRecord; +import com.ghy.order.service.IOrderAttachmentRecordService; +import com.ghy.common.core.controller.BaseController; +import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.utils.poi.ExcelUtil; +import com.ghy.common.core.page.TableDataInfo; + +/** + * 附件费Controller + * + * @author clunt + * @date 2024-01-02 + */ +@Controller +@RequestMapping("/order/attach") +public class OrderAttachmentRecordController extends BaseController +{ + private String prefix = "order/attach"; + + @Autowired + private IOrderAttachmentRecordService orderAttachmentRecordService; + + @RequiresPermissions("attach:record:view") + @GetMapping() + public String record() + { + return prefix + "/record"; + } + + /** + * 查询附件费列表 + */ + @RequiresPermissions("attach:record:list") + @PostMapping("/list") + @ResponseBody + public TableDataInfo list(OrderAttachmentRecord orderAttachmentRecord) + { + startPage(); + List list = orderAttachmentRecordService.selectOrderAttachmentRecordList(orderAttachmentRecord); + return getDataTable(list); + } + + /** + * App查询附件费列表 + */ + @PostMapping("/app/list") + @ResponseBody + public TableDataInfo appList(@RequestBody OrderAttachmentRecord orderAttachmentRecord) + { + startPage(); + List list = orderAttachmentRecordService.selectOrderAttachmentRecordList(orderAttachmentRecord); + return getDataTable(list); + } + + + /** + * 导出附件费列表 + */ + @RequiresPermissions("attach:record:export") + @Log(title = "附件费", businessType = BusinessType.EXPORT) + @PostMapping("/export") + @ResponseBody + public AjaxResult export(OrderAttachmentRecord orderAttachmentRecord) + { + List list = orderAttachmentRecordService.selectOrderAttachmentRecordList(orderAttachmentRecord); + ExcelUtil util = new ExcelUtil(OrderAttachmentRecord.class); + return util.exportExcel(list, "附件费数据"); + } + + /** + * 新增附件费 + */ + @GetMapping("/add") + public String add() + { + return prefix + "/add"; + } + + /** + * 新增保存附件费 + */ + @RequiresPermissions("attach:record:add") + @Log(title = "附件费", businessType = BusinessType.INSERT) + @PostMapping("/add") + @ResponseBody + public AjaxResult addSave(OrderAttachmentRecord orderAttachmentRecord) + { + return toAjax(orderAttachmentRecordService.insertOrderAttachmentRecord(orderAttachmentRecord)); + } + + /** + * 修改附件费 + */ + @RequiresPermissions("attach:record:edit") + @GetMapping("/edit/{id}") + public String edit(@PathVariable("id") Long id, ModelMap mmap) + { + OrderAttachmentRecord orderAttachmentRecord = orderAttachmentRecordService.selectOrderAttachmentRecordById(id); + mmap.put("orderAttachmentRecord", orderAttachmentRecord); + return prefix + "/edit"; + } + + /** + * 修改保存附件费 + */ + @RequiresPermissions("attach:record:edit") + @Log(title = "附件费", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + @ResponseBody + public AjaxResult editSave(OrderAttachmentRecord orderAttachmentRecord) + { + return toAjax(orderAttachmentRecordService.updateOrderAttachmentRecord(orderAttachmentRecord)); + } + + /** + * 删除附件费 + */ + @RequiresPermissions("attach:record:remove") + @Log(title = "附件费", businessType = BusinessType.DELETE) + @PostMapping( "/remove") + @ResponseBody + public AjaxResult remove(String ids) + { + return toAjax(orderAttachmentRecordService.deleteOrderAttachmentRecordByIds(ids)); + } +} \ No newline at end of file diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/pay/AlipayController.java b/ghy-admin/src/main/java/com/ghy/web/controller/pay/AlipayController.java index 5ce4924e..c5391e0a 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/pay/AlipayController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/pay/AlipayController.java @@ -1,5 +1,6 @@ package com.ghy.web.controller.pay; +import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSONObject; import com.ghy.common.adapay.model.AdapayStatusEnum; import com.ghy.common.adapay.model.PayParam; @@ -8,8 +9,10 @@ import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.enums.PayStatus; import com.ghy.common.enums.PayTypeEnum; import com.ghy.common.utils.MoneyUtil; +import com.ghy.order.domain.OrderAttachmentRecord; import com.ghy.order.domain.OrderDetail; import com.ghy.order.domain.OrderMaster; +import com.ghy.order.service.IOrderAttachmentRecordService; import com.ghy.order.service.OrderDetailService; import com.ghy.order.service.OrderMasterService; import com.ghy.payment.domain.FinancialChangeRecord; @@ -28,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.List; import java.util.Objects; /** @@ -51,6 +55,9 @@ public class AlipayController extends BaseController { private IPaymentRelationService paymentRelationService; @Resource private FinancialChangeRecordService financialChangeRecordService; + @Resource + private IOrderAttachmentRecordService orderAttachmentRecordService; + /** * 支付宝正扫支付 @@ -168,7 +175,13 @@ public class AlipayController extends BaseController { payMoney = payMoney.add(fcr.getChangeMoney()); relations.add(new PaymentRelation(null, fcr.getId(), PaymentRelation.FINANCIAL_CHANGE, fcr.getChangeMoney())); } - + OrderAttachmentRecord param = new OrderAttachmentRecord(); + param.setOrderDetailId(orderDetailId); + List orderAttachmentRecordList = orderAttachmentRecordService.selectOrderAttachmentRecordList(param); + if(CollectionUtil.isNotEmpty(orderAttachmentRecordList)){ + payMoney = payMoney.add(orderAttachmentRecordList.get(0).getAttachMoney()); + relations.add(new PaymentRelation(null, orderAttachmentRecordList.get(0).getId(), PaymentRelation.ORDER_ATTACHMENT, orderAttachmentRecordList.get(0).getAttachMoney())); + } if (MoneyUtil.lte0(payMoney)) { return AjaxResult.error("不需要支付"); } @@ -212,6 +225,12 @@ public class AlipayController extends BaseController { fcr2update.setPaymentId(paymentId); financialChangeRecordService.update(fcr2update); } + if(CollectionUtil.isNotEmpty(orderAttachmentRecordList)){ + OrderAttachmentRecord oarUpdate = new OrderAttachmentRecord(); + oarUpdate.setId(orderAttachmentRecordList.get(0).getId()); + oarUpdate.setPaymentId(paymentId); + orderAttachmentRecordService.updateOrderAttachmentRecord(oarUpdate); + } // 保存支付ID与订单ID到关系表 for (PaymentRelation relation : relations) { relation.setPaymentId(paymentId); diff --git a/ghy-order/src/main/java/com/ghy/order/domain/OrderAttachmentRecord.java b/ghy-order/src/main/java/com/ghy/order/domain/OrderAttachmentRecord.java new file mode 100644 index 00000000..e6018d3e --- /dev/null +++ b/ghy-order/src/main/java/com/ghy/order/domain/OrderAttachmentRecord.java @@ -0,0 +1,45 @@ +package com.ghy.order.domain; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + *

附加费

+ * @author clunt + * @since 2024-01-02 + */ +@Data +public class OrderAttachmentRecord { + + /** + * id + * */ + private Long id; + + /** + * 子单id + * */ + private Long orderDetailId; + + /** + * 主单id + * */ + private Long orderMasterId; + + /** + * 附件金额 + * */ + private BigDecimal attachMoney; + + /** + * 附件类型 + * */ + private String type; + + /** + * 支付ID + */ + private String paymentId; + +} diff --git a/ghy-order/src/main/java/com/ghy/order/mapper/OrderAttachmentRecordMapper.java b/ghy-order/src/main/java/com/ghy/order/mapper/OrderAttachmentRecordMapper.java new file mode 100644 index 00000000..8383f7ba --- /dev/null +++ b/ghy-order/src/main/java/com/ghy/order/mapper/OrderAttachmentRecordMapper.java @@ -0,0 +1,61 @@ +package com.ghy.order.mapper; + +import java.util.List; +import com.ghy.order.domain.OrderAttachmentRecord; + +/** + * 附件费Mapper接口 + * + * @author clunt + * @date 2024-01-02 + */ +public interface OrderAttachmentRecordMapper +{ + /** + * 查询附件费 + * + * @param id 附件费主键 + * @return 附件费 + */ + public OrderAttachmentRecord selectOrderAttachmentRecordById(Long id); + + /** + * 查询附件费列表 + * + * @param orderAttachmentRecord 附件费 + * @return 附件费集合 + */ + public List selectOrderAttachmentRecordList(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 新增附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + public int insertOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 修改附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + public int updateOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 删除附件费 + * + * @param id 附件费主键 + * @return 结果 + */ + public int deleteOrderAttachmentRecordById(Long id); + + /** + * 批量删除附件费 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteOrderAttachmentRecordByIds(String[] ids); +} diff --git a/ghy-order/src/main/java/com/ghy/order/service/IOrderAttachmentRecordService.java b/ghy-order/src/main/java/com/ghy/order/service/IOrderAttachmentRecordService.java new file mode 100644 index 00000000..06a14e77 --- /dev/null +++ b/ghy-order/src/main/java/com/ghy/order/service/IOrderAttachmentRecordService.java @@ -0,0 +1,61 @@ +package com.ghy.order.service; + +import java.util.List; +import com.ghy.order.domain.OrderAttachmentRecord; + +/** + * 附件费Service接口 + * + * @author clunt + * @date 2024-01-02 + */ +public interface IOrderAttachmentRecordService +{ + /** + * 查询附件费 + * + * @param id 附件费主键 + * @return 附件费 + */ + public OrderAttachmentRecord selectOrderAttachmentRecordById(Long id); + + /** + * 查询附件费列表 + * + * @param orderAttachmentRecord 附件费 + * @return 附件费集合 + */ + public List selectOrderAttachmentRecordList(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 新增附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + public int insertOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 修改附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + public int updateOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord); + + /** + * 批量删除附件费 + * + * @param ids 需要删除的附件费主键集合 + * @return 结果 + */ + public int deleteOrderAttachmentRecordByIds(String ids); + + /** + * 删除附件费信息 + * + * @param id 附件费主键 + * @return 结果 + */ + public int deleteOrderAttachmentRecordById(Long id); +} \ No newline at end of file diff --git a/ghy-order/src/main/java/com/ghy/order/service/impl/OrderAttachmentRecordServiceImpl.java b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderAttachmentRecordServiceImpl.java new file mode 100644 index 00000000..63842c0e --- /dev/null +++ b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderAttachmentRecordServiceImpl.java @@ -0,0 +1,94 @@ +package com.ghy.order.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ghy.order.mapper.OrderAttachmentRecordMapper; +import com.ghy.order.domain.OrderAttachmentRecord; +import com.ghy.order.service.IOrderAttachmentRecordService; +import com.ghy.common.core.text.Convert; + +/** + * 附件费Service业务层处理 + * + * @author clunt + * @date 2024-01-02 + */ +@Service +public class OrderAttachmentRecordServiceImpl implements IOrderAttachmentRecordService +{ + @Autowired + private OrderAttachmentRecordMapper orderAttachmentRecordMapper; + + /** + * 查询附件费 + * + * @param id 附件费主键 + * @return 附件费 + */ + @Override + public OrderAttachmentRecord selectOrderAttachmentRecordById(Long id) + { + return orderAttachmentRecordMapper.selectOrderAttachmentRecordById(id); + } + + /** + * 查询附件费列表 + * + * @param orderAttachmentRecord 附件费 + * @return 附件费 + */ + @Override + public List selectOrderAttachmentRecordList(OrderAttachmentRecord orderAttachmentRecord) + { + return orderAttachmentRecordMapper.selectOrderAttachmentRecordList(orderAttachmentRecord); + } + + /** + * 新增附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + @Override + public int insertOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord) + { + return orderAttachmentRecordMapper.insertOrderAttachmentRecord(orderAttachmentRecord); + } + + /** + * 修改附件费 + * + * @param orderAttachmentRecord 附件费 + * @return 结果 + */ + @Override + public int updateOrderAttachmentRecord(OrderAttachmentRecord orderAttachmentRecord) + { + return orderAttachmentRecordMapper.updateOrderAttachmentRecord(orderAttachmentRecord); + } + + /** + * 批量删除附件费 + * + * @param ids 需要删除的附件费主键 + * @return 结果 + */ + @Override + public int deleteOrderAttachmentRecordByIds(String ids) + { + return orderAttachmentRecordMapper.deleteOrderAttachmentRecordByIds(Convert.toStrArray(ids)); + } + + /** + * 删除附件费信息 + * + * @param id 附件费主键 + * @return 结果 + */ + @Override + public int deleteOrderAttachmentRecordById(Long id) + { + return orderAttachmentRecordMapper.deleteOrderAttachmentRecordById(id); + } +} diff --git a/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java index 06cd130e..1823060e 100644 --- a/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java +++ b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java @@ -26,10 +26,7 @@ import com.ghy.order.domain.*; import com.ghy.order.mapper.OrderAddSubtractMapper; import com.ghy.order.mapper.OrderDetailMapper; import com.ghy.order.mapper.OrderMasterMapper; -import com.ghy.order.service.IAfterServiceRecordService; -import com.ghy.order.service.OrderDetailService; -import com.ghy.order.service.OrderGoodsService; -import com.ghy.order.service.OrderMasterService; +import com.ghy.order.service.*; import com.ghy.payment.domain.FinancialChangeRecord; import com.ghy.payment.domain.FinancialDetail; import com.ghy.payment.domain.FinancialMaster; @@ -112,6 +109,9 @@ public class OrderDetailServiceImpl implements OrderDetailService { @Resource private IAfterServiceRecordService afterServiceRecordService; + @Resource + private IOrderAttachmentRecordService orderAttachmentRecordService; + // Adapay 手续费率 默认0.008 @Value("${adapay.fee_rate:0.008}") private String feeRate; @@ -575,6 +575,14 @@ public class OrderDetailServiceImpl implements OrderDetailService { } } + // 附件费分账 + OrderAttachmentRecord param = new OrderAttachmentRecord(); + param.setOrderDetailId(orderDetailId); + List orderAttachmentRecordList = orderAttachmentRecordService.selectOrderAttachmentRecordList(param); + if(CollectionUtils.isNotEmpty(orderAttachmentRecordList)){ + // 附件费分账. + attachPaymentConfirm(orderAttachmentRecordList.get(0), orderDetailId, orderDetail.getWorkerId(), deptId); + } // --------------------- 子财务单分账部分 start --------------------- // 子单的实际金额 BigDecimal odMoney = financialDetail.getPayMoney().subtract(changeMoney); @@ -766,6 +774,41 @@ public class OrderDetailServiceImpl implements OrderDetailService { return workerFee; } + private void attachPaymentConfirm(OrderAttachmentRecord orderAttachmentRecord, Long orderDetailId, Long workerId, Long deptId) throws BaseAdaPayException { + BigDecimal attachMoney = orderAttachmentRecord.getAttachMoney(); + // 扣除罚金后的上门师傅报酬 +// workerFee = workerFee.subtract(fineMoney); + // 平台抽成 + 超时罚金 +// platformFee = platformFee.add(fineMoney); + ArrayList divMembers = new ArrayList<>(); + // 承担手续费的标志 如果平台抽成为0则大师傅承担手续费 如果大师傅抽成也为0 则由上门师傅自己承担手续费 + boolean feeFlag = false; + if (MoneyUtil.gt0(attachMoney)) { + divMembers.add(new DivMember("0", MoneyUtil.toS(attachMoney), true)); + feeFlag = true; + } + String orderNo = "FCR_" + orderAttachmentRecord.getId() + "_" + System.currentTimeMillis(); + //调用分账 + logger.info("子订单[{}]的[附件费]发起分账", orderDetailId); + JSONObject response = adapayService.paymentConfirm(deptId, orderAttachmentRecord.getPaymentId(), orderNo, MoneyUtil.toS(attachMoney), divMembers, null, null); + logger.info("子订单[{}]的[附件费]分账结果: {}", orderDetailId, response.toString()); + if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) { // 分账成功 + logger.info("子订单[{}]的[附件费]分账成功", orderDetailId); + } else { // 分账失败 + if (AdapayErrorCode.CONFIRM_AMT_OVER_LIMIT.equals(response.getString("error_code"))) { + // 当前确认金额 > 支付金额 - 已支付确认金额 - 已支付撤销金额 + // 这里有两种可能 1.可能是之前算错了手续费的旧订单 + // 2.可能是之前执行过完单流程 改价单分账成功了 但是子财务单分账失败了 + // 所以直接跳过 + logger.info("子订单[{}] 跳过[附件费]分账 : CONFIRM_AMT_OVER_LIMIT", orderDetailId); + } else { + logger.error("子订单[{}]的[附件费 paymentId={}]分账失败: {}", orderDetailId, orderAttachmentRecord.getPaymentId(), response.toJSONString()); + // 其它错误抛异常 + throw new IllegalArgumentException(response.getString("error_msg")); + } + } + } + /** * 订单追加分账 * diff --git a/ghy-order/src/main/resources/mapper/order/OrderAttachmentRecordMapper.xml b/ghy-order/src/main/resources/mapper/order/OrderAttachmentRecordMapper.xml new file mode 100644 index 00000000..7727c7b4 --- /dev/null +++ b/ghy-order/src/main/resources/mapper/order/OrderAttachmentRecordMapper.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + select id, order_detail_id, order_master_id, type, attach_money,payment_id from order_attachment_record + + + + + + + + insert into order_attachment_record + + order_detail_id, + order_master_id, + type, + attach_money, + + + #{orderDetailId}, + #{orderMasterId}, + #{type}, + #{attachMoney}, + + + + + update order_attachment_record + + order_detail_id = #{orderDetailId}, + order_master_id = #{orderMasterId}, + type = #{type}, + attach_money = #{attachMoney}, + payment_id = #{paymentId}, + + where id = #{id} + + + + delete from order_attachment_record where id = #{id} + + + + delete from order_attachment_record where id in + + #{id} + + + + \ No newline at end of file diff --git a/ghy-payment/src/main/java/com/ghy/payment/domain/PaymentRelation.java b/ghy-payment/src/main/java/com/ghy/payment/domain/PaymentRelation.java index 82d683f4..6a038e99 100644 --- a/ghy-payment/src/main/java/com/ghy/payment/domain/PaymentRelation.java +++ b/ghy-payment/src/main/java/com/ghy/payment/domain/PaymentRelation.java @@ -47,5 +47,6 @@ public class PaymentRelation { public static final String FINANCIAL_MASTER = "financial_master"; public static final String FINANCIAL_CHANGE = "financial_change"; + public static final String ORDER_ATTACHMENT = "order_attachment"; public static final String ORDER_ADD = "order_add"; }