8.13优化
This commit is contained in:
		| @ -67,5 +67,10 @@ public class BusinessRespVO { | ||||
|  | ||||
|     private  Long carteenId; | ||||
|  | ||||
|     /** | ||||
|      * 提现 | ||||
|      */ | ||||
|     private BigDecimal  withdrawal; | ||||
|  | ||||
|  | ||||
| } | ||||
| @ -78,4 +78,15 @@ public class OrderDetailsRespVO { | ||||
|     @ExcelProperty("减免金额") | ||||
|     private BigDecimal reductionAmount; | ||||
|  | ||||
|     @Schema(description = "现有金额") | ||||
|     private BigDecimal money; | ||||
|  | ||||
|     /** | ||||
|      * 待支付金额 | ||||
|      */ | ||||
|     private BigDecimal payAmount; | ||||
|     /** | ||||
|      * 最大退款金额 | ||||
|      */ | ||||
|     private BigDecimal refundAmount; | ||||
| } | ||||
|  | ||||
| @ -44,4 +44,6 @@ public class OrderDetailRespVO { | ||||
|  | ||||
|     @Schema(description = "总价") | ||||
|     private List<OrderDetailRespVO> detailList; | ||||
|  | ||||
|     private BigDecimal money; | ||||
| } | ||||
| @ -1,5 +1,11 @@ | ||||
| package cn.iocoder.yudao.module.member.controller.admin.refund; | ||||
|  | ||||
| import cn.hutool.core.collection.CollectionUtil; | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import javax.annotation.Resource; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| @ -11,6 +17,7 @@ import io.swagger.v3.oas.annotations.Operation; | ||||
| import javax.validation.constraints.*; | ||||
| import javax.validation.*; | ||||
| import javax.servlet.http.*; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.*; | ||||
| import java.io.IOException; | ||||
|  | ||||
| @ -38,6 +45,9 @@ public class RefundController { | ||||
|     @Resource | ||||
|     private RefundService refundService; | ||||
|  | ||||
|     @Resource | ||||
|     private DishOrderMapper orderMapper; | ||||
|  | ||||
|     @PostMapping("/create") | ||||
|     @Operation(summary = "创建退款审核") | ||||
|     @PreAuthorize("@ss.hasPermission('member:refund:create')") | ||||
| @ -76,7 +86,19 @@ public class RefundController { | ||||
|     @PreAuthorize("@ss.hasPermission('member:refund:query')") | ||||
|     public CommonResult<PageResult<RefundRespVO>> getRefundPage(@Valid RefundPageReqVO pageReqVO) { | ||||
|         PageResult<RefundDO> pageResult = refundService.getRefundPage(pageReqVO); | ||||
|         return success(BeanUtils.toBean(pageResult, RefundRespVO.class)); | ||||
|         PageResult<RefundRespVO> bean = BeanUtils.toBean(pageResult, RefundRespVO.class); | ||||
|         if(CollectionUtil.isNotEmpty(bean.getList())){ | ||||
|             for (RefundRespVO vo : bean.getList()){ | ||||
|                 DishOrderDO dishOrderDO = orderMapper.selectById(vo.getOrderId()); | ||||
|                 if(ObjectUtil.isNotEmpty(dishOrderDO)){ | ||||
|                     vo.setRefundAmount(dishOrderDO.getRefundAmount()); | ||||
|                 }else { | ||||
|                     vo.setRefundAmount(BigDecimal.ZERO); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } | ||||
|         return success(bean); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/export-excel") | ||||
|  | ||||
| @ -40,5 +40,6 @@ public class RefundPageReqVO extends PageParam { | ||||
|     @Schema(description = "订单金额") | ||||
|     private BigDecimal orderMoney; | ||||
|  | ||||
|  | ||||
|     @Schema(description = "手机") | ||||
|     private String mobile; | ||||
| } | ||||
| @ -29,12 +29,12 @@ public class RefundRespVO { | ||||
|     @ExcelProperty("审核状态") | ||||
|     private String status; | ||||
|  | ||||
|     @Schema(description = "审核人id", example = "21777") | ||||
|     @ExcelProperty("审核人id") | ||||
|     @Schema(description = "申请人id", example = "21777") | ||||
|     @ExcelProperty("申请人id") | ||||
|     private Long userId; | ||||
|  | ||||
|     @Schema(description = "审核人", example = "王五") | ||||
|     @ExcelProperty("审核人") | ||||
|     @Schema(description = "申请人", example = "王五") | ||||
|     @ExcelProperty("申请人") | ||||
|     private String userName; | ||||
|  | ||||
|     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||||
| @ -44,4 +44,9 @@ public class RefundRespVO { | ||||
|     @Schema(description = "订单金额") | ||||
|     private BigDecimal orderMoney; | ||||
|  | ||||
|     @Schema(description = "申请人电话", example = "王五") | ||||
|     @ExcelProperty("申请人电话") | ||||
|     private String mobile; | ||||
|  | ||||
|     private BigDecimal refundAmount; | ||||
| } | ||||
| @ -32,4 +32,7 @@ public class RefundSaveReqVO { | ||||
|     @Schema(description = "审核人", example = "王五") | ||||
|     private String userName; | ||||
|  | ||||
|     @Schema(description = "手机", example = "王五") | ||||
|     private String mobile; | ||||
|  | ||||
| } | ||||
| @ -35,5 +35,22 @@ public class MemberTagBaseVO { | ||||
|      * 执行优先 | ||||
|      */ | ||||
|     private String state; | ||||
|     /** | ||||
|      * 时间段标志:0-关闭,1-开启 | ||||
|      */ | ||||
|     private String timeFlag; | ||||
|  | ||||
|     /** | ||||
|      * 早 | ||||
|      */ | ||||
|     private BigDecimal morning; | ||||
|     /** | ||||
|      * 中 | ||||
|      */ | ||||
|     private BigDecimal noon; | ||||
|     /** | ||||
|      * 晚 | ||||
|      */ | ||||
|     private BigDecimal night; | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -67,4 +67,16 @@ public class AppOrderRespVO { | ||||
|     @Schema(description = "减免金额") | ||||
|     private BigDecimal reductionAmount; | ||||
|  | ||||
|     @Schema(description = "现有金额") | ||||
|     private BigDecimal money; | ||||
|  | ||||
|     /** | ||||
|      * 待支付金额 | ||||
|      */ | ||||
|     private BigDecimal payAmount; | ||||
|     /** | ||||
|      * 最大退款金额 | ||||
|      */ | ||||
|     private BigDecimal refundAmount; | ||||
|  | ||||
| } | ||||
| @ -55,6 +55,10 @@ public class BusinessDO extends BaseDO { | ||||
|      * 充值钱包 | ||||
|      */ | ||||
|     private BigDecimal rechargePurse; | ||||
|     /** | ||||
|      * 提现 | ||||
|      */ | ||||
|     private BigDecimal  withdrawal; | ||||
|     /** | ||||
|      * 补贴钱包 | ||||
|      */ | ||||
|  | ||||
| @ -93,4 +93,13 @@ public class DishOrderDO extends BaseDO { | ||||
|      * 减免金额 | ||||
|      */ | ||||
|     private BigDecimal reductionAmount; | ||||
|  | ||||
|     /** | ||||
|      * 待支付金额 | ||||
|      */ | ||||
|     private BigDecimal payAmount; | ||||
|     /** | ||||
|      * 最大退款金额 | ||||
|      */ | ||||
|     private BigDecimal refundAmount; | ||||
| } | ||||
| @ -59,4 +59,6 @@ public class RefundDO extends BaseDO { | ||||
|      */ | ||||
|     private String userName; | ||||
|  | ||||
|     private String mobile; | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| package cn.iocoder.yudao.module.member.dal.dataobject.refundlog; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.math.BigDecimal; | ||||
| import java.time.LocalDateTime; | ||||
| import com.baomidou.mybatisplus.annotation.*; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
|  | ||||
| /** | ||||
|  * 退款记录 DO | ||||
|  * | ||||
|  * @author 管理员 | ||||
|  */ | ||||
| @TableName("member_refund_log") | ||||
| @KeySequence("member_refund_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class RefundLogDO { | ||||
|  | ||||
|     /** | ||||
|      * 编号 | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|     /** | ||||
|      * 退款 | ||||
|      */ | ||||
|     private BigDecimal money; | ||||
|  | ||||
|     /** | ||||
|      * 创建时间 | ||||
|      */ | ||||
|     @TableField(fill = FieldFill.INSERT) | ||||
|     private LocalDateTime createTime; | ||||
|  | ||||
| } | ||||
| @ -49,5 +49,21 @@ public class MemberTagDO extends BaseDO { | ||||
|      * 执行优先 | ||||
|      */ | ||||
|     private String state; | ||||
|     /** | ||||
|      * 时间段标志:0-关闭,1-开启 | ||||
|      */ | ||||
|     private String timeFlag; | ||||
|     /** | ||||
|      * 早 | ||||
|      */ | ||||
|     private BigDecimal morning; | ||||
|     /** | ||||
|      * 中 | ||||
|      */ | ||||
|     private BigDecimal noon; | ||||
|     /** | ||||
|      * 晚 | ||||
|      */ | ||||
|     private BigDecimal night; | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -8,6 +8,8 @@ import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardMonthVO; | ||||
| import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardPageReqVO; | ||||
| import cn.iocoder.yudao.module.member.controller.app.card.vo.FaceVo; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO; | ||||
| import cn.iocoder.yudao.module.member.util.MemberConstants; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
| import org.apache.ibatis.annotations.Param; | ||||
| import org.apache.ibatis.annotations.Select; | ||||
| @ -53,4 +55,16 @@ public interface CardMapper extends BaseMapperX<CardDO> { | ||||
|     List<CardDO> selectMoneyList(List<Long> list); | ||||
|  | ||||
|     FaceVo getFaceData(String faceId); | ||||
|  | ||||
|     default BigDecimal getMoneyByUsr(Long userId){ | ||||
|         CardDO lastCardDO = selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime) | ||||
|                 .orderByDesc(CardDO::getId) | ||||
|                 .last(MemberConstants.LIMIT_ONE)); | ||||
|         if (lastCardDO == null || lastCardDO.getMoney() == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return lastCardDO.getMoney(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -21,6 +21,7 @@ public interface IntegralRefundMapper extends BaseMapperX<RefundDO> { | ||||
|                 .eqIfPresent(RefundDO::getMoney, reqVO.getMoney()) | ||||
|                 .eqIfPresent(RefundDO::getStatus, reqVO.getStatus()) | ||||
|                 .eqIfPresent(RefundDO::getUserId, reqVO.getUserId()) | ||||
|                 .eqIfPresent(RefundDO::getMobile, reqVO.getMobile()) | ||||
|                 .likeIfPresent(RefundDO::getUserName, reqVO.getUserName()) | ||||
|                 .betweenIfPresent(RefundDO::getCreateTime, reqVO.getCreateTime()) | ||||
|                 .orderByDesc(RefundDO::getId)); | ||||
|  | ||||
| @ -0,0 +1,18 @@ | ||||
| package cn.iocoder.yudao.module.member.dal.mysql.refundlog; | ||||
|  | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.refundlog.RefundLogDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * 退款记录 Mapper | ||||
|  * | ||||
|  * @author 管理员 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface RefundLogMapper extends BaseMapperX<RefundLogDO> { | ||||
|  | ||||
|  | ||||
| } | ||||
| @ -25,4 +25,8 @@ public interface MemberTagMapper extends BaseMapperX<MemberTagDO> { | ||||
|     default MemberTagDO selelctByName(String name) { | ||||
|         return selectOne(MemberTagDO::getName, name); | ||||
|     } | ||||
|  | ||||
|     default MemberTagDO selelctByState(String name) { | ||||
|         return selectOne(MemberTagDO::getState, name); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -78,20 +78,41 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|  | ||||
|                 BigDecimal money = oldCardDO.getMoney(); | ||||
|                 //计算减免价格 | ||||
|                 BigDecimal reductionAmount = userService.getReductionAmount(userId, total); | ||||
|                 BigDecimal reductionAmount = BigDecimal.ZERO; | ||||
|                 if (total.compareTo(BigDecimal.ZERO) > 0) { | ||||
|                     reductionAmount = userService.getReductionAmount(userId, total, dishOrderDO.getCreateTime()); | ||||
|                 } | ||||
|                 dishOrderDO.setReductionAmount(reductionAmount); | ||||
|                 dishOrderDO.setReductionState(reductionAmount.compareTo(BigDecimal.ZERO)>0?"1":"0"); | ||||
|                 dishOrderDO.setReductionState(reductionAmount.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0"); | ||||
|  | ||||
|                 //计算减免后的总价 | ||||
|                 total = total.subtract(reductionAmount); | ||||
|  | ||||
|  | ||||
|                 if(total.compareTo(reductionAmount)<0){ | ||||
|                     total = BigDecimal.ZERO; | ||||
|                 }else { | ||||
|                     total = total.subtract(reductionAmount); | ||||
|                 } | ||||
|                  | ||||
|                 BigDecimal wxAmount = oldCardDO.getWxAmount(); | ||||
|                 BigDecimal giftAmount = oldCardDO.getGiftAmount(); | ||||
|                 BigDecimal cashAmount = oldCardDO.getCashAmount(); | ||||
|                 cardDO.setMoney(money.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 //待支付金额 最大退款金额 | ||||
|                 dishOrderDO.setRefundAmount(total); | ||||
|                 if (money.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|                     dishOrderDO.setPayAmount(total); | ||||
|                     dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|                 } else { | ||||
|                     if (total.compareTo(money) > 0) { | ||||
|                         dishOrderDO.setPayAmount(total.subtract(money).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                         dishOrderDO.setRefundAmount(money); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (total.compareTo(money) > 0) { | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.TOCOMPLETE); | ||||
|                     dishOrderDO.setWxAmount(wxAmount); | ||||
|                     dishOrderDO.setCashAmount(cashAmount); | ||||
|                     dishOrderDO.setGiftAmount(giftAmount); | ||||
|                 } else { | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                     //计算金额 | ||||
|  | ||||
| @ -23,6 +23,7 @@ import java.math.RoundingMode; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.temporal.ChronoUnit; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.stream.Collectors; | ||||
| @ -95,6 +96,14 @@ public class BusinessBatchJob implements JobHandler { | ||||
|                     .map(CardDO::getMoney) | ||||
|                     .reduce(BigDecimal.ZERO, BigDecimal::add); | ||||
|             build.setRechargePurse(reduce); | ||||
|             //提现金额 | ||||
|             BigDecimal withdrawal =cardMapper.selectList(new LambdaQueryWrapperX<CardDO>() | ||||
|                     .betweenIfPresent(CardDO::getCreateTime, startDate, endDate) | ||||
|                     .in(CardDO::getType, Arrays.asList(CostTypeEnum.WITHDRAW.getCode(),CostTypeEnum.CASH_WITHDRAW.getCode()))) | ||||
|                     .stream() | ||||
|                     .map(CardDO::getChangeMoney) | ||||
|                     .reduce(BigDecimal.ZERO, BigDecimal::add); | ||||
|             build.setWithdrawal(withdrawal); | ||||
|             //早餐 | ||||
|             value.forEach(x-> x.setPayMethods(TimePeriodEnum.getTimePeriod(x.getCreateTime()))); | ||||
|             Map<String, List<DishOrderDO>> collect1 = value.stream().collect(Collectors.groupingBy(DishOrderDO::getPayMethods)); | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| package cn.iocoder.yudao.module.member.service.card; | ||||
|  | ||||
| import cn.hutool.core.collection.CollectionUtil; | ||||
| import cn.hutool.core.math.Money; | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.iocoder.yudao.framework.common.exception.ServiceException; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| @ -14,12 +15,19 @@ import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardPageReqVO; | ||||
| import cn.iocoder.yudao.module.member.controller.app.card.vo.FaceVo; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.refund.RefundDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.refundlog.RefundLogDO; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.refund.IntegralRefundMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.refundlog.RefundLogMapper; | ||||
| import cn.iocoder.yudao.module.member.enums.CostTypeEnum; | ||||
| import cn.iocoder.yudao.module.member.service.refund.RefundService; | ||||
| import cn.iocoder.yudao.module.member.util.MemberConstants; | ||||
| import com.alibaba.druid.sql.visitor.functions.Left; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| @ -33,6 +41,7 @@ import java.time.LocalTime; | ||||
| import java.time.YearMonth; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| @ -56,6 +65,12 @@ public class CardServiceImpl implements CardService { | ||||
|     @Resource | ||||
|     private DishOrderMapper dishOrderMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private IntegralRefundMapper refundMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private RefundLogMapper refundLogMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Long createCard(CardSaveReqVO createReqVO) { | ||||
|         // 插入 | ||||
| @ -105,7 +120,7 @@ public class CardServiceImpl implements CardService { | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public Boolean recharge(BigDecimal money, String flag,BigDecimal giftMoney) { | ||||
|     public Boolean recharge(BigDecimal money, String flag, BigDecimal giftMoney) { | ||||
|         //获取最新余额 | ||||
|         CardDO lastCardDO = getLastCardDO(); | ||||
|         CardDO cardDO = new CardDO(); | ||||
| @ -114,9 +129,9 @@ public class CardServiceImpl implements CardService { | ||||
|         cardDO.setChangeMoney(money); | ||||
|         cardDO.setType(CostTypeEnum.WX_PAY.getCode()); | ||||
|         BigDecimal oldMoney = BigDecimal.ZERO; | ||||
|         BigDecimal wxOldMoney= BigDecimal.ZERO; | ||||
|         BigDecimal giftOldMoney= BigDecimal.ZERO; | ||||
|         BigDecimal cashAmount= BigDecimal.ZERO; | ||||
|         BigDecimal wxOldMoney = BigDecimal.ZERO; | ||||
|         BigDecimal giftOldMoney = BigDecimal.ZERO; | ||||
|         BigDecimal cashAmount = BigDecimal.ZERO; | ||||
|         if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getMoney() != null) { | ||||
|             oldMoney = lastCardDO.getMoney(); | ||||
|         } | ||||
| @ -133,27 +148,29 @@ public class CardServiceImpl implements CardService { | ||||
|         cardDO.setMoney(oldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|         cardDO.setCashAmount(cashAmount); | ||||
|         cardDO.setGiftAmount(giftOldMoney); | ||||
|         cardDO.setWxAmount(giftOldMoney); | ||||
|         if(cardDO.getMoney().compareTo(BigDecimal.ZERO) >0){ | ||||
|         cardDO.setWxAmount(wxOldMoney); | ||||
|         if (cardDO.getMoney().compareTo(BigDecimal.ZERO) > 0) { | ||||
|             BigDecimal wxAmount = money; | ||||
|             if(giftMoney!=null){ | ||||
|             if (giftMoney != null) { | ||||
|                 cardDO.setGiftAmount(giftOldMoney.add(giftMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 wxAmount = wxAmount.subtract(giftMoney); | ||||
|             } | ||||
|             if(oldMoney.compareTo(BigDecimal.ZERO)<0){ | ||||
|                 updateOrderStatus(cardDO.getUserId()); | ||||
|                if(wxAmount.add(oldMoney).compareTo(BigDecimal.ZERO)>=0){ | ||||
|                    cardDO.setWxAmount(wxAmount.add(oldMoney)); | ||||
|                }else{ | ||||
|                    BigDecimal left  = wxAmount.add(oldMoney); | ||||
|                    cardDO.setWxAmount(BigDecimal.ZERO); | ||||
|                    cardDO.setGiftAmount(giftMoney.add(left)); | ||||
|                } | ||||
|             }else{ | ||||
|             if (oldMoney.compareTo(BigDecimal.ZERO) < 0) { | ||||
|                 if (wxAmount.add(oldMoney).compareTo(BigDecimal.ZERO) >= 0) { | ||||
|                     cardDO.setWxAmount(wxAmount.add(oldMoney)); | ||||
|                 } else { | ||||
|                     BigDecimal left = wxAmount.add(oldMoney); | ||||
|                     cardDO.setWxAmount(BigDecimal.ZERO); | ||||
|                     cardDO.setGiftAmount(giftMoney.add(left)); | ||||
|                 } | ||||
|             } else { | ||||
|                 cardDO.setWxAmount(wxOldMoney.add(wxAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|             } | ||||
|         } | ||||
|         int i =cardMapper.insert(cardDO); | ||||
|         //处理未完全支付订单 | ||||
|         handleOrderWx(cardDO.getUserId(),money,giftMoney); | ||||
|  | ||||
|         int i = cardMapper.insert(cardDO); | ||||
|         return i > 0; | ||||
|     } | ||||
|  | ||||
| @ -169,7 +186,7 @@ public class CardServiceImpl implements CardService { | ||||
|     @Override | ||||
|     public BigDecimal getMoneyByUserId(Long userId) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|                 .orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).last(MemberConstants.LIMIT_ONE)); | ||||
|         if (lastCardDO == null || lastCardDO.getMoney() == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
| @ -179,7 +196,7 @@ public class CardServiceImpl implements CardService { | ||||
|     @Override | ||||
|     public CardDO getCardDoByUserId(Long userId) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|                 .orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).last(MemberConstants.LIMIT_ONE)); | ||||
|  | ||||
|         return lastCardDO; | ||||
|     } | ||||
| @ -191,12 +208,13 @@ public class CardServiceImpl implements CardService { | ||||
|      */ | ||||
|     public CardDO getLastCardDO() { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, SecurityFrameworkUtils.getLoginUserId()) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|                 .orderByDesc(CardDO::getCreateTime) | ||||
|                 .orderByDesc(CardDO::getId) | ||||
|                 .last(MemberConstants.LIMIT_ONE)); | ||||
|         return lastCardDO; | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public void insertBatch(List<CardDO> list) { | ||||
|         cardMapper.insertBatch(list); | ||||
| @ -238,7 +256,7 @@ public class CardServiceImpl implements CardService { | ||||
|         if (vo.getGroupId() != null) { | ||||
|             memberList.addAll(memberGroupMapper.getMemberList(vo.getGroupId())); | ||||
|         } else { | ||||
|             if (CollectionUtil.isEmpty(vo.getUserIds())){ | ||||
|             if (CollectionUtil.isEmpty(vo.getUserIds())) { | ||||
|                 throw new ServiceException(NEED_ADD_USER); | ||||
|             } | ||||
|             memberList.addAll(vo.getUserIds()); | ||||
| @ -261,15 +279,11 @@ public class CardServiceImpl implements CardService { | ||||
|             BigDecimal oldMoney = cardDO.getMoney(); | ||||
|             add.setMoney(oldMoney.add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|  | ||||
|             if(add.getMoney().compareTo(BigDecimal.ZERO) >0){ | ||||
|             if (add.getMoney().compareTo(BigDecimal.ZERO) > 0) { | ||||
|                 BigDecimal cashOldMoney = cardDO.getCashAmount(); | ||||
|                 add.setCashAmount(cashOldMoney.add(add.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 add.setCashAmount(cashOldMoney.add(add.getChangeMoney()).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 add.setWxAmount(cardDO.getWxAmount()); | ||||
|                 add.setGiftAmount(cardDO.getGiftAmount()); | ||||
|  | ||||
|                 if(oldMoney.compareTo(BigDecimal.ZERO)<0){ | ||||
|                     updateOrderStatus(cardDO.getUserId()); | ||||
|                 } | ||||
|             } | ||||
|             addList.add(add); | ||||
|  | ||||
| @ -288,22 +302,24 @@ public class CardServiceImpl implements CardService { | ||||
|                 addList.add(add); | ||||
|             } | ||||
|         } | ||||
|         //处理订单 | ||||
|         handleOrderCash(memberList,vo.getMoney()); | ||||
|  | ||||
|         //批量添加 | ||||
|         return cardMapper.insertBatch(addList); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public FaceVo getFaceData(String faceId){ | ||||
|     public FaceVo getFaceData(String faceId) { | ||||
|         return cardMapper.getFaceData(faceId); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void refund(Long userId,BigDecimal money,Long orderId) { | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void refund(Long userId, BigDecimal money, Long orderId) { | ||||
|         //获取最新余额 | ||||
|  | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|                 .orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).last(MemberConstants.LIMIT_ONE)); | ||||
|         DishOrderDO dishOrderDO = dishOrderMapper.selectById(orderId); | ||||
|  | ||||
|         CardDO cardDO = new CardDO(); | ||||
| @ -325,38 +341,227 @@ public class CardServiceImpl implements CardService { | ||||
|         BigDecimal dishWxAmount = dishOrderDO.getWxAmount(); | ||||
|         BigDecimal dishCashAmount = dishOrderDO.getCashAmount(); | ||||
|         BigDecimal dishGiftAmount = dishOrderDO.getGiftAmount(); | ||||
|         if (cardDO.getMoney().compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             cardDO.setWxAmount(BigDecimal.ZERO); | ||||
|             cardDO.setGiftAmount(BigDecimal.ZERO); | ||||
|             cardDO.setCashAmount(BigDecimal.ZERO); | ||||
|         } else { | ||||
|             if (money.compareTo(dishGiftAmount) <= 0) { | ||||
|                 cardDO.setGiftAmount(giftAmount.add(money).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|             } else { | ||||
|                 cardDO.setGiftAmount(giftAmount.add(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 BigDecimal money1 = money.subtract(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP); | ||||
|  | ||||
|         if(money.compareTo(dishGiftAmount)<=0){ | ||||
|             cardDO.setGiftAmount(giftAmount.add(money).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|         }else { | ||||
|             cardDO.setGiftAmount(giftAmount.add(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|             BigDecimal money1 = money.subtract(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP); | ||||
|                 if (money1.compareTo(dishCashAmount) <= 0) { | ||||
|                     cardDO.setCashAmount(cashAmount.add(money1).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 } else { | ||||
|                     cardDO.setCashAmount(cashAmount.add(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                     BigDecimal money2 = money1.subtract(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP); | ||||
|                     if (money2.compareTo(dishWxAmount) <= 0) { | ||||
|                         cardDO.setWxAmount(wxAmount.add(money2).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                     } else { | ||||
|                         cardDO.setWxAmount(wxAmount.add(dishWxAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                     } | ||||
|  | ||||
|             if(money1.compareTo(dishCashAmount)<=0){ | ||||
|                 cardDO.setCashAmount(cashAmount.add(money1).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|             }else { | ||||
|                 cardDO.setCashAmount(cashAmount.add(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 BigDecimal money2 = money1.subtract(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP); | ||||
|                 cardDO.setWxAmount(wxAmount.add(money2).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         //记录 | ||||
|         refundLog(dishOrderDO,money); | ||||
|         //订单处理 | ||||
|  | ||||
|         //可退款金额 | ||||
|         dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|         //待支付金额 | ||||
|         if (dishOrderDO.getPayAmount().compareTo(BigDecimal.ZERO) > 0) { | ||||
|             BigDecimal newPayAmount = dishOrderDO.getPayAmount().subtract(money); | ||||
|             if (newPayAmount.compareTo(BigDecimal.ZERO) > 0) { | ||||
|                 dishOrderDO.setPayAmount(newPayAmount); | ||||
|             } else { | ||||
|                 handleOtherMoney(dishOrderDO,money); | ||||
|                 dishOrderDO.setPayAmount(BigDecimal.ZERO); | ||||
|                 dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|             } | ||||
|         } | ||||
|         dishOrderMapper.updateById(dishOrderDO); | ||||
|         cardMapper.insert(cardDO); | ||||
|     } | ||||
|  | ||||
|     public void handleOtherMoney(DishOrderDO dishOrderDO,BigDecimal money){ | ||||
|         //查找其余未支付订单 | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(Wrappers.<DishOrderDO>lambdaQuery().eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE) | ||||
|                 .ne(DishOrderDO::getId, dishOrderDO.getId())); | ||||
|         if (CollectionUtil.isNotEmpty(dishOrderDOS)){ | ||||
|             //判断多出的金额来自哪一部分 | ||||
|             BigDecimal payAmount = dishOrderDO.getPayAmount(); | ||||
|             BigDecimal giftAmount = dishOrderDO.getGiftAmount(); | ||||
|             BigDecimal cashAmount = dishOrderDO.getCashAmount(); | ||||
|             BigDecimal wxAmount = dishOrderDO.getWxAmount(); | ||||
|  | ||||
|             //可用金额 | ||||
|             BigDecimal gift = BigDecimal.ZERO; | ||||
|             BigDecimal cash = BigDecimal.ZERO; | ||||
|             BigDecimal wx = BigDecimal.ZERO; | ||||
|  | ||||
|             //分配退款金额 | ||||
|             if(money.compareTo(giftAmount)<=0){ | ||||
|                 gift = money; | ||||
|             }else { | ||||
|                 gift = giftAmount; | ||||
|                 BigDecimal left = money.subtract(giftAmount); | ||||
|                 if(left.compareTo(cashAmount)<=0){ | ||||
|                     cash = left; | ||||
|                 }else { | ||||
|                     cash = cashAmount; | ||||
|                     BigDecimal left1 = left.subtract(cashAmount); | ||||
|                     if(left1.compareTo(wxAmount)<=0){ | ||||
|                         wx = left1; | ||||
|                     }else { | ||||
|                         wx = wxAmount; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|  | ||||
|             //去除该订单已支付的 | ||||
|             if(payAmount.compareTo(gift)<=0){ | ||||
|                 gift = gift.subtract(payAmount); | ||||
|             }else { | ||||
|                 BigDecimal left = payAmount.subtract(gift); | ||||
|                 gift = BigDecimal.ZERO; | ||||
|                 if(left.compareTo(cash)<=0){ | ||||
|                     cash = cash.subtract(left); | ||||
|                 }else{ | ||||
|                     BigDecimal left1 = left.subtract(cash); | ||||
|                     cash = BigDecimal.ZERO; | ||||
|                     if(left1.compareTo(wx)<=0){ | ||||
|                         wx = wx.subtract(left1); | ||||
|                     }else { | ||||
|                         wx= BigDecimal.ZERO; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             //待修改的订单 | ||||
|             ArrayList<DishOrderDO> update = new ArrayList<>(); | ||||
|  | ||||
|             //顺序补充直到金额用完跳出循环 | ||||
|             for (DishOrderDO vo : dishOrderDOS){ | ||||
|                 BigDecimal voPayAmount = vo.getPayAmount(); | ||||
|  | ||||
|                 //订单补充的金额 | ||||
|                 BigDecimal supGift = BigDecimal.ZERO; | ||||
|                 BigDecimal supCash = BigDecimal.ZERO; | ||||
|                 BigDecimal supWx = BigDecimal.ZERO; | ||||
|  | ||||
|  | ||||
|                 //计算 | ||||
|                 if(voPayAmount.compareTo(gift)<=0){ | ||||
|                     gift = gift.subtract(voPayAmount); | ||||
|                     supGift = voPayAmount; | ||||
|                 }else { | ||||
|                     voPayAmount = voPayAmount.subtract(gift); | ||||
|                     supGift = gift; | ||||
|                     gift = BigDecimal.ZERO; | ||||
|  | ||||
|                     if(voPayAmount.compareTo(cash)<=0){ | ||||
|                         cash = cash.subtract(voPayAmount); | ||||
|                         supCash = voPayAmount; | ||||
|                     }else{ | ||||
|                         voPayAmount = voPayAmount.subtract(cash); | ||||
|                         supCash = cash; | ||||
|                         cash = BigDecimal.ZERO; | ||||
|  | ||||
|                         if(voPayAmount.compareTo(wx)<=0){ | ||||
|                             wx = wx.subtract(voPayAmount); | ||||
|                             supWx = voPayAmount; | ||||
|                         }else { | ||||
|                             voPayAmount = voPayAmount.subtract(wx); | ||||
|                             supWx = wx; | ||||
|                             wx= BigDecimal.ZERO; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 //更改数据 | ||||
|                 vo.setGiftAmount(vo.getGiftAmount().add(supGift)); | ||||
|                 vo.setCashAmount(vo.getCashAmount().add(supCash)); | ||||
|                 vo.setWxAmount(vo.getWxAmount().add(supWx)); | ||||
|                 vo.setPayAmount(voPayAmount); | ||||
|                 vo.setRefundAmount(vo.getRefundAmount().add(supGift).add(supCash).add(supWx)); | ||||
|                 if(voPayAmount.compareTo(BigDecimal.ZERO)<=0){ | ||||
|                     vo.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                 } | ||||
|                 update.add(vo); | ||||
|                 //判断是否跳出循环 | ||||
|                 if(gift.compareTo(BigDecimal.ZERO) == 0 && cash.compareTo(BigDecimal.ZERO) == 0 && wx.compareTo(BigDecimal.ZERO) ==0){ | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             //批量 | ||||
|             if(CollectionUtil.isNotEmpty(update)){ | ||||
|                 dishOrderMapper.updateBatch(update); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void refundLog(DishOrderDO dishOrderDO,BigDecimal money){ | ||||
|         BigDecimal giftAmount = dishOrderDO.getGiftAmount(); | ||||
|         BigDecimal cashAmount = dishOrderDO.getCashAmount(); | ||||
|         BigDecimal wxAmount = dishOrderDO.getWxAmount(); | ||||
|  | ||||
|         //可用金额 | ||||
|         BigDecimal gift = BigDecimal.ZERO; | ||||
|         BigDecimal cash = BigDecimal.ZERO; | ||||
|         BigDecimal wx = BigDecimal.ZERO; | ||||
|  | ||||
|         //分配退款金额 | ||||
|         if(money.compareTo(giftAmount)<=0){ | ||||
|             gift = money; | ||||
|         }else { | ||||
|             gift = giftAmount; | ||||
|             BigDecimal left = money.subtract(giftAmount); | ||||
|             if(left.compareTo(cashAmount)<=0){ | ||||
|                 cash = left; | ||||
|             }else { | ||||
|                 cash = cashAmount; | ||||
|                 BigDecimal left1 = left.subtract(cashAmount); | ||||
|                 if(left1.compareTo(wxAmount)<=0){ | ||||
|                     wx = left1; | ||||
|                 }else { | ||||
|                     wx = wxAmount; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         List<RefundLogDO> refundLogDOS = refundLogMapper.selectList(Wrappers.<RefundLogDO>lambdaQuery() | ||||
|                 .apply("TO_DAYS(NOW())-TO_DAYS(create_time) = 0")); | ||||
|         if(CollectionUtil.isNotEmpty(refundLogDOS)){ | ||||
|             RefundLogDO refundLogDO = refundLogDOS.get(0); | ||||
|             refundLogDO.setMoney(refundLogDO.getMoney().add(wx)); | ||||
|             refundLogMapper.updateById(refundLogDO); | ||||
|         }else { | ||||
|             RefundLogDO refundLogDO = new RefundLogDO(); | ||||
|             refundLogDO.setMoney(wx); | ||||
|             refundLogDO.setCreateTime(LocalDateTime.now()); | ||||
|             refundLogMapper.insert(refundLogDO); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public BigDecimal checkOrder(Long userId) { | ||||
|  | ||||
|         LambdaQueryWrapper<DishOrderDO> wrapper = new LambdaQueryWrapper<>(); | ||||
|  | ||||
|         wrapper.eq(DishOrderDO::getUserId,userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus,DishOrderDO.TOCOMPLETE); | ||||
|         wrapper.eq(DishOrderDO::getUserId, userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE); | ||||
|  | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(wrapper); | ||||
|  | ||||
|         if(CollectionUtil.isNotEmpty(dishOrderDOS)){ | ||||
|         if (CollectionUtil.isNotEmpty(dishOrderDOS)) { | ||||
|             BigDecimal reduce = dishOrderDOS.stream().map(DishOrderDO::getTotalMoney).reduce(BigDecimal.ZERO, BigDecimal::add); | ||||
|             return reduce; | ||||
|         }else { | ||||
|         } else { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|     } | ||||
| @ -364,19 +569,20 @@ public class CardServiceImpl implements CardService { | ||||
|     @Override | ||||
|     public BigDecimal getCashMoney(Long userId) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|         if(ObjectUtil.isNotEmpty(lastCardDO)){ | ||||
|                 .orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId) | ||||
|                 .last(MemberConstants.LIMIT_ONE)); | ||||
|         if (ObjectUtil.isNotEmpty(lastCardDO)) { | ||||
|             return lastCardDO.getCashAmount(); | ||||
|         } | ||||
|         return BigDecimal.ZERO; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean cashDraw(Long userId,BigDecimal money) { | ||||
|     public Boolean cashDraw(Long userId, BigDecimal money) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|         if(ObjectUtil.isEmpty(lastCardDO) || lastCardDO.getCashAmount().compareTo(BigDecimal.ZERO)<1 | ||||
|             || money.compareTo(lastCardDO.getCashAmount())>0){ | ||||
|                 .orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).last(MemberConstants.LIMIT_ONE)); | ||||
|         if (ObjectUtil.isEmpty(lastCardDO) || lastCardDO.getCashAmount().compareTo(BigDecimal.ZERO) < 1 | ||||
|                 || money.compareTo(lastCardDO.getCashAmount()) > 0) { | ||||
|             throw exception(CASH_AMOUNT_NOT_ENOUGH); | ||||
|         } | ||||
|         CardDO cardDO = new CardDO(); | ||||
| @ -385,7 +591,7 @@ public class CardServiceImpl implements CardService { | ||||
|         cardDO.setChangeMoney(money); | ||||
|         cardDO.setType(CostTypeEnum.CASH_WITHDRAW.getCode()); | ||||
|  | ||||
|         BigDecimal oldMoney  = lastCardDO.getMoney(); | ||||
|         BigDecimal oldMoney = lastCardDO.getMoney(); | ||||
|         BigDecimal oldWxAmount = lastCardDO.getWxAmount(); | ||||
|         BigDecimal oldCashAmount = lastCardDO.getCashAmount(); | ||||
|         BigDecimal oldGiftAmount = lastCardDO.getGiftAmount(); | ||||
| @ -395,20 +601,127 @@ public class CardServiceImpl implements CardService { | ||||
|         cardDO.setMoney(oldMoney.subtract(money)); | ||||
|         cardDO.setCashAmount(oldCashAmount.subtract(money)); | ||||
|         int insert = cardMapper.insert(cardDO); | ||||
|         return insert>0; | ||||
|         return insert > 0; | ||||
|     } | ||||
|  | ||||
|     void updateOrderStatus(Long userId){ | ||||
|         LambdaQueryWrapper<DishOrderDO> wrapper = new LambdaQueryWrapper<>(); | ||||
|     void updateOrderStatus(Long userId) { | ||||
|         LambdaUpdateWrapper<DishOrderDO> wrapper = new LambdaUpdateWrapper<>(); | ||||
|  | ||||
|         wrapper.eq(DishOrderDO::getUserId,userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus,DishOrderDO.TOCOMPLETE); | ||||
|         wrapper.eq(DishOrderDO::getUserId, userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE); | ||||
|         wrapper.set(DishOrderDO::getOrderStatus, DishOrderDO.COMPLETE); | ||||
|         dishOrderMapper.update(wrapper); | ||||
|  | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(wrapper); | ||||
|         if(CollectionUtil.isNotEmpty(dishOrderDOS)){ | ||||
|             dishOrderDOS.forEach(vo -> vo.setOrderStatus(DishOrderDO.COMPLETE)); | ||||
|             dishOrderMapper.updateBatch(dishOrderDOS); | ||||
|     } | ||||
|  | ||||
|     void handleOrderWx(Long userId, BigDecimal money, BigDecimal giftAmount) { | ||||
|         BigDecimal wxMoney = money; | ||||
|         BigDecimal giftMoney = BigDecimal.ZERO; | ||||
|         if (giftAmount != null) { | ||||
|             wxMoney = money.subtract(giftMoney); | ||||
|             giftMoney = giftAmount; | ||||
|         } | ||||
|         //已审核的订单 | ||||
|         List<Long> refundOrder = getRefundOrder(); | ||||
|  | ||||
|         //查询出所有未完全支付订单 | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(Wrappers.<DishOrderDO>lambdaQuery() | ||||
|                 .eq(DishOrderDO::getUserId, userId).eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE)); | ||||
|  | ||||
|         ArrayList<DishOrderDO> updateList = new ArrayList<>(); | ||||
|         if (CollectionUtil.isNotEmpty(dishOrderDOS)) { | ||||
|             for (DishOrderDO dishOrderDO : dishOrderDOS) { | ||||
|                 BigDecimal payAmount = dishOrderDO.getPayAmount(); | ||||
|                 if(payAmount.compareTo(money)<=0){ | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                     dishOrderDO.setPayAmount(BigDecimal.ZERO); | ||||
|                     dishOrderDO.setRefundAmount(dishOrderDO.getRefundAmount().add(payAmount)); | ||||
|                     if(refundOrder.contains(dishOrderDO.getId())){ | ||||
|                         dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|                     } | ||||
|                     if(payAmount.compareTo(wxMoney)<=0){ | ||||
|                         dishOrderDO.setWxAmount(dishOrderDO.getWxAmount().add(payAmount)); | ||||
|                         wxMoney = wxMoney.subtract(payAmount); | ||||
|                     }else { | ||||
|                         dishOrderDO.setWxAmount(dishOrderDO.getWxAmount().add(wxMoney)); | ||||
|                         wxMoney = BigDecimal.ZERO; | ||||
|                         BigDecimal left = payAmount.subtract(wxMoney); | ||||
|                         dishOrderDO.setGiftAmount(dishOrderDO.getGiftAmount().add(left)); | ||||
|                         giftMoney = giftMoney.subtract(left); | ||||
|                     } | ||||
|                     money = money.subtract(payAmount); | ||||
|  | ||||
|                     updateList.add(dishOrderDO); | ||||
|                 }else { | ||||
|                     dishOrderDO.setPayAmount(payAmount.subtract(money)); | ||||
|                     dishOrderDO.setRefundAmount(dishOrderDO.getRefundAmount().add(money)); | ||||
|                     if(refundOrder.contains(dishOrderDO.getId())){ | ||||
|                         dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|                     } | ||||
|                     dishOrderDO.setWxAmount(dishOrderDO.getWxAmount().add(wxMoney)); | ||||
|                     dishOrderDO.setGiftAmount(dishOrderDO.getGiftAmount().add(giftMoney)); | ||||
|                     updateList.add(dishOrderDO); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if(CollectionUtil.isNotEmpty(updateList)){ | ||||
|             dishOrderMapper.updateBatch(updateList); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     void handleOrderCash(List<Long> userIds, BigDecimal money) { | ||||
|         ArrayList<DishOrderDO> updateList = new ArrayList<>(); | ||||
|         List<Long> refundOrder = getRefundOrder(); | ||||
|         //查询出所有未完全支付订单 | ||||
|         for (Long userId : userIds){ | ||||
|             BigDecimal cashMoney = money; | ||||
|  | ||||
|             List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(Wrappers.<DishOrderDO>lambdaQuery() | ||||
|                     .eq(DishOrderDO::getUserId, userId).eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE)); | ||||
|  | ||||
|             if (CollectionUtil.isNotEmpty(dishOrderDOS)) { | ||||
|                 for (DishOrderDO dishOrderDO : dishOrderDOS) { | ||||
|                     BigDecimal payAmount = dishOrderDO.getPayAmount(); | ||||
|                     if(payAmount.compareTo(cashMoney)<=0){ | ||||
|                         dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                         dishOrderDO.setPayAmount(BigDecimal.ZERO); | ||||
|                         dishOrderDO.setRefundAmount(dishOrderDO.getRefundAmount().add(payAmount)); | ||||
|                         if(refundOrder.contains(dishOrderDO.getId())){ | ||||
|                             dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|                         } | ||||
|                         dishOrderDO.setCashAmount(dishOrderDO.getCashAmount().add(payAmount)); | ||||
|                         cashMoney = cashMoney.subtract(payAmount); | ||||
|                         updateList.add(dishOrderDO); | ||||
|                     }else { | ||||
|                         dishOrderDO.setPayAmount(payAmount.subtract(cashMoney)); | ||||
|                         dishOrderDO.setRefundAmount(dishOrderDO.getRefundAmount().add(cashMoney)); | ||||
|                         if(refundOrder.contains(dishOrderDO.getId())){ | ||||
|                             dishOrderDO.setRefundAmount(BigDecimal.ZERO); | ||||
|                         } | ||||
|                         dishOrderDO.setCashAmount(dishOrderDO.getCashAmount().add(cashMoney)); | ||||
|                         updateList.add(dishOrderDO); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if(CollectionUtil.isNotEmpty(updateList)){ | ||||
|             dishOrderMapper.updateBatch(updateList); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public List<Long> getRefundOrder(){ | ||||
|         List<RefundDO> refundDOS = refundMapper.selectList(Wrappers.<RefundDO>lambdaQuery().in(RefundDO::getStatus, Arrays.asList("2", "3"))); | ||||
|         ArrayList<Long> orderIds = new ArrayList<>(); | ||||
|         if(CollectionUtil.isNotEmpty(refundDOS)){ | ||||
|             List<Long> collect = refundDOS.stream().map(RefundDO::getOrderId).collect(Collectors.toList()); | ||||
|             orderIds.addAll(collect); | ||||
|         } | ||||
|  | ||||
|         return orderIds; | ||||
|     } | ||||
| } | ||||
| @ -186,7 +186,9 @@ public class CarteenMoneyServiceImpl implements CarteenMoneyService { | ||||
|                     .carteenName(value.get(0).getStoreName()) | ||||
|                     .carteenId(storeId1) | ||||
|                     .successMoney(bigDecimal1) | ||||
|                     .sumMoney(bigDecimal1).build(); | ||||
|                     .sumMoney(bigDecimal1) | ||||
|                     .build(); | ||||
|             build.setCreateTime( LocalDateTime.now().minusDays(1)); | ||||
|             list.add(build); | ||||
|         } | ||||
|         return list; | ||||
|  | ||||
| @ -251,6 +251,9 @@ public class DiningPlatesServiceImpl implements DiningPlatesService { | ||||
|         if (diningPlatesDO == null || diningPlatesDO.getUserId() == null) { | ||||
|             return false; | ||||
|         } | ||||
|         //刷新绑定时间 | ||||
|         diningPlatesDO.setBindingTime(LocalDateTime.now()); | ||||
|         diningPlatesMapper.updateById(diningPlatesDO); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
| @ -270,7 +273,6 @@ public class DiningPlatesServiceImpl implements DiningPlatesService { | ||||
|         return data; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public void checkDiningPlates(DiningPlatesDO diningPlatesDO) { | ||||
|         if (diningPlatesDO == null) { | ||||
|             throw exception(DINING_PLATES_NOT_EXISTS); | ||||
|  | ||||
| @ -176,6 +176,8 @@ public class OrderServiceImpl implements OrderService { | ||||
|                 dishOrderDO.setRefundStatus(refundService.getRefundStatus(dishOrderDO.getId())); | ||||
|             } | ||||
|             dishOrderDO.setDetailList(appOrderDetailRespVOS); | ||||
|             dishOrderDO.setMoney(cardMapper.getMoneyByUsr(dishOrderDO.getUserId())); | ||||
|  | ||||
|         } | ||||
|         return appOrderRespVOPageResult; | ||||
|     } | ||||
| @ -232,6 +234,8 @@ public class OrderServiceImpl implements OrderService { | ||||
|         bean.setPayMethods("钱包"); | ||||
|         bean.setUserAccount(userDO.getMobile()); | ||||
|         bean.setTimePeriod(TimePeriodEnum.getTimeName(bean.getCreateTime())); | ||||
|         BigDecimal moneyByUsr = cardMapper.getMoneyByUsr(bean.getUserId()); | ||||
|         bean.setMoney(moneyByUsr); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -72,11 +72,13 @@ public class OrderDetailServiceImpl implements OrderDetailService { | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public Long createOrderDetail(AppOrderDetailSaveReqVO createReqVO) { | ||||
|         //判定餐盘是否绑定 | ||||
|         //判定餐盘是否绑定并刷新绑定时间 | ||||
|         Boolean b = diningPlatesService.checkBind(createReqVO.getDiningPlatesNum()); | ||||
|         if(!b){ | ||||
|             throw exception(DINING_PLATES_NOT_BIND); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         //餐盘号去获取订单 | ||||
|         DishOrderDO dishOrderDO = dishOrderMapper.selectOne(Wrappers.<DishOrderDO>lambdaQuery().eq(DishOrderDO::getDiningPlatesNum, createReqVO.getDiningPlatesNum()) | ||||
|                 .eq(DishOrderDO::getOrderStatus, DishOrderDO.INCOMPLETE) | ||||
|  | ||||
| @ -7,11 +7,14 @@ import cn.iocoder.yudao.module.member.controller.admin.refund.vo.RefundPageReqVO | ||||
| import cn.iocoder.yudao.module.member.controller.admin.refund.vo.RefundSaveReqVO; | ||||
| import cn.iocoder.yudao.module.member.controller.app.refund.vo.AppRefundSaveReqVO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.refund.RefundDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.refund.IntegralRefundMapper; | ||||
| import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; | ||||
| import cn.iocoder.yudao.module.member.enums.RefundStatusEnum; | ||||
| import cn.iocoder.yudao.module.member.service.card.CardService; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| @ -32,6 +35,8 @@ public class RefundServiceImpl implements RefundService { | ||||
|     private IntegralRefundMapper refundMapper; | ||||
|     @Resource | ||||
|     private CardService cardService; | ||||
|     @Resource | ||||
|     private MemberUserMapper userMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Long createRefund(RefundSaveReqVO createReqVO) { | ||||
| @ -43,6 +48,7 @@ public class RefundServiceImpl implements RefundService { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void updateRefund(RefundSaveReqVO updateReqVO) { | ||||
|         // 校验存在 | ||||
|         validateRefundExists(updateReqVO.getId()); | ||||
| @ -82,6 +88,8 @@ public class RefundServiceImpl implements RefundService { | ||||
|     public Long createAppRefund(AppRefundSaveReqVO createReqVO) { | ||||
|         // 插入 | ||||
|         RefundDO refund = BeanUtils.toBean(createReqVO, RefundDO.class); | ||||
|         MemberUserDO memberUserDO = userMapper.selectById(refund.getUserId()); | ||||
|         refund.setMobile(memberUserDO.getMobile()); | ||||
|         refundMapper.insert(refund); | ||||
|         // 返回 | ||||
|         return refund.getId(); | ||||
|  | ||||
| @ -44,6 +44,9 @@ public class MemberTagServiceImpl implements MemberTagService { | ||||
|     public Long createTag(MemberTagCreateReqVO createReqVO) { | ||||
|         // 校验名称唯一 | ||||
|         validateTagNameUnique(null, createReqVO.getName()); | ||||
|         // 校验优先级唯一 | ||||
|         validateTagStateUnique(null, createReqVO.getState()); | ||||
|  | ||||
|         // 插入 | ||||
|         MemberTagDO tag = MemberTagConvert.INSTANCE.convert(createReqVO); | ||||
|         memberTagMapper.insert(tag); | ||||
| @ -57,6 +60,8 @@ public class MemberTagServiceImpl implements MemberTagService { | ||||
|         validateTagExists(updateReqVO.getId()); | ||||
|         // 校验名称唯一 | ||||
|         validateTagNameUnique(updateReqVO.getId(), updateReqVO.getName()); | ||||
|         // 校验优先级唯一 | ||||
|         validateTagStateUnique(updateReqVO.getId(), updateReqVO.getState()); | ||||
|         // 更新 | ||||
|         MemberTagDO updateObj = MemberTagConvert.INSTANCE.convert(updateReqVO); | ||||
|         memberTagMapper.updateById(updateObj); | ||||
| @ -96,6 +101,24 @@ public class MemberTagServiceImpl implements MemberTagService { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void validateTagStateUnique(Long id, String state) { | ||||
|         if (StrUtil.isBlank(state)) { | ||||
|             return; | ||||
|         } | ||||
|         MemberTagDO tag = memberTagMapper.selelctByState(state); | ||||
|         if (tag == null) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // 如果 id 为空,说明不用比较是否为相同 id 的标签 | ||||
|         if (id == null) { | ||||
|             throw exception(TAG_STATE_EXISTS); | ||||
|         } | ||||
|         if (!tag.getId().equals(id)) { | ||||
|             throw exception(TAG_STATE_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void validateTagHasUser(Long id) { | ||||
|         Long count = memberUserService.getUserCountByTagId(id); | ||||
|         if (count > 0) { | ||||
|  | ||||
| @ -243,5 +243,5 @@ public interface MemberUserService { | ||||
|  | ||||
|     String getCardId(Long userId); | ||||
|  | ||||
|     BigDecimal getReductionAmount(Long userId,BigDecimal money); | ||||
|     BigDecimal getReductionAmount(Long userId,BigDecimal money,LocalDateTime time); | ||||
| } | ||||
|  | ||||
| @ -62,6 +62,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import com.google.common.annotations.VisibleForTesting; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.ibatis.annotations.Case; | ||||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| @ -75,12 +76,7 @@ import java.math.RoundingMode; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.time.temporal.WeekFields; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.*; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| @ -747,7 +743,10 @@ public class MemberUserServiceImpl implements MemberUserService { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public BigDecimal getReductionAmount(Long userId, BigDecimal money) { | ||||
|     public BigDecimal getReductionAmount(Long userId, BigDecimal money,LocalDateTime time) { | ||||
|  | ||||
|         String timePeriod = TimePeriodEnum.getTimePeriod(time); | ||||
|  | ||||
|         MemberUserDO memberUserDO = memberUserMapper.selectById(userId); | ||||
|         List<Long> tagIds = memberUserDO.getTagIds(); | ||||
|         if (CollectionUtil.isEmpty(tagIds)){ | ||||
| @ -756,25 +755,62 @@ public class MemberUserServiceImpl implements MemberUserService { | ||||
|         List<MemberTagDO> tagList = memberTagService.getTagList(tagIds); | ||||
|  | ||||
|         if(tagList.size()>1){ | ||||
|             List<MemberTagDO> collect = tagList.stream().filter(vo -> vo.getState().equals("1")).collect(Collectors.toList()); | ||||
|             if(CollectionUtil.isEmpty(collect)){ | ||||
|                 return countAmount(tagList.get(0),money); | ||||
|             }else { | ||||
|                 return countAmount(collect.get(0),money); | ||||
|             } | ||||
|             //排序 | ||||
|             List<MemberTagDO> collect = tagList.stream().sorted(Comparator.comparing(MemberTagDO::getState)) | ||||
|                     .collect(Collectors.toList()); | ||||
|             return countAmount(collect.get(0),money,timePeriod); | ||||
|         }else { | ||||
|             return countAmount(tagList.get(0),money); | ||||
|             return countAmount(tagList.get(0),money,timePeriod); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public BigDecimal countAmount(MemberTagDO memberTagDO,BigDecimal money){ | ||||
|     public BigDecimal countAmount(MemberTagDO memberTagDO,BigDecimal money,String timePeriod ){ | ||||
|         if(memberTagDO.getType().equals("1")){ | ||||
|             BigDecimal bigDecimal = money.multiply(memberTagDO.getProportion()).setScale(2, RoundingMode.HALF_UP); | ||||
|             return bigDecimal; | ||||
|             if (memberTagDO.getTimeFlag().equals("0")){ | ||||
|                 return money.multiply(memberTagDO.getProportion()).setScale(2, RoundingMode.HALF_UP); | ||||
|             }else { | ||||
|                 BigDecimal bigDecimal; | ||||
|                 switch (timePeriod){ | ||||
|                     case "2": | ||||
|                         bigDecimal = money.multiply(memberTagDO.getMorning()).setScale(2, RoundingMode.HALF_UP); | ||||
|                         break; | ||||
|                     case "3": | ||||
|                         bigDecimal = money.multiply(memberTagDO.getNoon()).setScale(2, RoundingMode.HALF_UP); | ||||
|                         break; | ||||
|                     case "4": | ||||
|                         bigDecimal = money.multiply(memberTagDO.getNight()).setScale(2, RoundingMode.HALF_UP); | ||||
|                         break; | ||||
|                     default: | ||||
|                         bigDecimal = BigDecimal.ZERO; | ||||
|                         break; | ||||
|                 } | ||||
|                 return bigDecimal; | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         if(memberTagDO.getType().equals("2")){ | ||||
|             return memberTagDO.getAmount(); | ||||
|             if (memberTagDO.getTimeFlag().equals("0")){ | ||||
|                 return memberTagDO.getAmount(); | ||||
|             }else { | ||||
|                 BigDecimal bigDecimal; | ||||
|                 switch (timePeriod){ | ||||
|                     case "2": | ||||
|                         bigDecimal = memberTagDO.getMorning(); | ||||
|                         break; | ||||
|                     case "3": | ||||
|                         bigDecimal = memberTagDO.getNoon(); | ||||
|                         break; | ||||
|                     case "4": | ||||
|                         bigDecimal = memberTagDO.getNight(); | ||||
|                         break; | ||||
|                     default: | ||||
|                         bigDecimal = BigDecimal.ZERO; | ||||
|                         break; | ||||
|                 } | ||||
|                 return bigDecimal; | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         return BigDecimal.ZERO; | ||||
|     } | ||||
|  | ||||
| @ -12,7 +12,7 @@ public class MemberConstants { | ||||
|     /** | ||||
|      * 报警余额 | ||||
|      */ | ||||
|     public static final BigDecimal ALARM_BALANCE = new BigDecimal("30"); | ||||
|     public static final BigDecimal ALARM_BALANCE = new BigDecimal("15"); | ||||
|  | ||||
|     /** | ||||
|      * 时间格式 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 seesaw
					seesaw