附件费用加价

This commit is contained in:
kuang.yife 2024-01-02 22:26:46 +08:00
parent e79e530bcd
commit 443a61e2ec
9 changed files with 539 additions and 5 deletions

View File

@ -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<OrderAttachmentRecord> list = orderAttachmentRecordService.selectOrderAttachmentRecordList(orderAttachmentRecord);
return getDataTable(list);
}
/**
* App查询附件费列表
*/
@PostMapping("/app/list")
@ResponseBody
public TableDataInfo appList(@RequestBody OrderAttachmentRecord orderAttachmentRecord)
{
startPage();
List<OrderAttachmentRecord> 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<OrderAttachmentRecord> list = orderAttachmentRecordService.selectOrderAttachmentRecordList(orderAttachmentRecord);
ExcelUtil<OrderAttachmentRecord> util = new ExcelUtil<OrderAttachmentRecord>(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));
}
}

View File

@ -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<OrderAttachmentRecord> 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);

View File

@ -0,0 +1,45 @@
package com.ghy.order.domain;
import lombok.Data;
import java.math.BigDecimal;
/**
* <P>附加费</P>
* @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;
}

View File

@ -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<OrderAttachmentRecord> 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);
}

View File

@ -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<OrderAttachmentRecord> 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);
}

View File

@ -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<OrderAttachmentRecord> 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);
}
}

View File

@ -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<OrderAttachmentRecord> 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<DivMember> 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"));
}
}
}
/**
* 订单追加分账
*

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ghy.order.mapper.OrderAttachmentRecordMapper">
<resultMap type="OrderAttachmentRecord" id="OrderAttachmentRecordResult">
<result property="id" column="id" />
<result property="orderDetailId" column="order_detail_id" />
<result property="orderMasterId" column="order_master_id" />
<result property="type" column="type" />
<result property="attachMoney" column="attach_money" />
<result property="paymentId" column="payment_id" />
</resultMap>
<sql id="selectOrderAttachmentRecordVo">
select id, order_detail_id, order_master_id, type, attach_money,payment_id from order_attachment_record
</sql>
<select id="selectOrderAttachmentRecordList" parameterType="OrderAttachmentRecord" resultMap="OrderAttachmentRecordResult">
<include refid="selectOrderAttachmentRecordVo"/>
<where>
<if test="orderDetailId != null "> and order_detail_id = #{orderDetailId}</if>
<if test="orderMasterId != null "> and order_master_id = #{orderMasterId}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="attachMoney != null "> and attach_money = #{attachMoney}</if>
</where>
</select>
<select id="selectOrderAttachmentRecordById" parameterType="Long" resultMap="OrderAttachmentRecordResult">
<include refid="selectOrderAttachmentRecordVo"/>
where id = #{id}
</select>
<insert id="insertOrderAttachmentRecord" parameterType="OrderAttachmentRecord" useGeneratedKeys="true" keyProperty="id">
insert into order_attachment_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderDetailId != null">order_detail_id,</if>
<if test="orderMasterId != null">order_master_id,</if>
<if test="type != null">type,</if>
<if test="attachMoney != null">attach_money,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderDetailId != null">#{orderDetailId},</if>
<if test="orderMasterId != null">#{orderMasterId},</if>
<if test="type != null">#{type},</if>
<if test="attachMoney != null">#{attachMoney},</if>
</trim>
</insert>
<update id="updateOrderAttachmentRecord" parameterType="OrderAttachmentRecord">
update order_attachment_record
<trim prefix="SET" suffixOverrides=",">
<if test="orderDetailId != null">order_detail_id = #{orderDetailId},</if>
<if test="orderMasterId != null">order_master_id = #{orderMasterId},</if>
<if test="type != null">type = #{type},</if>
<if test="attachMoney != null">attach_money = #{attachMoney},</if>
<if test="paymentId != null">payment_id = #{paymentId},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteOrderAttachmentRecordById" parameterType="Long">
delete from order_attachment_record where id = #{id}
</delete>
<delete id="deleteOrderAttachmentRecordByIds" parameterType="String">
delete from order_attachment_record where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -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";
}