diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index b43ec8a..64491fc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.controller; +import cn.hutool.core.util.ObjectUtil; import com.chaozhanggui.system.cashierservice.entity.TbShopTable; import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto; import com.chaozhanggui.system.cashierservice.service.OrderService; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; import java.text.ParseException; +import java.util.Map; @CrossOrigin(origins = "*") @RestController @@ -51,6 +53,14 @@ public class OrderController { return orderService.orderList(userId,page,size,status); } + @PostMapping("/rmOrder") + private Result rmOrder(@RequestBody Map map){ + if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { + return Result.fail("订单号不允许为空"); + } + return orderService.rmOrder(Integer.valueOf(map.get("orderId").toString())); + } + @GetMapping("/tradeIntegral") private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException, ParseException { return orderService.tradeIntegral(userId,id); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java new file mode 100644 index 0000000..508867a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("userConpons") +public class TbUserCouponsController { + /** + * 服务对象 + */ + @Autowired + private TbUserCouponsService tbUserCouponsService; + + /** + * 查询优惠卷 + * @param conponDto + * @return + */ + @RequestMapping("find") + public Result queryByPage(@RequestBody UserCouponDto conponDto) { + return tbUserCouponsService.queryByPage(conponDto); + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java index 7a5a8f8..df4b1d5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java @@ -2,6 +2,8 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord; import com.chaozhanggui.system.cashierservice.entity.TbProduct; +import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -31,6 +33,7 @@ public interface TbActivateInRecordMapper { List queryAll(TbActivateInRecord tbActivateInRecord); List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); + List queryVipPro(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("shopName")String shopName); int queryByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId); List queryAllByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java index b2b9dcd..7b8b5ba 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -29,6 +30,8 @@ public interface TbActivateOutRecordMapper { */ List queryAll(TbActivateOutRecord tbActivateOutRecord); + List queryVipPro(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId, @Param("shopName") String shopName); + /** * 新增数据 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java index 20d3776..0affb60 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java @@ -11,6 +11,10 @@ import java.util.List; @Component @Mapper public interface TbOrderInfoMapper { + + /** + * 逻辑删除 + */ int deleteByPrimaryKey(Integer id); int insert(TbOrderInfo record); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java index 192a2e3..8306b65 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java @@ -1,6 +1,8 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -18,6 +20,7 @@ public interface TbUserCouponsMapper { int insertSelective(TbUserCoupons record); TbUserCoupons selectByPrimaryKey(Integer id); + List queryAllSelective(UserCouponDto record); int updateByPrimaryKeySelective(TbUserCoupons record); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java index 2b95fe1..120e92f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java @@ -37,6 +37,7 @@ public class TbOrderDetail implements Serializable { private BigDecimal priceAmount; private BigDecimal packAmount; + private String remark; private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index 3f34ec1..8a08964 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -103,6 +103,8 @@ public class TbOrderInfo implements Serializable { private String isWinner; private String shopName; + private String useType; + //根据状态返回 需付款 已付款 未付款 已退 private String description; @@ -188,4 +190,4 @@ public class TbOrderInfo implements Serializable { this.createdAt = System.currentTimeMillis(); this.isAccepted = 1; } -} \ No newline at end of file +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java index 6f59527..13d7029 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java @@ -7,10 +7,11 @@ import java.math.BigDecimal; import java.util.Date; @Data -public class TbUserCoupons implements Serializable { +public class TbUserCoupons implements Serializable{ private Integer id; private String userId; + private String detail; private Integer orderId; private BigDecimal couponsPrice; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java new file mode 100644 index 0000000..b53d03f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java @@ -0,0 +1,11 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +@Data +public class UserCouponDto extends BasePageDto{ + private Integer userId; + private Integer status; + private Integer shopId; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java new file mode 100644 index 0000000..8dfec49 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java @@ -0,0 +1,34 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class UserCouponVo { + /** + * 2 会员商品卷 + */ + private Integer type; + /** + * 卷描述 + */ + private String detail; + private String shopName; + /** + * 优惠金额 + */ + private BigDecimal couponsPrice = BigDecimal.ZERO; + /** + * 多少可用 + */ + private BigDecimal couponsAmount = BigDecimal.ZERO; + /** + * 数量 + */ + private Integer num; + /** + * 卷状态 0 未使用 + */ + private String status; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java index 1657918..77299dc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java @@ -1,11 +1,14 @@ package com.chaozhanggui.system.cashierservice.rabbit; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.model.CategoryInfo; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; +import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil; import com.chaozhanggui.system.cashierservice.util.JSONUtil; @@ -14,12 +17,15 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; @Slf4j @Component @@ -47,6 +53,10 @@ public class PrintMechineConsumer { @Autowired private TbOrderDetailMapper tbOrderDetailMapper; + @Autowired + private RedisTemplate redisTemplate2; + @Autowired + private StringRedisTemplate stringRedisTemplate; @RabbitHandler public void listener(String message) { @@ -74,6 +84,9 @@ public class PrintMechineConsumer { return; } + log.info("打印机列表,{}", ArrayUtil.toString(list)); + log.info("待打印订单信息, {}", orderInfo); + list.parallelStream().forEach(tbPrintMachineWithBLOBs->{ if (!"network".equals(tbPrintMachineWithBLOBs.getConnectionType())) { log.error("非网络打印机:{},{}",tbPrintMachineWithBLOBs.getAddress(),tbPrintMachineWithBLOBs.getConnectionType()); @@ -182,10 +195,20 @@ public class PrintMechineConsumer { break; case "one": //一菜一品 cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final"); + log.info("一菜一品打印,待打印信息:{}", cashierCarts); if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) { + cashierCarts.parallelStream().forEach(it -> { + // 取餐号不为空为代客下单 + if ("postPay".equals(orderInfo.getUseType()) && StrUtil.isNotBlank(it.getMasterId())) { + log.info("--------------------代客下单 打印一菜一品"); + printTicket(Integer.valueOf(orderId), categoryInfos, tbPrintMachineWithBLOBs, orderInfo); + return; + } + log.info("--------------------非代客下单 打印一菜一品"); + String categoryId; if(ObjectUtil.isEmpty(it.getCategoryId())){ categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId(); @@ -220,6 +243,115 @@ public class PrintMechineConsumer { } } + private void printTicket(Integer orderId, List categoryInfos, TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, TbOrderInfo orderInfo) { + String printKey = RedisCst.ORDER_PRINT_PRO + orderId; + AtomicReference> printProductSet = new AtomicReference<>(redisTemplate2.opsForSet().members(printKey)); + List tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderId); + log.info("--------------------订单detail列表: {}", tbOrderDetails); + log.info("--------------------缓存打印printProductSet: {}", printProductSet); + if (!tbOrderDetails.isEmpty()) { + + // 重置打印数据 + redisTemplate2.delete(printKey); + tbOrderDetails.forEach(it -> { + log.info("开始打印一菜一品票据,:{}", it.getProductName()); + String categoryId = tbProductMapper.selectByPrimaryKey(it.getProductId()).getCategoryId(); + + long count = categoryInfos.stream().filter(c -> + c.getId().toString().equals(categoryId) + ).count(); + + log.info("获取当前类别是否未打印类别:{}", count); + if (count > 0) { + + // 统计已打数量 + int printerNum = 0; + boolean isReturn = false; + String key = RedisCst.ORDER_PRINT + orderId + ":" + it.getProductId() + ":" + it.getProductSkuId(); + String info = stringRedisTemplate.opsForValue().get(key); + stringRedisTemplate.opsForValue().set(key, String.valueOf(it.getNum()), 60 * 60 * 24, TimeUnit.SECONDS); + + log.info("--------------------已打印数量: {}", info); + + // 删除已打印数据 + if (printProductSet.get() != null) { + printProductSet.set(printProductSet.get().stream().filter(r -> { + TbOrderDetail detail = (TbOrderDetail) r; + return !detail.getProductSkuId().equals(it.getProductSkuId()) || !detail.getProductId().equals(it.getProductId()); + }).collect(Collectors.toSet())); + } + + + if (info != null) { + isReturn = it.getNum() - Integer.parseInt(info) < 0; + printerNum = it.getNum() - Integer.parseInt(info); + }else { + printerNum = it.getNum(); + } + + log.info("--------------------isReturn: {}, 数量: {}", isReturn, printerNum); + + + TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(it.getProductSkuId()); + String remark = ""; + if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) { + remark = tbProductSkuWithBLOBs.getSpecSnap(); + } + + // 将已打印信息加入redis + it.setRemark(remark); + redisTemplate2.opsForSet().add(printKey, it); + redisTemplate2.expire(printKey, 24, TimeUnit.HOURS); + + // 已打印不再打印 + if (info != null && printerNum == 0) { + log.info("--------------------------订单已打印,跳过打印"); + return; + } + + String data; + String voiceJson; + if (isReturn) { + + data = PrinterUtils.getPrintData("return", + StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(), + DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), Math.abs(printerNum), remark); + voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}"; + + PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data); + + } else { + data = PrinterUtils.getPrintData("", orderInfo.getMasterId(), + DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), + printerNum, remark); + voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; + PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data); + + + } + } + }); + + } + + // 已删除的商品打印退款信息 + if (printProductSet.get() != null) { + printProductSet.get().forEach(item -> { + log.info("已删除订单,打印退款票据, {}", item); + TbOrderDetail orderDetail = (TbOrderDetail) item; + String data = PrinterUtils.getPrintData("return", + StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(), + DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), orderDetail.getRemark()); + String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}"; + PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data); + + String key = RedisCst.ORDER_PRINT + orderId + ":" + orderDetail.getProductId() + ":" + orderDetail.getProductSkuId(); + log.info("删除商品数量记录key, {}", key); + stringRedisTemplate.delete(key); + }); + } + } + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java index 35934b2..0019723 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java @@ -96,4 +96,11 @@ public class RedisConfig { template.setValueSerializer(new StringRedisSerializer(Charset.forName("UTF-8"))); return template; } + + @Bean + public RedisTemplate redisTemplate2(RedisConnectionFactory factory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(factory); + return template; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java index d305be3..45a477b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java @@ -26,4 +26,13 @@ public class RedisCst { public static final String CREATE_ORDER_LOCK = "CREATE_ORDER_LOCK:"; public static final String SEND_STOCK_WARN_MSG = "SEND_STOCK_WARN_MSG:"; public static final String SONG_PAY_LOCK = "song_pay_lock:"; + public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:"; + public static final String ORDER_PRINT = "ORDER_PRINT:"; + + static String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:"; + + + public static String getCurrentOrderKey(String tableId, String shopId) { + return CURRENT_TABLE_ORDER + shopId + ":" + tableId; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 833db96..f68534f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -93,6 +94,8 @@ public class CartService { private final RedisTemplate redisTemplate; + private final StringRedisTemplate stringRedisTemplate; + @Autowired private TbProskuConMapper tbProskuConMapper; @@ -100,7 +103,7 @@ public class CartService { @Autowired TbConsInfoMapper tbConsInfoMapper; - public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate redisTemplate) { + public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate redisTemplate, StringRedisTemplate stringRedisTemplate) { this.tbUserShopMsgMapper = tbUserShopMsgMapper; this.wechatUtil = wechatUtil; this.wxAccountUtil = wxAccountUtil; @@ -108,6 +111,7 @@ public class CartService { this.productService = productService; this.tbProductMapper = tbProductMapper; this.redisTemplate = redisTemplate; + this.stringRedisTemplate = stringRedisTemplate; } public void initCart(JSONObject jsonObject) { @@ -224,7 +228,8 @@ public class CartService { if (cashierCart.getSkuId().equals(skuId) && cashierCart.getIsVip().intValue() == isVip) { cashierCart.setTotalNumber(buyNum); cashierCart.setNumber(buyNum); - if (type == 0 && isVip == 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) { + if (type == 0 && isVip == 0 && tbProductSkuWithBLOBs.getSuit() != null + && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) { cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); continue; } @@ -650,28 +655,7 @@ public class CartService { couponAmount = userCoupons.getCouponsAmount(); } else { TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已使用"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } + totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); userCoupons.setStatus("1"); userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); @@ -708,6 +692,7 @@ public class CartService { orderInfo.setIsBuyCoupon(isBuyYhq); orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setRemark(remark); + orderInfo.setUserId(userId); orderInfoMapper.updateByPrimaryKeySelective(orderInfo); } else { @@ -719,6 +704,7 @@ public class CartService { orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setUserCouponAmount(couponAmount); orderInfo.setRemark(remark); + orderInfo.setUserId(userId); JSONObject object = new JSONObject(); String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index ccb8505..23c2434 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -212,6 +212,14 @@ public class OrderService { return Result.success(CodeEnum.ENCRYPT, orderVo); } + public Result rmOrder(Integer orderId) { + int i = orderInfoMapper.deleteByPrimaryKey(orderId); + if (i > 0) { + return Result.success(CodeEnum.SUCCESS); + } + return Result.fail("删除失败"); + } + public Result orderList(Integer userId, Integer page, Integer size, String status) { // TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(userId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 0b2b1cc..3e832ae 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -31,6 +31,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -158,6 +159,8 @@ public class PayService { private final TbShopSongOrderService shopSongOrderService; @Autowired private MQUtils mQUtils; + @Autowired + private StringRedisTemplate stringRedisTemplate; public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) { this.shopSongOrderService = shopSongOrderService; @@ -330,6 +333,7 @@ public class PayService { if (ObjectUtil.isEmpty(orderInfo)) { return Result.fail("订单信息不存在"); } + if (System.currentTimeMillis() - orderInfo.getCreatedAt() > 60 * 15 * 1000) { return Result.fail("订单十五分钟内有效,当前已超时,请重新下单。"); } @@ -432,10 +436,12 @@ public class PayService { baObj.put("time",flow.getCreateTime()); producer.balance(baObj.toString()); - - - - + // 为代客下单清楚当前台桌最新订单 + String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId()); + String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey); + if (currentOrderId != null && currentOrderId.equals(orderId)) { + stringRedisTemplate.delete(currentOrderKey); + } return Result.success(CodeEnum.SUCCESS, "1"); } @@ -916,6 +922,13 @@ public class PayService { sendOrderToClient(orderInfo); redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString())); + // 为代客下单清除当前台桌最新订单 + String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId()); + String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey); + if (currentOrderId != null && currentOrderId.equals(orderInfo.getId().toString())) { + stringRedisTemplate.delete(currentOrderKey); + } + // 发送mq消息并保存库存记录 JSONObject data = new JSONObject(); data.put("orderId", orderInfo.getId()); @@ -967,6 +980,13 @@ public class PayService { sendOrderToClient(orderInfo); redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString())); + // 为代客下单清楚当前台桌最新订单 + String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId()); + String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey); + if (currentOrderId != null && currentOrderId.equals(orderInfo.getId().toString())) { + stringRedisTemplate.delete(currentOrderKey); + } + // 发送mq消息并保存库存记录 JSONObject data = new JSONObject(); data.put("orderId", orderInfo.getId()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java new file mode 100644 index 0000000..c687d0a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.sign.Result; + +/** + * (TbUserCoupons)表服务接口 + * + * @author ww + * @since 2024-09-02 13:38:20 + */ +public interface TbUserCouponsService { + + /** + * 分页查询 + * + * @param tbUserCoupons 筛选条件 + * @return 查询结果 + */ + Result queryByPage(UserCouponDto tbUserCoupons); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java new file mode 100644 index 0000000..5236c6c --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java @@ -0,0 +1,71 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.chaozhanggui.system.cashierservice.dao.*; +import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; +import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * (TbUserCoupons)表服务实现类 + * + * @author ww + * @since 2024-09-02 13:38:20 + */ +@Primary +@Service +public class TbUserCouponsServiceImpl implements TbUserCouponsService { + @Resource + private TbUserCouponsMapper tbUserCouponsMapper; + @Resource + private TbActivateInRecordMapper inRecordMapper; + @Resource + private TbActivateOutRecordMapper outRecordMapper; + @Autowired + private TbShopUserMapper tbShopUserMapper; + @Autowired + private TbShopInfoMapper tbShopInfoMapper; + + + /** + * 分页查询 + * @return 查询结果 + */ + @Override + public Result queryByPage(UserCouponDto couponDto) { +// PageHelper.startPage(couponDto.getPage(), couponDto.getSize()); +// List result = tbUserCouponsMapper.queryAllSelective(couponDto); +// return new Result(CodeEnum.SUCCESS, new PageInfo<>(result)); +// List result = tbUserCouponsMapper.queryAllSelective(couponDto); + List result = new ArrayList<>(); + List tbShopUsers = tbShopUserMapper.selectByUserId(couponDto.getUserId().toString(), couponDto.getShopId()==null?null:couponDto.getShopId().toString()); + if (!CollectionUtils.isEmpty(tbShopUsers)) { + tbShopUsers.forEach(s -> { + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(s.getShopId().intValue()); + if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() == 0)) { + List unuseCoupon = inRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue(),shopInfo.getShopName()); + result.addAll(unuseCoupon); + } + if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() == 1)) { + List useCoupon = outRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue(),shopInfo.getShopName()); + result.addAll(useCoupon); + } + }); + } + + return new Result(CodeEnum.SUCCESS, result); + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java index 16f3cbd..7f438c6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.util; import cn.hutool.core.util.ObjectUtil; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -14,6 +15,7 @@ import java.util.*; /** * 打印机 */ +@Slf4j public class PrinterUtils { //请求地址 private static final String URL_STR = "https://ioe.car900.com/v1/openApi/dev/customPrint.json"; @@ -83,6 +85,41 @@ public class PrinterUtils { return builder.toString(); } + /** + * 厨房打印机 + * + * @param pickupNumber + * @param date + * @param productName + * @param number + * @param remark + * @return + */ + public static String getPrintData(String type, String pickupNumber, String date, String productName, Integer number, String remark) { + StringBuilder builder = new StringBuilder(); + if ("return".equals(type)) { + builder.append("" + pickupNumber + "【退】

"); + } else { + builder.append("" + pickupNumber + "

"); + } + + + builder.append("时间: " + date + "


"); + + if (productName.length() > 4 || remark.length() > 4) { + builder.append("" + productName + " " + number + "
"); + builder.append("" + remark + "
"); + } else { + builder.append("" + productName + " " + number + "
"); + builder.append("" + remark + "
"); + } + builder.append(""); + builder.append(""); + + return builder.toString(); + } + + public static String getCashPrintData(OrderDetailPO detailPO,String type){ StringBuilder sb = new StringBuilder(); @@ -162,7 +199,46 @@ public class PrinterUtils { + /** + * 打印票据 + * + * @throws Exception + */ + public static void printTickets(String voiceJson, Integer actWay, Integer cn, String devName, String data) { + log.info("开始请求云享印,请求数据:{}, {}", voiceJson, data); + //设备名称 + //行为方式 1:只打印数据 2:只播放信息 3:打印数据并播放信息 +// actWay = 3; +// //打印联数 +// int cn = 1; + //打印内容 + //播报语音数据体,字段参考文档IOT_XY_API11001 + String time = String.valueOf(System.currentTimeMillis()); + String uuid = UUID.randomUUID().toString(); + Map param = getToken(time, uuid); + //参数 + MultiValueMap multiValueMap = new LinkedMultiValueMap<>(); + multiValueMap.add("token", param.get("TOKEN")); + multiValueMap.add("devName", devName); + multiValueMap.add("actWay", actWay); + multiValueMap.add("cn", cn); + multiValueMap.add("data", data); + multiValueMap.add("voiceJson", voiceJson); + multiValueMap.add("appId", APP_ID); + multiValueMap.add("timestamp", time); + multiValueMap.add("requestId", uuid); + multiValueMap.add("userCode", USER_CODE); + RestTemplate restTemplate = new RestTemplate(); + HttpHeaders header = new HttpHeaders(); + header.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + HttpEntity> httpEntity = new HttpEntity<>(multiValueMap, header); + String httpResponse = restTemplate.postForObject(URL_STR, + httpEntity, String.class); + + System.out.println("map" + httpResponse); + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 73baaa9..d91d442 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -23,11 +23,11 @@ import java.util.Map; @Slf4j @Component public class WxAccountUtil { - @Value("${wx.ysk.appId}") +// @Value("${wx.ysk.appId}") private static String appId = "wx212769170d2c6b2a"; - @Value("${wx.ysk.secrete}") +// @Value("${wx.ysk.secrete}") private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0"; - @Value("${wx.ysk.warnMsgTmpId}") +// @Value("${wx.ysk.warnMsgTmpId}") private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0"; private final TbShopMsgStateMapper shopMsgStateMapper; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b31734b..3d23497 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -55,7 +55,7 @@ logging: # web日志 org.springframework.web: debug # mybatis日志 - org.mybatis: debug + org.apache.ibatis: debug charset: # 输出控制台编码 console: UTF-8 diff --git a/src/main/resources/mapper/TbActivateInRecordMapper.xml b/src/main/resources/mapper/TbActivateInRecordMapper.xml index aa51b93..6d9ad84 100644 --- a/src/main/resources/mapper/TbActivateInRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateInRecordMapper.xml @@ -39,6 +39,23 @@ group by tb_activate_in_record.pro_id + + + + + select - + * from tb_order_info where id = #{id,jdbcType=INTEGER} - - delete from tb_order_info - where id = #{id,jdbcType=INTEGER} - + + + + + + update tb_order_info + set is_del = 1 + where id = #{id,jdbcType=INTEGER} + - insert into tb_order_info (id, order_no, settlement_amount, - pack_fee, origin_amount, product_amount, - amount, refund_amount, pay_type, - pay_amount, order_amount, freight_amount, - discount_ratio, discount_amount, table_id, - small_change, send_type, order_type, - product_type, status, billing_id, - merchant_id, shop_id, is_vip, - member_id, user_id, product_score, - deduct_score, user_coupon_id, user_coupon_amount, - refund_able, paid_time, is_effect, - is_group, updated_at, system_time, + insert into tb_order_info (id, order_no, settlement_amount, + pack_fee, origin_amount, product_amount, + amount, refund_amount, pay_type, + pay_amount, order_amount, freight_amount, + discount_ratio, discount_amount, table_id, + small_change, send_type, order_type, + product_type, status, billing_id, + merchant_id, shop_id, is_vip, + member_id, user_id, product_score, + deduct_score, user_coupon_id, user_coupon_amount, + refund_able, paid_time, is_effect, + is_group, updated_at, system_time, created_at, is_accepted, pay_order_no,trade_day,source,remark,master_id,table_name,is_buy_coupon,is_use_coupon,out_number ) - values (#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{settlementAmount,jdbcType=DECIMAL}, - #{packFee,jdbcType=DECIMAL}, #{originAmount,jdbcType=DECIMAL}, #{productAmount,jdbcType=DECIMAL}, - #{amount,jdbcType=DECIMAL}, #{refundAmount,jdbcType=DECIMAL}, #{payType,jdbcType=VARCHAR}, - #{payAmount,jdbcType=DECIMAL}, #{orderAmount,jdbcType=DECIMAL}, #{freightAmount,jdbcType=DECIMAL}, - #{discountRatio,jdbcType=DECIMAL}, #{discountAmount,jdbcType=DECIMAL}, #{tableId,jdbcType=VARCHAR}, - #{smallChange,jdbcType=DECIMAL}, #{sendType,jdbcType=VARCHAR}, #{orderType,jdbcType=VARCHAR}, - #{productType,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{billingId,jdbcType=VARCHAR}, - #{merchantId,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{isVip,jdbcType=TINYINT}, - #{memberId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{productScore,jdbcType=INTEGER}, - #{deductScore,jdbcType=INTEGER}, #{userCouponId,jdbcType=VARCHAR}, #{userCouponAmount,jdbcType=DECIMAL}, - #{refundAble,jdbcType=TINYINT}, #{paidTime,jdbcType=BIGINT}, #{isEffect,jdbcType=TINYINT}, - #{isGroup,jdbcType=TINYINT}, #{updatedAt,jdbcType=BIGINT}, #{systemTime,jdbcType=BIGINT}, + values (#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{settlementAmount,jdbcType=DECIMAL}, + #{packFee,jdbcType=DECIMAL}, #{originAmount,jdbcType=DECIMAL}, #{productAmount,jdbcType=DECIMAL}, + #{amount,jdbcType=DECIMAL}, #{refundAmount,jdbcType=DECIMAL}, #{payType,jdbcType=VARCHAR}, + #{payAmount,jdbcType=DECIMAL}, #{orderAmount,jdbcType=DECIMAL}, #{freightAmount,jdbcType=DECIMAL}, + #{discountRatio,jdbcType=DECIMAL}, #{discountAmount,jdbcType=DECIMAL}, #{tableId,jdbcType=VARCHAR}, + #{smallChange,jdbcType=DECIMAL}, #{sendType,jdbcType=VARCHAR}, #{orderType,jdbcType=VARCHAR}, + #{productType,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{billingId,jdbcType=VARCHAR}, + #{merchantId,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{isVip,jdbcType=TINYINT}, + #{memberId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{productScore,jdbcType=INTEGER}, + #{deductScore,jdbcType=INTEGER}, #{userCouponId,jdbcType=VARCHAR}, #{userCouponAmount,jdbcType=DECIMAL}, + #{refundAble,jdbcType=TINYINT}, #{paidTime,jdbcType=BIGINT}, #{isEffect,jdbcType=TINYINT}, + #{isGroup,jdbcType=TINYINT}, #{updatedAt,jdbcType=BIGINT}, #{systemTime,jdbcType=BIGINT}, #{createdAt,jdbcType=BIGINT}, #{isAccepted,jdbcType=TINYINT}, #{payOrderNo,jdbcType=VARCHAR}, #{tradeDay,jdbcType=VARCHAR}, #{source,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{masterId,jdbcType=VARCHAR}, #{tableName,jdbcType=VARCHAR}, #{isBuyCoupon,jdbcType=VARCHAR}, #{isUseCoupon,jdbcType=VARCHAR},#{outNumber,jdbcType=VARCHAR} @@ -486,9 +491,10 @@ is_buy_coupon = #{isBuyCoupon,jdbcType=VARCHAR}, - - is_use_coupon = #{isUseCoupon,jdbcType=VARCHAR}, + + user_id = #{userId,jdbcType=VARCHAR}, + where id = #{id,jdbcType=INTEGER} @@ -549,6 +555,7 @@ where user_id = #{userId} and order_type='miniapp' + and is_del != 1 @@ -576,4 +583,4 @@ left join tb_user_info tui on tui.id = toi.user_id where toi.user_id = #{userId} - \ No newline at end of file + diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index e13ffa6..c3cc4c9 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -414,6 +414,10 @@ select * from tb_shop_user where user_id=#{userId} + + diff --git a/src/main/resources/mapper/TbUserCouponsMapper.xml b/src/main/resources/mapper/TbUserCouponsMapper.xml index b746d3c..cd27c4b 100644 --- a/src/main/resources/mapper/TbUserCouponsMapper.xml +++ b/src/main/resources/mapper/TbUserCouponsMapper.xml @@ -4,6 +4,7 @@ + @@ -13,7 +14,7 @@ - id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double + id, user_id, detail, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double + + +