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_PRODUCT_NUM = "ORDER_NUM:";
|
||||
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(
|
||||
@RequestBody CreateOrderDTO createOrderDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO, true));
|
||||
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO, !createOrderDTO.isPostPay(), true));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
|
|
|
|||
|
|
@ -24,4 +24,5 @@ public class AddCartDTO {
|
|||
private Integer num;
|
||||
private boolean isPack;
|
||||
private boolean isGift;
|
||||
private Integer cartId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,5 @@ public class CreateOrderDTO {
|
|||
private String tableId;
|
||||
private String note;
|
||||
private boolean postPay;
|
||||
private Integer orderId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package cn.ysk.cashier.dto.shoptable;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
|
@ -13,4 +15,8 @@ public class PayDTO {
|
|||
private Integer orderId;
|
||||
@NotEmpty
|
||||
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":
|
||||
this.name = "店铺首页背景图";
|
||||
this.detail="建议尺寸: 375*600 ";
|
||||
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/shuangbackground.png";
|
||||
break;
|
||||
case "my_bg":
|
||||
this.name = "我的页面背景图";
|
||||
this.detail="建议尺寸: 375*200";
|
||||
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/my/myTopBack.png";
|
||||
break;
|
||||
case "member_bg":
|
||||
this.name = "会员卡页面背景图";
|
||||
this.detail="建议尺寸: 315*152";
|
||||
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_bg.png";
|
||||
break;
|
||||
case "shopinfo_bg":
|
||||
this.name = "商品列表顶部背景图";
|
||||
this.detail="建议尺寸: 375*120";
|
||||
this.value = "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/shopDetails/topBanner.png";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Select;
|
|||
public interface ShopUserMapper extends BaseMapper<TbShopUser> {
|
||||
|
||||
@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.birth_day as birthDay, su.is_vip as isVip, su.created_at as createAt " +
|
||||
"FROM tb_shop_user su " +
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class TbShopExtendServiceImpl extends ServiceImpl<TbShopExtendMapper, TbS
|
|||
}
|
||||
wrapper.orderByDesc("create_time");
|
||||
Page<TbShopExtend> ipage = tbShopExtendmapper.selectPage(page, wrapper);
|
||||
checkAndInitialize(ipage,criteria.getShopId());
|
||||
ipage = checkAndInitialize(ipage,criteria.getShopId());
|
||||
return PageUtil.toPage(ipage.getRecords(), ipage.getTotal());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull;
|
|||
public interface TbPayService {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,14 @@ import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
|||
import cn.ysk.cashier.service.TbPayService;
|
||||
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||
import cn.ysk.cashier.utils.SnowFlakeUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
|
@ -297,7 +298,7 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
private final TbShopUserFlowMapper shopUserFlowMapper;
|
||||
|
||||
@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);
|
||||
|
||||
|
|
@ -309,6 +310,9 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
throw new BadRequestException("订单非未支付状态");
|
||||
}
|
||||
|
||||
if (vipUserId != null) {
|
||||
orderInfo.setUserId(String.valueOf(vipUserId));
|
||||
}
|
||||
|
||||
// 扣减会员余额
|
||||
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
|
||||
|
|
@ -319,22 +323,29 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
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) {
|
||||
throw new BadRequestException("余额不足或扣除余额失败");
|
||||
}
|
||||
|
||||
TbShopUserFlow userFlow = new TbShopUserFlow();
|
||||
userFlow.setAmount(orderInfo.getOrderAmount());
|
||||
userFlow.setAmount(payMount);
|
||||
userFlow.setBalance(shopUser.getAmount());
|
||||
userFlow.setShopUserId(shopUser.getId());
|
||||
userFlow.setBizCode("vipCardCash");
|
||||
userFlow.setBizName("代客下单会员余额支付");
|
||||
userFlow.setBizName("余额支付");
|
||||
userFlow.setCreateTime(DateUtil.date());
|
||||
userFlow.setType("-");
|
||||
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.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
|
|
@ -373,7 +384,12 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
// 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.setStatus("closed");
|
||||
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.utils.*;
|
||||
import cn.ysk.cashier.vo.PendingCountVO;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
|
@ -70,6 +71,7 @@ import java.util.*;
|
|||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
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 RabbitMsgUtils rabbitMsgUtils;
|
||||
private final TbPayServiceImpl tbPayServiceImpl;
|
||||
private final TbCashierCartMapper tbCashierCartMapper;
|
||||
private final TbOrderDetailMapper tbOrderDetailMapper;
|
||||
|
||||
@Override
|
||||
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));
|
||||
ArrayList<Map<String, Object>> infoList = new ArrayList<>();
|
||||
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);
|
||||
if (!"".equals(date.getQrcode())) {
|
||||
itemMap.put("qrcode", QRCODE + date.getQrcode().trim());
|
||||
|
|
@ -320,6 +341,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
||||
.eq(TbCashierCart::getProductId, addCartDTO.getProductId())
|
||||
.eq(TbCashierCart::getTableId, addCartDTO.getTableId())
|
||||
.in(TbCashierCart::getStatus, "create", "refund")
|
||||
// .and(q -> {
|
||||
// q.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
// .or()
|
||||
// .isNull(TbCashierCart::getTradeDay);
|
||||
//
|
||||
// });
|
||||
.and(query2 -> {
|
||||
query2.and(query3 -> {
|
||||
query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
|
|
@ -330,7 +358,19 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.eq(TbCashierCart::getMasterId, "");
|
||||
}));
|
||||
});
|
||||
|
||||
if (addCartDTO.getCartId() != null) {
|
||||
query.eq(TbCashierCart::getId, addCartDTO.getCartId());
|
||||
}
|
||||
|
||||
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) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
|
|
@ -366,6 +406,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
tbCashierCart.setNumber(addCartDTO.getNum());
|
||||
tbCashierCart.setCategoryId(product.getCategoryId());
|
||||
cashierCartRepository.save(tbCashierCart);
|
||||
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
|
||||
|
||||
|
|
@ -394,9 +435,36 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
cashierCartRepository.save(tbCashierCart);
|
||||
}
|
||||
|
||||
setRedisTableCartInfo(addCartDTO.getTableId(), addCartDTO.getShopId().toString(), Collections.singletonList(tbCashierCart), true);
|
||||
|
||||
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
|
||||
public void removeCart(RemoveCartDTO removeCartDTO) {
|
||||
// 会员点单
|
||||
|
|
@ -409,10 +477,23 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
if (cashierCart.getOrderId() != null) {
|
||||
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()));
|
||||
}
|
||||
cashierCartMapper.delete(new LambdaQueryWrapper<TbCashierCart>().eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
|
||||
.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
|
||||
|
|
@ -428,6 +509,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.isNull(TbCashierCart::getUserId));
|
||||
}
|
||||
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
|
||||
|
|
@ -751,9 +841,27 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
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
|
||||
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();
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
|
|
@ -782,12 +890,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
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 packAMount = BigDecimal.ZERO;
|
||||
BigDecimal feeAmount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
Integer orderId = null;
|
||||
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
|
|
@ -815,11 +931,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
if (cashierCart.getOrderId() != null) {
|
||||
orderId = cashierCart.getOrderId();
|
||||
}
|
||||
orderDetail.setOrderId(orderId);
|
||||
}
|
||||
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (orderId != null) {
|
||||
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.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setPayAmount(BigDecimal.ZERO);
|
||||
orderInfo.setPackFee(packAMount);
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(totalAmount);
|
||||
|
|
@ -860,9 +982,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderInfo.setRefundAble(1);
|
||||
orderInfo.setTradeDay(day);
|
||||
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
||||
orderInfo.setOutNumber(createOrderDTO.getMasterId());
|
||||
orderInfo.setRemark(createOrderDTO.getNote());
|
||||
orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId()));
|
||||
orderInfo.setCreatedAt(DateUtil.current());
|
||||
orderInfo.setTableName(tbShopTable.getName());
|
||||
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>()
|
||||
.eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId())
|
||||
.eq(TbMerchantAccount::getStatus, 1));
|
||||
|
|
@ -871,6 +995,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
orderInfo.setMerchantId(merchantAccount.getId().toString());
|
||||
orderInfoMapper.insert(orderInfo);
|
||||
|
||||
redisTemplate.opsForValue().set(currentOrderKey, orderInfo.getId().toString());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -901,13 +1027,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
if (isFirst) {
|
||||
// 后付费,不增加当前台桌取餐号
|
||||
if (createOrderDTO.isPostPay()) {
|
||||
// addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId()));
|
||||
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||
redisTemplate.delete(key);
|
||||
} else {
|
||||
addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId()));
|
||||
// String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||
// redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
if (!createOrderDTO.isPostPay() || addMaterId){
|
||||
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 推送耗材信息
|
||||
|
|
@ -918,7 +1047,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
|
||||
|
||||
if (createOrderDTO.isPostPay()) {
|
||||
if (createOrderDTO.isPostPay() && isPrint) {
|
||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
||||
}
|
||||
|
||||
|
|
@ -990,7 +1119,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
createOrderDTO.setMasterId(pendingDTO.getMasterId());
|
||||
createOrderDTO.setVipUserId(pendingDTO.getVipUserId());
|
||||
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>()
|
||||
.eq(TbShopTable::getQrcode, cashierCart.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.PENDING.getState()));
|
||||
|
||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
||||
}
|
||||
|
||||
redisTemplate.delete(RedisConstant.getCurrentOrderKey(pendingDTO.getTableId(), pendingDTO.getShopId().toString()));
|
||||
|
||||
return orderInfoMapper.selectById(orderId);
|
||||
}
|
||||
|
||||
|
|
@ -1079,7 +1209,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
TbOrderInfo orderInfo = null;
|
||||
switch (payDTO.getPayType()) {
|
||||
case "vipPay":
|
||||
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId());
|
||||
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId(), payDTO.getDiscount(), payDTO.getVipUserId());
|
||||
break;
|
||||
case "cash":
|
||||
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
||||
|
|
@ -1097,9 +1227,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
// 打印消息
|
||||
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消息
|
||||
JSONObject mqData = new JSONObject();
|
||||
|
|
@ -1117,6 +1245,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,10 +73,15 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
|||
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() + ""));
|
||||
|
|
@ -194,51 +199,49 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
|||
|
||||
@Override
|
||||
public void modfiyAccount(Map<String, Object> map) {
|
||||
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("amount"))||ObjectUtil.isNull(map.get("amount"))||!map.containsKey("operationType")||ObjectUtil.isEmpty(map.get("operationType"))||ObjectUtil.isNull(map.get("operationType"))
|
||||
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("amount")) || ObjectUtil.isNull(map.get("amount")) || !map.containsKey("operationType") || ObjectUtil.isEmpty(map.get("operationType")) || ObjectUtil.isNull(map.get("operationType"))
|
||||
|
||||
){
|
||||
) {
|
||||
throw new BadRequestException("参数错误");
|
||||
|
||||
}
|
||||
|
||||
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("请输入正确的数字");
|
||||
}
|
||||
|
||||
|
||||
|
||||
TbShopUser tbShopUser= tbShopUserRepository.getById(Integer.valueOf(map.get("id")+""));
|
||||
if(ObjectUtil.isNull(tbShopUser)){
|
||||
throw new BadRequestException("不存在的会员信息");
|
||||
TbShopUser tbShopUser = tbShopUserRepository.getById(Integer.valueOf(map.get("id") + ""));
|
||||
if (ObjectUtil.isNull(tbShopUser)) {
|
||||
throw new BadRequestException("不存在的会员信息");
|
||||
}
|
||||
String operationType=map.get("operationType").toString();
|
||||
String operationType = map.get("operationType").toString();
|
||||
|
||||
BigDecimal amount=new BigDecimal(map.get("amount").toString());
|
||||
if("out".equals(operationType)){
|
||||
if(amount.compareTo(tbShopUser.getAmount())>0){
|
||||
BigDecimal amount = new BigDecimal(map.get("amount").toString());
|
||||
if ("out".equals(operationType)) {
|
||||
if (amount.compareTo(tbShopUser.getAmount()) > 0) {
|
||||
throw new BadRequestException("账户余额不足,请输入正确的金额");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String type = map.get("type").toString();
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
|
||||
String type=map.get("type").toString();
|
||||
TbShopUserFlow flow=new TbShopUserFlow();
|
||||
|
||||
if("in".equals(operationType)){
|
||||
if ("in".equals(operationType)) {
|
||||
flow.setType("+");
|
||||
flow.setBizName("inMoney".equals(type)?"充值":"消费退款");
|
||||
flow.setBizCode("inMoney".equals(type)?"inMoneyIn":"consumeIn");
|
||||
flow.setBizName("inMoney".equals(type) ? "充值" : "消费退款");
|
||||
flow.setBizCode("inMoney".equals(type) ? "inMoneyIn" : "consumeIn");
|
||||
tbShopUser.setAmount(tbShopUser.getAmount().add(amount));
|
||||
}else if("out".equals(operationType)){
|
||||
flow.setBizName("inMoneyOut".equals(type)?"充值退款":"消费");
|
||||
flow.setBizCode("inMoneyOut".equals(type)?"inMoneyOut":"consumeOut");
|
||||
} else if ("out".equals(operationType)) {
|
||||
flow.setBizName("inMoneyOut".equals(type) ? "充值退款" : "消费");
|
||||
flow.setBizCode("inMoneyOut".equals(type) ? "inMoneyOut" : "consumeOut");
|
||||
flow.setType("-");
|
||||
tbShopUser.setAmount(tbShopUser.getAmount().subtract(amount));
|
||||
}else {
|
||||
} else {
|
||||
throw new BadRequestException("错误的请求类型");
|
||||
}
|
||||
|
||||
|
|
@ -254,8 +257,6 @@ public class TbShopUserServiceImpl implements TbShopUserService {
|
|||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ public interface TbShopTableService {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
package cn.ysk.cashier.utils;
|
||||
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import org.slf4j.Logger;
|
||||
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;
|
||||
|
||||
public class Utils {
|
||||
public static int retryCount = 5;
|
||||
private static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||
|
||||
public static <T> void catchErrNoReturn(Supplier<T> supplier) {
|
||||
|
|
@ -15,4 +23,70 @@ public class Utils {
|
|||
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
|
||||
public class ShopUserInfoVo implements Serializable {
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private String headImg;
|
||||
private String nickName;
|
||||
private Object sex;
|
||||
|
|
|
|||
Loading…
Reference in New Issue