Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
94e875008b
|
|
@ -12,4 +12,18 @@ public interface RedisConstant {
|
||||||
public static final String ORDER_MESSAGE="ORDER:MESSAGE:";
|
public static final String ORDER_MESSAGE="ORDER:MESSAGE:";
|
||||||
public static final String ORDER_PRODUCT_NUM = "ORDER_NUM:";
|
public static final String ORDER_PRODUCT_NUM = "ORDER_NUM:";
|
||||||
public static final String ORDER_CART_EXISTS = "ORDER_CART_EXISTS:";
|
public static final String ORDER_CART_EXISTS = "ORDER_CART_EXISTS:";
|
||||||
|
String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";
|
||||||
|
|
||||||
|
public static String TABLE_CART = "TABLE:CART:";
|
||||||
|
String ADD_TABLE_CART_LOCK = "ADD_TABLE_CART";
|
||||||
|
String PC_OUT_NUMBER = "PC_OUT_NUMBER:";
|
||||||
|
|
||||||
|
|
||||||
|
static String getCurrentOrderKey(String tableId, String shopId) {
|
||||||
|
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getTableCartKey(String tableId, String shopId) {
|
||||||
|
return TABLE_CART + tableId + "-" + shopId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ public class TbPlaceController {
|
||||||
public ResponseEntity<Object> createOrder(
|
public ResponseEntity<Object> createOrder(
|
||||||
@RequestBody CreateOrderDTO createOrderDTO
|
@RequestBody CreateOrderDTO createOrderDTO
|
||||||
) {
|
) {
|
||||||
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO, true));
|
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO, !createOrderDTO.isPostPay(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AnonymousAccess
|
@AnonymousAccess
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,5 @@ public class AddCartDTO {
|
||||||
private Integer num;
|
private Integer num;
|
||||||
private boolean isPack;
|
private boolean isPack;
|
||||||
private boolean isGift;
|
private boolean isGift;
|
||||||
|
private Integer cartId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,5 @@ public class CreateOrderDTO {
|
||||||
private String tableId;
|
private String tableId;
|
||||||
private String note;
|
private String note;
|
||||||
private boolean postPay;
|
private boolean postPay;
|
||||||
|
private Integer orderId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package cn.ysk.cashier.dto.shoptable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
@ -13,4 +15,8 @@ public class PayDTO {
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String payType;
|
private String payType;
|
||||||
|
@Min(0)
|
||||||
|
@Max(1)
|
||||||
|
private Double discount;
|
||||||
|
private Integer vipUserId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,18 +118,22 @@ public class TbShopExtend extends Model<TbShopExtend> {
|
||||||
case "index_bg":
|
case "index_bg":
|
||||||
this.name = "店铺首页背景图";
|
this.name = "店铺首页背景图";
|
||||||
this.detail="建议尺寸: 375*600 ";
|
this.detail="建议尺寸: 375*600 ";
|
||||||
|
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/shuangbackground.png";
|
||||||
break;
|
break;
|
||||||
case "my_bg":
|
case "my_bg":
|
||||||
this.name = "我的页面背景图";
|
this.name = "我的页面背景图";
|
||||||
this.detail="建议尺寸: 375*200";
|
this.detail="建议尺寸: 375*200";
|
||||||
|
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/my/myTopBack.png";
|
||||||
break;
|
break;
|
||||||
case "member_bg":
|
case "member_bg":
|
||||||
this.name = "会员卡页面背景图";
|
this.name = "会员卡页面背景图";
|
||||||
this.detail="建议尺寸: 315*152";
|
this.detail="建议尺寸: 315*152";
|
||||||
|
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_bg.png";
|
||||||
break;
|
break;
|
||||||
case "shopinfo_bg":
|
case "shopinfo_bg":
|
||||||
this.name = "商品列表顶部背景图";
|
this.name = "商品列表顶部背景图";
|
||||||
this.detail="建议尺寸: 375*120";
|
this.detail="建议尺寸: 375*120";
|
||||||
|
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/shopDetails/topBanner.png";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Select;
|
||||||
public interface ShopUserMapper extends BaseMapper<TbShopUser> {
|
public interface ShopUserMapper extends BaseMapper<TbShopUser> {
|
||||||
|
|
||||||
@Select("<script>" +
|
@Select("<script>" +
|
||||||
"SELECT su.id as id, su.head_img as headImg, su.name as nickName, su.sex as sex, " +
|
"SELECT su.id as id, su.user_id as user_id, su.head_img as headImg, su.name as nickName, su.sex as sex, " +
|
||||||
"su.amount as amount, 0 as totalScore, su.telephone as telephone, u.last_log_in_at as lastLoginAt, " +
|
"su.amount as amount, 0 as totalScore, su.telephone as telephone, u.last_log_in_at as lastLoginAt, " +
|
||||||
"su.birth_day as birthDay, su.is_vip as isVip, su.created_at as createAt " +
|
"su.birth_day as birthDay, su.is_vip as isVip, su.created_at as createAt " +
|
||||||
"FROM tb_shop_user su " +
|
"FROM tb_shop_user su " +
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public class TbShopExtendServiceImpl extends ServiceImpl<TbShopExtendMapper, TbS
|
||||||
}
|
}
|
||||||
wrapper.orderByDesc("create_time");
|
wrapper.orderByDesc("create_time");
|
||||||
Page<TbShopExtend> ipage = tbShopExtendmapper.selectPage(page, wrapper);
|
Page<TbShopExtend> ipage = tbShopExtendmapper.selectPage(page, wrapper);
|
||||||
checkAndInitialize(ipage,criteria.getShopId());
|
ipage = checkAndInitialize(ipage,criteria.getShopId());
|
||||||
return PageUtil.toPage(ipage.getRecords(), ipage.getTotal());
|
return PageUtil.toPage(ipage.getRecords(), ipage.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull;
|
||||||
public interface TbPayService {
|
public interface TbPayService {
|
||||||
void scanPay(ScanPayDTO scanPayDTO);
|
void scanPay(ScanPayDTO scanPayDTO);
|
||||||
|
|
||||||
TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId);
|
TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId);
|
||||||
|
|
||||||
TbOrderInfo cashPay(PayDTO payDTO);
|
TbOrderInfo cashPay(PayDTO payDTO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,14 @@ import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||||
import cn.ysk.cashier.service.TbPayService;
|
import cn.ysk.cashier.service.TbPayService;
|
||||||
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||||
import cn.ysk.cashier.utils.SnowFlakeUtil;
|
import cn.ysk.cashier.utils.SnowFlakeUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -297,7 +298,7 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
private final TbShopUserFlowMapper shopUserFlowMapper;
|
private final TbShopUserFlowMapper shopUserFlowMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId) {
|
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId) {
|
||||||
|
|
||||||
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
||||||
|
|
||||||
|
|
@ -309,6 +310,9 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
throw new BadRequestException("订单非未支付状态");
|
throw new BadRequestException("订单非未支付状态");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vipUserId != null) {
|
||||||
|
orderInfo.setUserId(String.valueOf(vipUserId));
|
||||||
|
}
|
||||||
|
|
||||||
// 扣减会员余额
|
// 扣减会员余额
|
||||||
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
|
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
|
||||||
|
|
@ -319,22 +323,29 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
throw new BadRequestException("用户不存在或已被禁用");
|
throw new BadRequestException("用户不存在或已被禁用");
|
||||||
}
|
}
|
||||||
|
|
||||||
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), orderInfo.getOrderAmount());
|
BigDecimal payMount = discount == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP);
|
||||||
|
|
||||||
|
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), payMount);
|
||||||
if (flag < 1) {
|
if (flag < 1) {
|
||||||
throw new BadRequestException("余额不足或扣除余额失败");
|
throw new BadRequestException("余额不足或扣除余额失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
TbShopUserFlow userFlow = new TbShopUserFlow();
|
TbShopUserFlow userFlow = new TbShopUserFlow();
|
||||||
userFlow.setAmount(orderInfo.getOrderAmount());
|
userFlow.setAmount(payMount);
|
||||||
userFlow.setBalance(shopUser.getAmount());
|
userFlow.setBalance(shopUser.getAmount());
|
||||||
userFlow.setShopUserId(shopUser.getId());
|
userFlow.setShopUserId(shopUser.getId());
|
||||||
userFlow.setBizCode("vipCardCash");
|
userFlow.setBizCode("vipCardCash");
|
||||||
userFlow.setBizName("代客下单会员余额支付");
|
userFlow.setBizName("余额支付");
|
||||||
userFlow.setCreateTime(DateUtil.date());
|
userFlow.setCreateTime(DateUtil.date());
|
||||||
userFlow.setType("-");
|
userFlow.setType("-");
|
||||||
shopUserFlowMapper.insert(userFlow);
|
shopUserFlowMapper.insert(userFlow);
|
||||||
|
|
||||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
orderInfo.setPayAmount(payMount);
|
||||||
|
if (discount != null && discount != 1) {
|
||||||
|
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
|
||||||
|
orderInfo.setDiscountRatio(BigDecimal.valueOf(discount));
|
||||||
|
}
|
||||||
|
|
||||||
orderInfo.setPayType("cash");
|
orderInfo.setPayType("cash");
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
|
@ -373,7 +384,12 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
orderInfo.setPayAmount(payDTO.getDiscount() == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount()
|
||||||
|
.multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.UP));
|
||||||
|
if (payDTO.getDiscount() != null && payDTO.getDiscount() != 1) {
|
||||||
|
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
|
||||||
|
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
||||||
|
}
|
||||||
orderInfo.setPayType("cash");
|
orderInfo.setPayType("cash");
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||||
import cn.ysk.cashier.service.impl.TbPayServiceImpl;
|
import cn.ysk.cashier.service.impl.TbPayServiceImpl;
|
||||||
import cn.ysk.cashier.utils.*;
|
import cn.ysk.cashier.utils.*;
|
||||||
import cn.ysk.cashier.vo.PendingCountVO;
|
import cn.ysk.cashier.vo.PendingCountVO;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
|
@ -70,6 +71,7 @@ import java.util.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,6 +112,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
private final String QRCODE = "https://kysh.sxczgkj.cn/codeplate?code=";
|
private final String QRCODE = "https://kysh.sxczgkj.cn/codeplate?code=";
|
||||||
private final RabbitMsgUtils rabbitMsgUtils;
|
private final RabbitMsgUtils rabbitMsgUtils;
|
||||||
private final TbPayServiceImpl tbPayServiceImpl;
|
private final TbPayServiceImpl tbPayServiceImpl;
|
||||||
|
private final TbCashierCartMapper tbCashierCartMapper;
|
||||||
|
private final TbOrderDetailMapper tbOrderDetailMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) {
|
public Map<String, Object> queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) {
|
||||||
|
|
@ -136,6 +140,23 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
List<TbShopTable> tbShopTableList = tbShopTableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
|
List<TbShopTable> tbShopTableList = tbShopTableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
|
||||||
ArrayList<Map<String, Object>> infoList = new ArrayList<>();
|
ArrayList<Map<String, Object>> infoList = new ArrayList<>();
|
||||||
for (TbShopTable date : tbShopTableList) {
|
for (TbShopTable date : tbShopTableList) {
|
||||||
|
String orderId = redisTemplate.opsForValue().get(RedisConstant.CURRENT_TABLE_ORDER + date.getShopId() + ":" + date.getQrcode());
|
||||||
|
if (StrUtil.isBlank(date.getQrcode())) {
|
||||||
|
date.setStatus("closed");
|
||||||
|
}else if (tbCashierCartMapper.selectCount(new LambdaQueryWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getShopId, date.getShopId())
|
||||||
|
.eq(TbCashierCart::getTableId, date.getQrcode())
|
||||||
|
.eq(TbCashierCart::getStatus, "create")) < 1 || (orderId != null &&
|
||||||
|
tbOrderDetailMapper.selectCount(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getShopId, date.getShopId())
|
||||||
|
.eq(TbOrderDetail::getStatus, "unpaid")
|
||||||
|
.eq(TbOrderDetail::getOrderId, orderId)) < 1)
|
||||||
|
) {
|
||||||
|
date.setStatus("idle");
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, date.getQrcode())
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||||
|
}
|
||||||
Map<String, Object> itemMap = BeanUtil.beanToMap(date, false, false);
|
Map<String, Object> itemMap = BeanUtil.beanToMap(date, false, false);
|
||||||
if (!"".equals(date.getQrcode())) {
|
if (!"".equals(date.getQrcode())) {
|
||||||
itemMap.put("qrcode", QRCODE + date.getQrcode().trim());
|
itemMap.put("qrcode", QRCODE + date.getQrcode().trim());
|
||||||
|
|
@ -320,6 +341,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
||||||
.eq(TbCashierCart::getProductId, addCartDTO.getProductId())
|
.eq(TbCashierCart::getProductId, addCartDTO.getProductId())
|
||||||
.eq(TbCashierCart::getTableId, addCartDTO.getTableId())
|
.eq(TbCashierCart::getTableId, addCartDTO.getTableId())
|
||||||
|
.in(TbCashierCart::getStatus, "create", "refund")
|
||||||
|
// .and(q -> {
|
||||||
|
// q.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||||
|
// .or()
|
||||||
|
// .isNull(TbCashierCart::getTradeDay);
|
||||||
|
//
|
||||||
|
// });
|
||||||
.and(query2 -> {
|
.and(query2 -> {
|
||||||
query2.and(query3 -> {
|
query2.and(query3 -> {
|
||||||
query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||||
|
|
@ -330,7 +358,19 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.eq(TbCashierCart::getMasterId, "");
|
.eq(TbCashierCart::getMasterId, "");
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (addCartDTO.getCartId() != null) {
|
||||||
|
query.eq(TbCashierCart::getId, addCartDTO.getCartId());
|
||||||
|
}
|
||||||
|
|
||||||
TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query);
|
TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query);
|
||||||
|
// 增加redis购物车数据
|
||||||
|
String tableCartKey = RedisConstant.getTableCartKey(addCartDTO.getTableId(), addCartDTO.getShopId().toString());
|
||||||
|
String tableCart = redisTemplate.opsForValue().get(tableCartKey);
|
||||||
|
List<TbCashierCart> cartArrayList = new ArrayList<>();
|
||||||
|
if (tableCart != null) {
|
||||||
|
cartArrayList = JSONObject.parseArray(tableCart, TbCashierCart.class);
|
||||||
|
}
|
||||||
// 首次加入
|
// 首次加入
|
||||||
if (tbCashierCart == null) {
|
if (tbCashierCart == null) {
|
||||||
tbCashierCart = new TbCashierCart();
|
tbCashierCart = new TbCashierCart();
|
||||||
|
|
@ -366,6 +406,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
tbCashierCart.setNumber(addCartDTO.getNum());
|
tbCashierCart.setNumber(addCartDTO.getNum());
|
||||||
tbCashierCart.setCategoryId(product.getCategoryId());
|
tbCashierCart.setCategoryId(product.getCategoryId());
|
||||||
cashierCartRepository.save(tbCashierCart);
|
cashierCartRepository.save(tbCashierCart);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
|
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
|
||||||
|
|
||||||
|
|
@ -394,9 +435,36 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
cashierCartRepository.save(tbCashierCart);
|
cashierCartRepository.save(tbCashierCart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRedisTableCartInfo(addCartDTO.getTableId(), addCartDTO.getShopId().toString(), Collections.singletonList(tbCashierCart), true);
|
||||||
|
|
||||||
return tbCashierCart;
|
return tbCashierCart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRedisTableCartInfo(String tableId, String shopId, List<TbCashierCart> tbCashierCartList, boolean isAdd) {
|
||||||
|
String tableCartKey = RedisConstant.getTableCartKey(tableId, shopId);
|
||||||
|
String tableCart = redisTemplate.opsForValue().get(tableCartKey);
|
||||||
|
|
||||||
|
List<TbCashierCart> cartArrayList = new ArrayList<>();
|
||||||
|
if (tableCart != null) {
|
||||||
|
cartArrayList = JSONObject.parseArray(tableCart, TbCashierCart.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TbCashierCart cashierCart : tbCashierCartList) {
|
||||||
|
cartArrayList = cartArrayList.stream().filter(d -> !d.getId().equals(cashierCart.getId())).collect(Collectors.toList());
|
||||||
|
if (isAdd) {
|
||||||
|
cartArrayList.add(cashierCart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TbCashierCart> finalCartArrayList = cartArrayList;
|
||||||
|
Utils.runFunAndCheckKey(() -> {
|
||||||
|
redisTemplate.opsForValue().set(tableCartKey,
|
||||||
|
JSONObject.toJSONString(finalCartArrayList));
|
||||||
|
return null;
|
||||||
|
}, redisTemplate, RedisConstant.ADD_TABLE_CART_LOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCart(RemoveCartDTO removeCartDTO) {
|
public void removeCart(RemoveCartDTO removeCartDTO) {
|
||||||
// 会员点单
|
// 会员点单
|
||||||
|
|
@ -409,10 +477,23 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
|
|
||||||
if (cashierCart.getOrderId() != null) {
|
if (cashierCart.getOrderId() != null) {
|
||||||
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>()
|
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getShopId, cashierCart.getShopId())
|
||||||
|
.eq(TbOrderDetail::getProductId, cashierCart.getProductId())
|
||||||
|
.eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId())
|
||||||
.eq(TbOrderDetail::getOrderId, cashierCart.getOrderId()));
|
.eq(TbOrderDetail::getOrderId, cashierCart.getOrderId()));
|
||||||
}
|
}
|
||||||
cashierCartMapper.delete(new LambdaQueryWrapper<TbCashierCart>().eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
|
cashierCartMapper.delete(new LambdaQueryWrapper<TbCashierCart>().eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
|
||||||
.eq(TbCashierCart::getId, removeCartDTO.getCartId()));
|
.eq(TbCashierCart::getId, removeCartDTO.getCartId()));
|
||||||
|
|
||||||
|
|
||||||
|
// 清空购物车 出票
|
||||||
|
long carCount = countCar(cashierCart.getTableId(), cashierCart.getShopId(), cashierCart.getMasterId());
|
||||||
|
if (cashierCart.getOrderId() != null && carCount < 1) {
|
||||||
|
rabbitMsgUtils.printTicket(String.valueOf(cashierCart.getOrderId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
setRedisTableCartInfo(removeCartDTO.getTableId().toString(), removeCartDTO.getShopId().toString(), Collections.singletonList(cashierCart), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -428,6 +509,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.isNull(TbCashierCart::getUserId));
|
.isNull(TbCashierCart::getUserId));
|
||||||
}
|
}
|
||||||
tbShopTableRepository.deleteByTableIdAndShopId(clearCartDTO.getTableId(), clearCartDTO.getShopId());
|
tbShopTableRepository.deleteByTableIdAndShopId(clearCartDTO.getTableId(), clearCartDTO.getShopId());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private long countCar(Long tableId, String shopId, String masterId) {
|
||||||
|
String orderId = redisTemplate.opsForValue().get(RedisConstant.getCurrentOrderKey(tableId.toString(), shopId));
|
||||||
|
return tbOrderDetailMapper.selectCount(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getShopId, shopId)
|
||||||
|
.eq(TbOrderDetail::getStatus, "unpaid")
|
||||||
|
.eq(TbOrderDetail::getOrderId, orderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -751,9 +841,27 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getOutNumber(String shopId, String tableId) {
|
||||||
|
String shopKey = RedisConstant.PC_OUT_NUMBER + ":" + shopId;
|
||||||
|
String outNumber = redisTemplate.opsForValue().get(shopKey);
|
||||||
|
if (outNumber == null) {
|
||||||
|
Boolean flag = redisTemplate.opsForValue().setIfAbsent(shopKey, "1");
|
||||||
|
if (flag != null && flag.equals(Boolean.FALSE)) {
|
||||||
|
outNumber = redisTemplate.opsForValue().get(shopKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String shopTableKey = RedisConstant.PC_OUT_NUMBER + ":" + shopId;
|
||||||
|
redisTemplate.opsForValue().get(shopTableKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO, boolean addMaterId) {
|
public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO, boolean addMaterId, boolean isPrint) {
|
||||||
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString());
|
||||||
|
String orderIdValue = redisTemplate.opsForValue().get(currentOrderKey);
|
||||||
|
Integer orderId = orderIdValue == null ? null : Integer.parseInt(orderIdValue);
|
||||||
|
orderId = createOrderDTO.getOrderId() != null ? createOrderDTO.getOrderId() : orderId;
|
||||||
|
|
||||||
String day = DateUtils.getDay();
|
String day = DateUtils.getDay();
|
||||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||||
|
|
@ -782,12 +890,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
throw new BadRequestException("购物车为空,请先添加商品");
|
throw new BadRequestException("购物车为空,请先添加商品");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||||
|
.in(TbShopTable::getStatus, "idle", "using"));
|
||||||
|
|
||||||
|
if (tbShopTable == null) {
|
||||||
|
throw new BadRequestException("台桌未开台或不存在");
|
||||||
|
}
|
||||||
|
|
||||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||||
BigDecimal packAMount = BigDecimal.ZERO;
|
BigDecimal packAMount = BigDecimal.ZERO;
|
||||||
BigDecimal feeAmount = BigDecimal.ZERO;
|
BigDecimal feeAmount = BigDecimal.ZERO;
|
||||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||||
Integer orderId = null;
|
|
||||||
for (TbCashierCart cashierCart : cashierCarts) {
|
for (TbCashierCart cashierCart : cashierCarts) {
|
||||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||||
|
|
@ -815,11 +931,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
if (cashierCart.getOrderId() != null) {
|
if (cashierCart.getOrderId() != null) {
|
||||||
orderId = cashierCart.getOrderId();
|
orderId = cashierCart.getOrderId();
|
||||||
}
|
}
|
||||||
|
orderDetail.setOrderId(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
TbOrderInfo orderInfo = null;
|
TbOrderInfo orderInfo = null;
|
||||||
if (orderId != null) {
|
if (orderId != null) {
|
||||||
orderInfo = orderInfoMapper.selectById(orderId);
|
orderInfo = orderInfoMapper.selectById(orderId);
|
||||||
|
|
||||||
|
if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
redisTemplate.delete(currentOrderKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改订单信息
|
// 修改订单信息
|
||||||
|
|
@ -847,6 +968,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
orderInfo.setOrderNo(orderNo);
|
orderInfo.setOrderNo(orderNo);
|
||||||
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
||||||
orderInfo.setAmount(totalAmount);
|
orderInfo.setAmount(totalAmount);
|
||||||
|
orderInfo.setPayAmount(BigDecimal.ZERO);
|
||||||
orderInfo.setPackFee(packAMount);
|
orderInfo.setPackFee(packAMount);
|
||||||
orderInfo.setSettlementAmount(totalAmount);
|
orderInfo.setSettlementAmount(totalAmount);
|
||||||
orderInfo.setOriginAmount(totalAmount);
|
orderInfo.setOriginAmount(totalAmount);
|
||||||
|
|
@ -860,9 +982,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
orderInfo.setRefundAble(1);
|
orderInfo.setRefundAble(1);
|
||||||
orderInfo.setTradeDay(day);
|
orderInfo.setTradeDay(day);
|
||||||
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
||||||
|
orderInfo.setOutNumber(createOrderDTO.getMasterId());
|
||||||
orderInfo.setRemark(createOrderDTO.getNote());
|
orderInfo.setRemark(createOrderDTO.getNote());
|
||||||
orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId()));
|
orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId()));
|
||||||
orderInfo.setCreatedAt(DateUtil.current());
|
orderInfo.setCreatedAt(DateUtil.current());
|
||||||
|
orderInfo.setTableName(tbShopTable.getName());
|
||||||
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>()
|
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>()
|
||||||
.eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId())
|
.eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId())
|
||||||
.eq(TbMerchantAccount::getStatus, 1));
|
.eq(TbMerchantAccount::getStatus, 1));
|
||||||
|
|
@ -871,6 +995,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
}
|
}
|
||||||
orderInfo.setMerchantId(merchantAccount.getId().toString());
|
orderInfo.setMerchantId(merchantAccount.getId().toString());
|
||||||
orderInfoMapper.insert(orderInfo);
|
orderInfoMapper.insert(orderInfo);
|
||||||
|
|
||||||
|
redisTemplate.opsForValue().set(currentOrderKey, orderInfo.getId().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -901,13 +1027,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
// 后付费,不增加当前台桌取餐号
|
// 后付费,不增加当前台桌取餐号
|
||||||
if (createOrderDTO.isPostPay()) {
|
if (createOrderDTO.isPostPay()) {
|
||||||
// addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId()));
|
addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId()));
|
||||||
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
// String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||||
redisTemplate.delete(key);
|
// redisTemplate.delete(key);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!createOrderDTO.isPostPay() || addMaterId){
|
||||||
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 推送耗材信息
|
// 推送耗材信息
|
||||||
|
|
@ -918,7 +1047,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||||
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
|
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
|
||||||
|
|
||||||
if (createOrderDTO.isPostPay()) {
|
if (createOrderDTO.isPostPay() && isPrint) {
|
||||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -990,7 +1119,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
createOrderDTO.setMasterId(pendingDTO.getMasterId());
|
createOrderDTO.setMasterId(pendingDTO.getMasterId());
|
||||||
createOrderDTO.setVipUserId(pendingDTO.getVipUserId());
|
createOrderDTO.setVipUserId(pendingDTO.getVipUserId());
|
||||||
createOrderDTO.setNote(pendingDTO.getNote());
|
createOrderDTO.setNote(pendingDTO.getNote());
|
||||||
orderId = createOrder(createOrderDTO, true).getId();
|
orderId = createOrder(createOrderDTO, true, false).getId();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1018,9 +1147,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
.eq(TbShopTable::getQrcode, cashierCart.getTableId())
|
.eq(TbShopTable::getQrcode, cashierCart.getTableId())
|
||||||
.set(TbShopTable::getStatus, TableStateEnum.PENDING.getState()));
|
.set(TbShopTable::getStatus, TableStateEnum.PENDING.getState()));
|
||||||
|
|
||||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redisTemplate.delete(RedisConstant.getCurrentOrderKey(pendingDTO.getTableId(), pendingDTO.getShopId().toString()));
|
||||||
|
|
||||||
return orderInfoMapper.selectById(orderId);
|
return orderInfoMapper.selectById(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1079,7 +1209,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
TbOrderInfo orderInfo = null;
|
TbOrderInfo orderInfo = null;
|
||||||
switch (payDTO.getPayType()) {
|
switch (payDTO.getPayType()) {
|
||||||
case "vipPay":
|
case "vipPay":
|
||||||
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId());
|
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId(), payDTO.getDiscount(), payDTO.getVipUserId());
|
||||||
break;
|
break;
|
||||||
case "cash":
|
case "cash":
|
||||||
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
||||||
|
|
@ -1097,9 +1227,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
|
|
||||||
// 打印消息
|
// 打印消息
|
||||||
rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
|
rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
|
||||||
if (StrUtil.isBlank(orderInfo.getUseType()) || orderInfo.getUseType().equals("afterPay")) {
|
rabbitMsgUtils.printTicket(String.valueOf(orderInfo.getId()));
|
||||||
rabbitMsgUtils.printTicket(String.valueOf(orderInfo.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送库存记录mq消息
|
// 发送库存记录mq消息
|
||||||
JSONObject mqData = new JSONObject();
|
JSONObject mqData = new JSONObject();
|
||||||
|
|
@ -1117,6 +1245,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String currentOrderKey = RedisConstant.CURRENT_TABLE_ORDER + payDTO.getShopId() + ":" + orderInfo.getTableId();
|
||||||
|
redisTemplate.delete(currentOrderKey);
|
||||||
|
|
||||||
|
// 小程序购物车缓存
|
||||||
|
String tableCartKey = RedisConstant.getTableCartKey(orderInfo.getTableId(), orderInfo.getShopId());
|
||||||
|
redisTemplate.delete(tableCartKey);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,15 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
||||||
shopUserInfoVo.setTotalScore(0);
|
shopUserInfoVo.setTotalScore(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Integer orderNumber=tbOrderInfoRepository.countByUserIdAndStatusAndShopId(shopUserInfoVo.getId().toString(),criteria.getShopId());
|
|
||||||
shopUserInfoVo.setOrderNumber(Objects.isNull(orderNumber)?0:orderNumber);
|
|
||||||
shopUserInfoVo.setInMoney(tbShopUserRepository.sumAmount(shopUserInfoVo.getId()));
|
|
||||||
|
|
||||||
|
if (shopUserInfoVo.getUserId() == null) {
|
||||||
|
shopUserInfoVo.setUserId(0);
|
||||||
|
shopUserInfoVo.setOrderNumber(0);
|
||||||
|
} else {
|
||||||
|
Integer orderNumber = tbOrderInfoRepository.countByUserIdAndStatusAndShopId(shopUserInfoVo.getUserId().toString(), criteria.getShopId());
|
||||||
|
shopUserInfoVo.setOrderNumber(Objects.isNull(orderNumber) ? 0 : orderNumber);
|
||||||
|
}
|
||||||
|
shopUserInfoVo.setInMoney(tbShopUserRepository.sumAmount(shopUserInfoVo.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return PageUtil.toPlusPage(iPage.getRecords(), Integer.valueOf(iPage.getTotal() + ""));
|
return PageUtil.toPlusPage(iPage.getRecords(), Integer.valueOf(iPage.getTotal() + ""));
|
||||||
|
|
@ -194,51 +199,49 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modfiyAccount(Map<String, Object> map) {
|
public void modfiyAccount(Map<String, Object> map) {
|
||||||
if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("id")||!map.containsKey("type")||!map.containsKey("amount")
|
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("id") || !map.containsKey("type") || !map.containsKey("amount")
|
||||||
||ObjectUtil.isEmpty(map.get("id"))||ObjectUtil.isNull(map.get("id"))||ObjectUtil.isNull(map.get("type"))||ObjectUtil.isEmpty(map.get("type"))
|
|| ObjectUtil.isEmpty(map.get("id")) || ObjectUtil.isNull(map.get("id")) || ObjectUtil.isNull(map.get("type")) || ObjectUtil.isEmpty(map.get("type"))
|
||||||
||ObjectUtil.isEmpty(map.get("amount"))||ObjectUtil.isNull(map.get("amount"))||!map.containsKey("operationType")||ObjectUtil.isEmpty(map.get("operationType"))||ObjectUtil.isNull(map.get("operationType"))
|
|| ObjectUtil.isEmpty(map.get("amount")) || ObjectUtil.isNull(map.get("amount")) || !map.containsKey("operationType") || ObjectUtil.isEmpty(map.get("operationType")) || ObjectUtil.isNull(map.get("operationType"))
|
||||||
|
|
||||||
){
|
) {
|
||||||
throw new BadRequestException("参数错误");
|
throw new BadRequestException("参数错误");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String regex = "^(([1-9][0-9]*)|(([0]\\.\\d{1,2}|[1-9][0-9]*\\.\\d{1,2})))$";
|
String regex = "^(([1-9][0-9]*)|(([0]\\.\\d{1,2}|[1-9][0-9]*\\.\\d{1,2})))$";
|
||||||
if(!map.get("amount").toString().matches(regex)){
|
if (!map.get("amount").toString().matches(regex)) {
|
||||||
throw new BadRequestException("请输入正确的数字");
|
throw new BadRequestException("请输入正确的数字");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TbShopUser tbShopUser = tbShopUserRepository.getById(Integer.valueOf(map.get("id") + ""));
|
||||||
TbShopUser tbShopUser= tbShopUserRepository.getById(Integer.valueOf(map.get("id")+""));
|
if (ObjectUtil.isNull(tbShopUser)) {
|
||||||
if(ObjectUtil.isNull(tbShopUser)){
|
throw new BadRequestException("不存在的会员信息");
|
||||||
throw new BadRequestException("不存在的会员信息");
|
|
||||||
}
|
}
|
||||||
String operationType=map.get("operationType").toString();
|
String operationType = map.get("operationType").toString();
|
||||||
|
|
||||||
BigDecimal amount=new BigDecimal(map.get("amount").toString());
|
BigDecimal amount = new BigDecimal(map.get("amount").toString());
|
||||||
if("out".equals(operationType)){
|
if ("out".equals(operationType)) {
|
||||||
if(amount.compareTo(tbShopUser.getAmount())>0){
|
if (amount.compareTo(tbShopUser.getAmount()) > 0) {
|
||||||
throw new BadRequestException("账户余额不足,请输入正确的金额");
|
throw new BadRequestException("账户余额不足,请输入正确的金额");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String type = map.get("type").toString();
|
||||||
|
TbShopUserFlow flow = new TbShopUserFlow();
|
||||||
|
|
||||||
String type=map.get("type").toString();
|
if ("in".equals(operationType)) {
|
||||||
TbShopUserFlow flow=new TbShopUserFlow();
|
|
||||||
|
|
||||||
if("in".equals(operationType)){
|
|
||||||
flow.setType("+");
|
flow.setType("+");
|
||||||
flow.setBizName("inMoney".equals(type)?"充值":"消费退款");
|
flow.setBizName("inMoney".equals(type) ? "充值" : "消费退款");
|
||||||
flow.setBizCode("inMoney".equals(type)?"inMoneyIn":"consumeIn");
|
flow.setBizCode("inMoney".equals(type) ? "inMoneyIn" : "consumeIn");
|
||||||
tbShopUser.setAmount(tbShopUser.getAmount().add(amount));
|
tbShopUser.setAmount(tbShopUser.getAmount().add(amount));
|
||||||
}else if("out".equals(operationType)){
|
} else if ("out".equals(operationType)) {
|
||||||
flow.setBizName("inMoneyOut".equals(type)?"充值退款":"消费");
|
flow.setBizName("inMoneyOut".equals(type) ? "充值退款" : "消费");
|
||||||
flow.setBizCode("inMoneyOut".equals(type)?"inMoneyOut":"consumeOut");
|
flow.setBizCode("inMoneyOut".equals(type) ? "inMoneyOut" : "consumeOut");
|
||||||
flow.setType("-");
|
flow.setType("-");
|
||||||
tbShopUser.setAmount(tbShopUser.getAmount().subtract(amount));
|
tbShopUser.setAmount(tbShopUser.getAmount().subtract(amount));
|
||||||
}else {
|
} else {
|
||||||
throw new BadRequestException("错误的请求类型");
|
throw new BadRequestException("错误的请求类型");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,8 +257,6 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
||||||
tbShopUserFlowMapper.insert(flow);
|
tbShopUserFlowMapper.insert(flow);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public interface TbShopTableService {
|
||||||
|
|
||||||
void pack(PackCartDTO packCartDTO);
|
void pack(PackCartDTO packCartDTO);
|
||||||
|
|
||||||
Object createOrder(CreateOrderDTO createOrderDTO, boolean addMasterId);
|
Object createOrder(CreateOrderDTO createOrderDTO, boolean addMasterId, boolean isPrint);
|
||||||
|
|
||||||
Object getMasterId(Integer shopId, Long tableId, Integer vipUserId);
|
Object getMasterId(Integer shopId, Long tableId, Integer vipUserId);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
package cn.ysk.cashier.utils;
|
package cn.ysk.cashier.utils;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
public static int retryCount = 5;
|
||||||
private static final Logger log = LoggerFactory.getLogger(Utils.class);
|
private static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||||
|
|
||||||
public static <T> void catchErrNoReturn(Supplier<T> supplier) {
|
public static <T> void catchErrNoReturn(Supplier<T> supplier) {
|
||||||
|
|
@ -15,4 +23,70 @@ public class Utils {
|
||||||
log.error("执行方法出现异常", e);
|
log.error("执行方法出现异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T, R> void runFunAndRetryNoReturn(
|
||||||
|
Supplier<R> function,
|
||||||
|
Function<R, Boolean> check, Consumer<R> errFun) {
|
||||||
|
log.info("工具类开始执行函数");
|
||||||
|
R result = function.get();
|
||||||
|
boolean flag = check.apply(result);
|
||||||
|
|
||||||
|
log.info("执行结果: {}", result);
|
||||||
|
|
||||||
|
while (flag && retryCount-- > 0) {
|
||||||
|
log.info("执行函数失败, 剩余尝试次数{}", retryCount);
|
||||||
|
result = function.get();
|
||||||
|
log.info("执行结果: {}", result);
|
||||||
|
flag = check.apply(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
errFun.accept(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static<T> T runFunAndCheckKey(Supplier<T> supplier, StringRedisTemplate redisTemplate, String lockKey) {
|
||||||
|
try{
|
||||||
|
// 创建线程id, 用作判断
|
||||||
|
String clientId = UUID.randomUUID().toString();
|
||||||
|
// 设置分布式锁
|
||||||
|
boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
|
||||||
|
int count = 0;
|
||||||
|
while (!lock) {
|
||||||
|
if (count++ > 100) {
|
||||||
|
throw new BadRequestException("系统繁忙, 稍后再试");
|
||||||
|
}
|
||||||
|
Thread.sleep(20);
|
||||||
|
lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
|
||||||
|
}
|
||||||
|
return supplier.get();
|
||||||
|
} catch (Exception e){
|
||||||
|
log.info("执行出错:{}", e.getMessage());
|
||||||
|
throw new BadRequestException(e.getMessage());
|
||||||
|
}finally{
|
||||||
|
redisTemplate.delete(lockKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, R> R runFunAndRetry(
|
||||||
|
Supplier<R> function,
|
||||||
|
Function<R, Boolean> check, Consumer<R> errFun) {
|
||||||
|
log.info("工具类开始执行函数");
|
||||||
|
R result = function.get();
|
||||||
|
boolean flag = check.apply(result);
|
||||||
|
|
||||||
|
log.info("执行结果: {}", result);
|
||||||
|
|
||||||
|
while (flag && retryCount-- > 0) {
|
||||||
|
log.info("执行函数失败, 剩余尝试次数{}", retryCount);
|
||||||
|
result = function.get();
|
||||||
|
log.info("执行结果: {}", result);
|
||||||
|
flag = check.apply(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
errFun.accept(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import java.math.BigDecimal;
|
||||||
@Data
|
@Data
|
||||||
public class ShopUserInfoVo implements Serializable {
|
public class ShopUserInfoVo implements Serializable {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
private Integer userId;
|
||||||
private String headImg;
|
private String headImg;
|
||||||
private String nickName;
|
private String nickName;
|
||||||
private Object sex;
|
private Object sex;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue