优化
This commit is contained in:
@ -147,4 +147,12 @@ public class OrderController {
|
|||||||
orderService.abnormalHandle(orderId,mobile);
|
orderService.abnormalHandle(orderId,mobile);
|
||||||
return CommonResult.success(true);
|
return CommonResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/orderTransfer")
|
||||||
|
@Operation(summary = "转让订单")
|
||||||
|
public CommonResult<Boolean> orderTransfer(Long orderId,String mobile){
|
||||||
|
orderService.orderTransfer(orderId,mobile);
|
||||||
|
return CommonResult.success(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,4 +104,11 @@ public class OrderDetailsRespVO {
|
|||||||
* 补贴金额
|
* 补贴金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal subsidyAmount;
|
private BigDecimal subsidyAmount;
|
||||||
|
|
||||||
|
private String transferState;
|
||||||
|
|
||||||
|
private LocalDateTime transferTime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,5 +110,19 @@ public class AppOrderController {
|
|||||||
return CommonResult.success(true);
|
return CommonResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/abnormalHandle")
|
||||||
|
@Operation(summary = "异常订单指定用户扣款")
|
||||||
|
public CommonResult<Boolean> abnormalHandle(Long orderId,String mobile){
|
||||||
|
orderService.abnormalHandle(orderId,mobile);
|
||||||
|
return CommonResult.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/orderTransfer")
|
||||||
|
@Operation(summary = "转让订单")
|
||||||
|
public CommonResult<Boolean> orderTransfer(Long orderId,String mobile){
|
||||||
|
orderService.orderTransfer(orderId,mobile);
|
||||||
|
return CommonResult.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -4,14 +4,10 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
|||||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员订单 DO
|
* 会员订单 DO
|
||||||
@ -114,4 +110,8 @@ public class DishOrderDO extends BaseDO {
|
|||||||
* 补贴金额
|
* 补贴金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal subsidyAmount;
|
private BigDecimal subsidyAmount;
|
||||||
|
|
||||||
|
private String transferState;
|
||||||
|
|
||||||
|
private LocalDateTime transferTime;
|
||||||
}
|
}
|
@ -21,6 +21,11 @@ public interface DeductionService {
|
|||||||
*/
|
*/
|
||||||
void abnormalOrderDeduct(DishOrderDO dishOrderDO);
|
void abnormalOrderDeduct(DishOrderDO dishOrderDO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单转让处理
|
||||||
|
*/
|
||||||
|
void orderTransferHandle(DishOrderDO dishOrderDO,Long transferUserId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 现金提现
|
* 现金提现
|
||||||
*/
|
*/
|
||||||
|
@ -18,16 +18,17 @@ import cn.iocoder.yudao.module.member.service.group.MemberGroupService;
|
|||||||
import cn.iocoder.yudao.module.member.service.holiday.HolidayService;
|
import cn.iocoder.yudao.module.member.service.holiday.HolidayService;
|
||||||
import cn.iocoder.yudao.module.member.service.money.MoneyService;
|
import cn.iocoder.yudao.module.member.service.money.MoneyService;
|
||||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||||
|
import cn.iocoder.yudao.module.member.util.MemberTimeUtils;
|
||||||
import com.sun.istack.NotNull;
|
import com.sun.istack.NotNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.CASH_AMOUNT_NOT_ALLOW;
|
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.CASH_AMOUNT_NOT_ALLOW;
|
||||||
@ -279,7 +280,7 @@ public class DeductionServiceImpl implements DeductionService {
|
|||||||
} else {
|
} else {
|
||||||
dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE);
|
dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE);
|
||||||
//扣除具体金额
|
//扣除具体金额
|
||||||
if (judge(userId)) { //微信->现金
|
if (judge(userId, MemberTimeUtils.Time2StringDate(dishOrderDO.getCreateTime()))) { //微信->现金
|
||||||
if (total.compareTo(wxAmount) <= 0) {
|
if (total.compareTo(wxAmount) <= 0) {
|
||||||
user.setWxAmount(wxAmount.subtract(total));
|
user.setWxAmount(wxAmount.subtract(total));
|
||||||
dishOrderDO.setWxAmount(total);
|
dishOrderDO.setWxAmount(total);
|
||||||
@ -348,6 +349,191 @@ public class DeductionServiceImpl implements DeductionService {
|
|||||||
updateRedis(userId, name, newMoney);
|
updateRedis(userId, name, newMoney);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void orderTransferHandle(DishOrderDO dishOrderDO, Long transferUserId) {
|
||||||
|
//退款处理
|
||||||
|
if (dishOrderDO.getOrderStatus().equals(DishOrderDO.INCOMPLETE)) {
|
||||||
|
dishOrderDO.setUserId(transferUserId);
|
||||||
|
} else if (dishOrderDO.getOrderStatus().equals(DishOrderDO.COMPLETE)) {
|
||||||
|
transferRefund(dishOrderDO);
|
||||||
|
transferDeduct(dishOrderDO, transferUserId);
|
||||||
|
} else if (dishOrderDO.getOrderStatus().equals(DishOrderDO.TOCOMPLETE)) {
|
||||||
|
transferRefund(dishOrderDO);
|
||||||
|
transferDeduct(dishOrderDO, transferUserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void transferRefund(DishOrderDO dishOrderDO) {
|
||||||
|
//退款
|
||||||
|
BigDecimal wxNewMoney;
|
||||||
|
BigDecimal cashNewMoney;
|
||||||
|
BigDecimal newMoney;
|
||||||
|
String name;
|
||||||
|
Long userId = dishOrderDO.getUserId();
|
||||||
|
BigDecimal total = dishOrderDO.getTotalMoney().subtract(dishOrderDO.getPayAmount());
|
||||||
|
synchronized (getUserLock(userId)) {
|
||||||
|
MemberUserDO user = userService.getUser(userId);
|
||||||
|
//用户当前金额
|
||||||
|
BigDecimal userMoney = user.getMoney();
|
||||||
|
BigDecimal cashAmount = user.getCashAmount();
|
||||||
|
user.setCashAmount(cashAmount.add(total));
|
||||||
|
user.setMoney(userMoney.add(total));
|
||||||
|
userService.updateById(user);
|
||||||
|
wxNewMoney = user.getWxAmount();
|
||||||
|
newMoney = user.getMoney();
|
||||||
|
cashNewMoney = user.getCashAmount();
|
||||||
|
name = user.getNickname();
|
||||||
|
}
|
||||||
|
CardDO cardDO = new CardDO();
|
||||||
|
cardDO.setUserId(userId);
|
||||||
|
cardDO.setFlag(CardDO.ADD);
|
||||||
|
cardDO.setChangeMoney(total);
|
||||||
|
cardDO.setType(CostTypeEnum.REFUND.getCode());
|
||||||
|
cardDO.setWxAmount(wxNewMoney);
|
||||||
|
cardDO.setCashAmount(cashNewMoney);
|
||||||
|
cardDO.setCarteenId(dishOrderDO.getStoreId());
|
||||||
|
cardDO.setMoney(newMoney);
|
||||||
|
cardService.insertOne(cardDO);
|
||||||
|
|
||||||
|
StatisticsVo statisticsVo = new StatisticsVo();
|
||||||
|
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
|
||||||
|
statisticsVo.setTotalMoney(total.negate());
|
||||||
|
statisticsVo.setOrderSum(-1);
|
||||||
|
statisticsVo.setReduceMoney(dishOrderDO.getReductionAmount().negate());
|
||||||
|
statisticsVo.setTime(dishOrderDO.getCreateTime());
|
||||||
|
statisticsVo.setOrderId(dishOrderDO.getId());
|
||||||
|
statisticsVo.setSubsidyPurse(dishOrderDO.getSubsidyAmount().negate());
|
||||||
|
businessService.updateStatistics(statisticsVo);
|
||||||
|
|
||||||
|
//更新redis
|
||||||
|
updateRedis(userId, name, newMoney);
|
||||||
|
}
|
||||||
|
|
||||||
|
void transferDeduct(DishOrderDO dishOrderDO, Long userId) {
|
||||||
|
//扣款
|
||||||
|
BigDecimal wxNewMoney;
|
||||||
|
BigDecimal cashNewMoney;
|
||||||
|
BigDecimal newMoney;
|
||||||
|
String name;
|
||||||
|
synchronized (getUserLock(userId)) {
|
||||||
|
MemberUserDO user = userService.getUser(userId);
|
||||||
|
dishOrderDO.setUserId(userId);
|
||||||
|
//新的总价
|
||||||
|
BigDecimal total = dishOrderDO.getTotalMoney().add(dishOrderDO.getReductionAmount()).add(dishOrderDO.getSubsidyAmount());
|
||||||
|
|
||||||
|
//计算减免价格
|
||||||
|
BigDecimal reductionAmount = BigDecimal.ZERO;
|
||||||
|
//补贴
|
||||||
|
BigDecimal subsidyAmount = BigDecimal.ZERO;
|
||||||
|
if (total.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
subsidyAmount = userService.getReductionAmount(userId, total, dishOrderDO.getCreateTime());
|
||||||
|
}
|
||||||
|
dishOrderDO.setSubsidyAmount(subsidyAmount);
|
||||||
|
dishOrderDO.setReductionAmount(BigDecimal.ZERO);
|
||||||
|
dishOrderDO.setReductionState(reductionAmount.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
|
||||||
|
//计算减免后的总价
|
||||||
|
reductionAmount = reductionAmount.add(subsidyAmount);
|
||||||
|
if (total.compareTo(reductionAmount) < 0) {
|
||||||
|
total = BigDecimal.ZERO;
|
||||||
|
} else {
|
||||||
|
total = total.subtract(reductionAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
dishOrderDO.setTotalMoney(total);
|
||||||
|
|
||||||
|
//微信
|
||||||
|
BigDecimal wxAmount = user.getWxAmount();
|
||||||
|
//现金
|
||||||
|
BigDecimal cashAmount = user.getCashAmount();
|
||||||
|
//当前金额
|
||||||
|
BigDecimal money = user.getMoney();
|
||||||
|
|
||||||
|
//待支付金额 最大退款金额
|
||||||
|
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));
|
||||||
|
dishOrderDO.setRefundAmount(money);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//扣除金额
|
||||||
|
user.setMoney(money.subtract(total));
|
||||||
|
if (total.compareTo(money) > 0) {
|
||||||
|
dishOrderDO.setOrderStatus(DishOrderDO.TOCOMPLETE);
|
||||||
|
dishOrderDO.setWxAmount(wxAmount);
|
||||||
|
dishOrderDO.setCashAmount(cashAmount);
|
||||||
|
|
||||||
|
user.setWxAmount(BigDecimal.ZERO);
|
||||||
|
user.setCashAmount(BigDecimal.ZERO);
|
||||||
|
} else {
|
||||||
|
dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE);
|
||||||
|
//扣除具体金额
|
||||||
|
if (judge(userId, MemberTimeUtils.Time2StringDate(dishOrderDO.getCreateTime()))) { //微信->现金
|
||||||
|
if (total.compareTo(wxAmount) <= 0) {
|
||||||
|
user.setWxAmount(wxAmount.subtract(total));
|
||||||
|
dishOrderDO.setWxAmount(total);
|
||||||
|
} else {
|
||||||
|
user.setWxAmount(BigDecimal.ZERO);
|
||||||
|
dishOrderDO.setWxAmount(wxAmount);
|
||||||
|
BigDecimal total1 = total.subtract(wxAmount);
|
||||||
|
user.setCashAmount(cashAmount.subtract(total1));
|
||||||
|
dishOrderDO.setCashAmount(total1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else { //现金->微信
|
||||||
|
if (total.compareTo(cashAmount) <= 0) {
|
||||||
|
user.setCashAmount(cashAmount.subtract(total));
|
||||||
|
dishOrderDO.setCashAmount(total);
|
||||||
|
} else {
|
||||||
|
user.setCashAmount(BigDecimal.ZERO);
|
||||||
|
dishOrderDO.setCashAmount(cashAmount);
|
||||||
|
BigDecimal total1 = total.subtract(cashAmount);
|
||||||
|
user.setWxAmount(wxAmount.subtract(total1));
|
||||||
|
dishOrderDO.setWxAmount(total1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//修改
|
||||||
|
userService.updateById(user);
|
||||||
|
|
||||||
|
wxNewMoney = user.getWxAmount();
|
||||||
|
cashNewMoney = user.getCashAmount();
|
||||||
|
newMoney = user.getMoney();
|
||||||
|
name = user.getNickname();
|
||||||
|
}
|
||||||
|
|
||||||
|
//记录消费记录
|
||||||
|
CardDO cardDO = new CardDO();
|
||||||
|
cardDO.setType(TimePeriodEnum.getTimePeriod(dishOrderDO.getCreateTime()));
|
||||||
|
cardDO.setUserId(userId);
|
||||||
|
cardDO.setChangeMoney(dishOrderDO.getTotalMoney());
|
||||||
|
cardDO.setFlag(CardDO.MINUS);
|
||||||
|
cardDO.setCashAmount(cashNewMoney);
|
||||||
|
cardDO.setWxAmount(wxNewMoney);
|
||||||
|
cardDO.setCarteenId(dishOrderDO.getStoreId());
|
||||||
|
cardDO.setMoney(newMoney);
|
||||||
|
cardService.insertOne(cardDO);
|
||||||
|
|
||||||
|
//更新营业数据
|
||||||
|
if (dishOrderDO.getOrderStatus().equals(DishOrderDO.COMPLETE)) {
|
||||||
|
StatisticsVo statisticsVo = new StatisticsVo();
|
||||||
|
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
|
||||||
|
statisticsVo.setTotalMoney(dishOrderDO.getTotalMoney());
|
||||||
|
statisticsVo.setOrderSum(1);
|
||||||
|
statisticsVo.setReduceMoney(dishOrderDO.getReductionAmount());
|
||||||
|
statisticsVo.setTime(dishOrderDO.getCreateTime());
|
||||||
|
statisticsVo.setOrderId(dishOrderDO.getId());
|
||||||
|
statisticsVo.setSubsidyPurse(dishOrderDO.getSubsidyAmount());
|
||||||
|
businessService.updateStatistics(statisticsVo);
|
||||||
|
}
|
||||||
|
//更新redis
|
||||||
|
updateRedis(userId, name, newMoney);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cashDraw(Long userId, BigDecimal money, String type, Long storeId) {
|
public void cashDraw(Long userId, BigDecimal money, String type, Long storeId) {
|
||||||
|
|
||||||
@ -356,7 +542,7 @@ public class DeductionServiceImpl implements DeductionService {
|
|||||||
BigDecimal newMoney;
|
BigDecimal newMoney;
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
if(judgeDraw(userId)){
|
if (judgeDraw(userId)) {
|
||||||
throw exception(CASH_AMOUNT_NOT_ALLOW);
|
throw exception(CASH_AMOUNT_NOT_ALLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,5 +130,5 @@ public interface OrderService {
|
|||||||
|
|
||||||
void abnormalHandle(Long orderId,String mobile);
|
void abnormalHandle(Long orderId,String mobile);
|
||||||
|
|
||||||
|
void orderTransfer(Long orderId,String mobile);
|
||||||
}
|
}
|
@ -573,14 +573,34 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
dishOrderDO.setUserId(memberUserDOS.get(0).getId());
|
dishOrderDO.setUserId(memberUserDOS.get(0).getId());
|
||||||
DiningPlatesDO diningPlatesDO = diningPlatesService.getDiningPlatesByNum(dishOrderDO.getDiningPlatesNum(), dishOrderDO.getStoreId());
|
DiningPlatesDO diningPlatesDO = diningPlatesService.getDiningPlatesByNum(dishOrderDO.getDiningPlatesNum(), dishOrderDO.getStoreId());
|
||||||
|
|
||||||
if(dishOrderDO.getOrderStatus().equals("3")){
|
if(dishOrderDO.getTotalMoney().compareTo(BigDecimal.ZERO)>0){
|
||||||
//扣费处理
|
//扣费处理
|
||||||
deductionService.abnormalOrderDeduct(dishOrderDO);
|
deductionService.abnormalOrderDeduct(dishOrderDO);
|
||||||
diningPlatesService.updateBind(Collections.singletonList(diningPlatesDO.getId()));
|
diningPlatesService.updateBind(Collections.singletonList(diningPlatesDO.getId()));
|
||||||
}else {
|
}else {
|
||||||
diningPlatesDO.setUserId(dishOrderDO.getUserId());
|
diningPlatesDO.setUserId(dishOrderDO.getUserId());
|
||||||
diningPlatesService.updateById(diningPlatesDO);
|
diningPlatesService.updateById(diningPlatesDO);
|
||||||
|
dishOrderDO.setOrderStatus(DishOrderDO.INCOMPLETE);
|
||||||
}
|
}
|
||||||
dishOrderMapper.updateById(dishOrderDO);
|
dishOrderMapper.updateById(dishOrderDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void orderTransfer(Long orderId, String mobile) {
|
||||||
|
List<MemberUserDO> memberUserDOS = memberUserMapper.selectList(new LambdaQueryWrapperX<MemberUserDO>()
|
||||||
|
.eq(MemberUserDO::getMobile, mobile));
|
||||||
|
if(CollectionUtil.isEmpty(memberUserDOS)){
|
||||||
|
throw exception(USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
DishOrderDO dishOrderDO = dishOrderMapper.selectById(orderId);
|
||||||
|
if(dishOrderDO == null){
|
||||||
|
throw exception(ORDER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
MemberUserDO memberUserDO = memberUserDOS.get(0);
|
||||||
|
//扣费处理
|
||||||
|
deductionService.orderTransferHandle(dishOrderDO,memberUserDO.getId());
|
||||||
|
dishOrderDO.setTransferState("1");
|
||||||
|
dishOrderDO.setTransferTime(LocalDateTime.now());
|
||||||
|
dishOrderMapper.updateById(dishOrderDO);
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.util;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import org.aspectj.apache.bcel.generic.RET;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -115,4 +114,12 @@ public class MemberTimeUtils {
|
|||||||
return time.format(formatter);
|
return time.format(formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String Time2StringDate(LocalDateTime time) {
|
||||||
|
// 定义日期字符串格式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
|
// 将字符串解析为LocalDate对象
|
||||||
|
return time.format(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user