Merge remote-tracking branch 'origin/test' into test

# Conflicts:
#	src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java
This commit is contained in:
牛叉闪闪
2024-08-22 15:09:46 +08:00
32 changed files with 566 additions and 111 deletions

85
pom.xml
View File

@@ -48,11 +48,11 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>4.5.18</version> <version>4.5.18</version>
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>--> <!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>fastjson</artifactId>--> <!-- <artifactId>fastjson</artifactId>-->
<!-- <version>1.2.9</version>--> <!-- <version>1.2.9</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@@ -185,30 +185,57 @@
<version>2.2.0</version> <version>2.2.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.3.1</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<!-- <profiles>--> <!-- <profiles>-->
<!-- <profile>--> <!-- <profile>-->
<!-- <id>dev</id>--> <!-- <id>dev</id>-->
<!-- <properties>--> <!-- <properties>-->
<!-- <env>dev</env>--> <!-- <env>dev</env>-->
<!-- </properties>--> <!-- </properties>-->
<!-- <activation>--> <!-- <activation>-->
<!-- <activeByDefault>true</activeByDefault>--> <!-- <activeByDefault>true</activeByDefault>-->
<!-- </activation>--> <!-- </activation>-->
<!-- </profile>--> <!-- </profile>-->
<!-- <profile>--> <!-- <profile>-->
<!-- <id>test</id>--> <!-- <id>test</id>-->
<!-- <properties>--> <!-- <properties>-->
<!-- <env>test</env>--> <!-- <env>test</env>-->
<!-- </properties>--> <!-- </properties>-->
<!-- </profile>--> <!-- </profile>-->
<!-- <profile>--> <!-- <profile>-->
<!-- <id>pro</id>--> <!-- <id>pro</id>-->
<!-- <properties>--> <!-- <properties>-->
<!-- <env>pro</env>--> <!-- <env>pro</env>-->
<!-- </properties>--> <!-- </properties>-->
<!-- </profile>--> <!-- </profile>-->
<!-- </profiles>--> <!-- </profiles>-->
<build> <build>
<plugins> <plugins>
@@ -266,4 +293,4 @@
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@@ -10,7 +10,7 @@ import lombok.Getter;
@Getter @Getter
public enum LogTag { public enum LogTag {
JPUSH("极光"), CLIENT("安卓"), JPUSH("极光"), CLIENT("安卓"),
LOGIN("登录"), SYSTEM("系统"), CART("订单购物车"); LOGIN("登录"), SYSTEM("系统"), CART("订单购物车"), PLACE("下单");
private final String value; private final String value;
LogTag(String value) { LogTag(String value) {

View File

@@ -0,0 +1,15 @@
package com.chaozhanggui.system.cashierservice.bean;
public enum TableStateEnum {
IDLE("idle"),
CLOSED("closed"), PAYING("paying"), PENDING("pending"), USING("using");
private String state = "closed";
TableStateEnum(String state) {
this.state = state;
}
public String getState() {
return state;
}
}

View File

@@ -6,12 +6,15 @@ import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.annotation.MyLog; import com.chaozhanggui.system.cashierservice.annotation.MyLog;
import com.chaozhanggui.system.cashierservice.bean.LogTag; import com.chaozhanggui.system.cashierservice.bean.LogTag;
import com.chaozhanggui.system.cashierservice.entity.OrderVo; import com.chaozhanggui.system.cashierservice.entity.OrderVo;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo; import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.service.OrderService; import com.chaozhanggui.system.cashierservice.service.OrderService;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.TokenUtil; import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@@ -24,6 +27,14 @@ public class OrderController {
@Autowired @Autowired
private OrderService orderService; private OrderService orderService;
@PutMapping("/updateVip")
@MyLog(value = "代客下单 修改会员", tag = LogTag.PLACE)
public ResponseEntity<Object> updateVip(
@Validated @RequestBody UpdateVipDTO updateVipDTO
) {
return ResponseEntity.ok(orderService.updateVip(updateVipDTO));
}
@PostMapping("/createCart") @PostMapping("/createCart")
public Result createCart(@RequestHeader("token") String token, public Result createCart(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName, @RequestHeader("loginName") String loginName,
@@ -34,7 +45,7 @@ public class OrderController {
String userId = jsonObject.getString("accountId"); String userId = jsonObject.getString("accountId");
return orderService.createCart(cartVo.getMasterId(),cartVo.getProductId(),cartVo.getShopId(), return orderService.createCart(cartVo.getMasterId(),cartVo.getProductId(),cartVo.getShopId(),
cartVo.getSkuId(),cartVo.getNumber(),userId,clientType,cartVo.getCartId(),cartVo.getIsGift(), cartVo.getSkuId(),cartVo.getNumber(),userId,clientType,cartVo.getCartId(),cartVo.getIsGift(),
cartVo.getIsPack(),cartVo.getUuid(),cartVo.getType()); cartVo.getIsPack(),cartVo.getUuid(),cartVo.getType(), cartVo.getTableId());
} }
@MyLog(value = "查询购物车信息", tag = LogTag.CART) @MyLog(value = "查询购物车信息", tag = LogTag.CART)
@@ -49,7 +60,7 @@ public class OrderController {
if (tableId == null && StrUtil.isBlank(masterId)) { if (tableId == null && StrUtil.isBlank(masterId)) {
return Result.fail("masterId和tableId不能同时为空"); return Result.fail("masterId和tableId不能同时为空");
} }
return orderService.queryCart(masterId,shopId); return orderService.queryCart(masterId,shopId, tableId);
} }
@@ -90,7 +101,8 @@ public class OrderController {
JSONObject jsonObject = TokenUtil.parseParamFromToken(token); JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
String userId = jsonObject.getString("accountId"); String userId = jsonObject.getString("accountId");
String code = jsonObject.getString("code"); String code = jsonObject.getString("code");
return orderService.cartStatus(Integer.valueOf(cartVo.getShopId()),cartVo.getMasterId(),cartVo.getStatus(),userId,cartVo.getUuid(),clientType); return orderService.cartStatus(Integer.valueOf(cartVo.getShopId()),cartVo.getMasterId(),
cartVo.getStatus(),userId,cartVo.getUuid(),clientType, cartVo.getVipUserId(), cartVo.getTableId());
} }
@PostMapping("/createOrder") @PostMapping("/createOrder")
public Result createOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, public Result createOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,

View File

@@ -198,6 +198,26 @@ public class PayController {
} }
/**
* 会员支付
* @param token
* @param loginName
* @param clientType
* @param orderId
* @return
*/
@GetMapping("vipPay")
@LimitSubmit(key = "vipPay:%s")
public Result vipPay(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType,
@RequestParam("orderId") String orderId,
@RequestParam("vipUserId") Integer vipUserId){
return payService.vipPay(orderId,token, vipUserId);
}
/** /**
@@ -216,7 +236,7 @@ public class PayController {
@RequestParam("orderId") String orderId, @RequestParam("orderId") String orderId,
@RequestParam("payAmount") BigDecimal payAmount, @RequestParam("payAmount") BigDecimal payAmount,
@RequestParam("discountAmount") BigDecimal discountAmount){ @RequestParam("discountAmount") BigDecimal discountAmount){
return payService.bankPay(orderId,token,payAmount,discountAmount); return payService.bankPay(orderId,token);
} }

View File

@@ -77,11 +77,12 @@ public class ProductController {
@RequestParam("categoryId") String categoryId, @RequestParam("categoryId") String categoryId,
@RequestParam("commdityName") String commdityName, @RequestParam("commdityName") String commdityName,
@RequestParam("masterId") String masterId, @RequestParam("masterId") String masterId,
@RequestParam("tableId") String tableId,
@RequestParam("page") int page, @RequestParam("page") int page,
@RequestParam("pageSize") int pageSize @RequestParam("pageSize") int pageSize
){ ){
return productService.queryNewCommodityInfo(shopId,categoryId,commdityName,page,pageSize,masterId); return productService.queryNewCommodityInfo(shopId,categoryId,commdityName, tableId,page,pageSize,masterId);
} }
@GetMapping(value = "queryCategory") @GetMapping(value = "queryCategory")

View File

@@ -30,7 +30,7 @@ public interface TbCashierCartMapper {
List<TbCashierCart> selectALlByMasterId(@Param("masterId") String masterId,@Param("status") String status); List<TbCashierCart> selectALlByMasterId(@Param("masterId") String masterId,@Param("status") String status);
TbCashierCart selectByDetail(@Param("masterId") String masterId, @Param("productId") String productId, TbCashierCart selectByDetail(@Param("masterId") String masterId, @Param("productId") String productId,
@Param("shopId") String shopId, @Param("skuId") String skuId, @Param("day") String day,@Param("uuid") String uuid); @Param("shopId") String shopId, @Param("skuId") String skuId, @Param("day") String day,@Param("uuid") String uuid, @Param("tableId") String tableId);
TbCashierCart selectDetailByQrcode(@Param("tableId") String tableId, @Param("productId") String productId, TbCashierCart selectDetailByQrcode(@Param("tableId") String tableId, @Param("productId") String productId,
@Param("shopId") String shopId, @Param("skuId") String skuId, @Param("uuid") String uuid); @Param("shopId") String shopId, @Param("skuId") String skuId, @Param("uuid") String uuid);

View File

@@ -40,7 +40,7 @@ public interface TbProductMapper {
Integer countOrderByshopIdAndProductId(@Param("shopId") String shopId, @Param("productId") String productId, @Param("masterId") String masterId,@Param("day") String day); Integer countOrderByshopIdAndProductId(@Param("shopId") String shopId, @Param("productId") String productId, @Param("masterId") String masterId,@Param("day") String day, @Param("tableId") String tableId);
void updateStockById(@Param("productId")Integer productId, @Param("num")Integer num); void updateStockById(@Param("productId")Integer productId, @Param("num")Integer num);

View File

@@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.dao; package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable; import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.entity.vo.TbShopTableVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -23,4 +24,5 @@ public interface TbShopTableMapper {
int updateByPrimaryKey(TbShopTable record); int updateByPrimaryKey(TbShopTable record);
List<TbShopTable> selectByShopIdAndStatus(@Param("shopId") String shopId,@Param("areaId") String areaId,@Param("status") String status); List<TbShopTable> selectByShopIdAndStatus(@Param("shopId") String shopId,@Param("areaId") String areaId,@Param("status") String status);
} List<TbShopTableVO> selectTableInfo(@Param("shopId") String shopId, @Param("areaId") String areaId, @Param("status") String status);
}

View File

@@ -12,4 +12,6 @@ public class OrderVo {
private Integer shopId; private Integer shopId;
private String userId; private String userId;
private Integer merchantId; private Integer merchantId;
private String tableId;
private Integer vipUserId;
} }

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.entity; package com.chaozhanggui.system.cashierservice.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@@ -57,8 +58,12 @@ public class TbCashierCart implements Serializable {
private Long updatedAt; private Long updatedAt;
private Integer userId; private Integer userId;
private String tableId; private String tableId;
@TableField(exist = false)
private TbProductSpec tbProductSpec; private TbProductSpec tbProductSpec;
@TableField(exist = false)
private String selectSpec=""; private String selectSpec="";
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@@ -102,6 +102,8 @@ public class TbOrderInfo implements Serializable {
private Integer staffId; private Integer staffId;
private String useType;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public TbOrderInfo(){ public TbOrderInfo(){
super(); super();
@@ -166,4 +168,4 @@ public class TbOrderInfo implements Serializable {
this.payType=payType; this.payType=payType;
this.tableName=tableName; this.tableName=tableName;
} }
} }

View File

@@ -0,0 +1,23 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class UpdateVipDTO {
@NotNull
private Integer shopId;
@NotEmpty
private String tableId;
@NotNull
private String masterId;
private Integer vipUserId;
@NotNull
@Range(min = 0, max = 1)
private Integer type;
}

View File

@@ -5,10 +5,6 @@ import lombok.Data;
@Data @Data
public class CartVo { public class CartVo {
private String productId; private String productId;
// orderId不为空为代客下单
private String masterId;
private String tableId;
private String shopId; private String shopId;
private Integer skuId; private Integer skuId;
private Integer number; private Integer number;
@@ -18,4 +14,7 @@ public class CartVo {
private String uuid; private String uuid;
private String type; private String type;
private Integer cartId; private Integer cartId;
private String masterId;
private String tableId;
private Integer vipUserId;
} }

View File

@@ -0,0 +1,17 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
@EqualsAndHashCode(callSuper = true)
@Data
public class TbShopTableVO extends TbShopTable {
private Integer userId;
private String masterId;
private Integer orderId;
private String orderNo;
private BigDecimal orderAmount;
}

View File

@@ -0,0 +1,7 @@
package com.chaozhanggui.system.cashierservice.mybatis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
public interface MPCashierCartMapper extends BaseMapper<TbCashierCart> {
}

View File

@@ -0,0 +1,8 @@
package com.chaozhanggui.system.cashierservice.mybatis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
public interface MpShopTableMapper extends BaseMapper<TbShopTable> {
}

View File

@@ -0,0 +1,7 @@
package com.chaozhanggui.system.cashierservice.mybatis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopUserFlow;
public interface MpShopUserFlowMapper extends BaseMapper<TbShopUserFlow> {
}

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.mybatis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal;
public interface MpShopUserMapper extends BaseMapper<TbShopUser> {
@Update("update tb_shop_user set amount=amount-#{orderAmount}, consume_amount=consume_amount+#{orderAmount} where id=#{vipUserId} and amount >= 0")
long decrBalance(@Param("vipUserId") Integer vipUserId, @Param("orderAmount") BigDecimal orderAmount);
}

View File

@@ -8,10 +8,7 @@ import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.*;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
@@ -49,6 +46,9 @@ public class PrintMechineConsumer {
@Autowired @Autowired
private TbOrderDetailMapper tbOrderDetailMapper; private TbOrderDetailMapper tbOrderDetailMapper;
@Autowired
private RedisUtil redisUtils;
@RabbitHandler @RabbitHandler
public void listener(String message) { public void listener(String message) {
@@ -127,7 +127,8 @@ public class PrintMechineConsumer {
* @param shopInfo * @param shopInfo
* @param printerNum * @param printerNum
*/ */
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){ private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,
TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
String orderId=orderInfo.getId().toString(); String orderId=orderInfo.getId().toString();
@@ -257,10 +258,13 @@ public class PrintMechineConsumer {
return; return;
}else { }else {
tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId)); tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) { if (ObjectUtil.isNotEmpty(tbOrderDetails) && !tbOrderDetails.isEmpty()) {
tbOrderDetails.parallelStream().forEach(it -> { tbOrderDetails.parallelStream().forEach(it -> {
// 已经打印过的菜品不再打印
if ("postPay".equals(orderInfo.getUseType()) && isPrint(it)) {
return;
}
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId(); String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count = categoryInfos.stream().filter(c -> Long count = categoryInfos.stream().filter(c ->
@@ -274,7 +278,9 @@ public class PrintMechineConsumer {
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) { if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap(); remark = tbProductSkuWithBLOBs.getSpecSnap();
} }
String data = PrinterUtils.getPrintData("",orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark); String data = PrinterUtils.getPrintData("",orderInfo.getMasterId(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(),
it.getNum(), remark);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data); PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
} }
@@ -292,6 +298,21 @@ public class PrintMechineConsumer {
} }
} }
/**
* 判断商品是否已打票
* @return true 已打 false 未打
*/
private boolean isPrint(TbOrderDetail orderDetail) {
String key = RedisCst.ORDER_PRINT + orderDetail.getProductId() + ":" + orderDetail.getProductSkuId();
String info = redisUtils.getMessage(key);
redisUtils.saveMessage(key, String.valueOf(orderDetail.getNum()), 60 * 60 * 24);
if (info == null) {
return false;
}
orderDetail.setNum(orderDetail.getNum() - Integer.parseInt(info));
return true;
}

View File

@@ -37,8 +37,6 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
public void cons(String content){ public void cons(String content){
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT, content, correlationId); rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT, content, correlationId);

View File

@@ -1,17 +1,24 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum; import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
import com.chaozhanggui.system.cashierservice.entity.po.*; import com.chaozhanggui.system.cashierservice.entity.po.*;
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo; import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mybatis.MPCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -26,7 +33,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -68,6 +74,7 @@ public class OrderService {
RedisUtil redisUtil; RedisUtil redisUtil;
private final WxAccountUtil wxAccountUtil; private final WxAccountUtil wxAccountUtil;
private final MPCashierCartMapper mpCashierCartMapper;
@Autowired @Autowired
RabbitProducer producer; RabbitProducer producer;
@@ -77,6 +84,7 @@ public class OrderService {
private final TbUserShopMsgMapper tbUserShopMsgMapper; private final TbUserShopMsgMapper tbUserShopMsgMapper;
private final TbShopOpenIdMapper shopOpenIdMapper; private final TbShopOpenIdMapper shopOpenIdMapper;
private final MpShopTableMapper mpShopTableMapper;
@Autowired @Autowired
private TbProskuConMapper tbProskuConMapper; private TbProskuConMapper tbProskuConMapper;
@@ -90,16 +98,18 @@ public class OrderService {
@Autowired @Autowired
private ProductService productService; private ProductService productService;
public OrderService(WxAccountUtil wxAccountUtil, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper) { public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper) {
this.wxAccountUtil = wxAccountUtil; this.wxAccountUtil = wxAccountUtil;
this.mpCashierCartMapper = mpCashierCartMapper;
this.wechatUtil = wechatUtil; this.wechatUtil = wechatUtil;
this.tbUserShopMsgMapper = tbUserShopMsgMapper; this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.shopOpenIdMapper = shopOpenIdMapper; this.shopOpenIdMapper = shopOpenIdMapper;
this.mpShopTableMapper = mpShopTableMapper;
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number, public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number,
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type) { String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String tableId) {
if (Objects.isNull(number) || number < 0) { if (Objects.isNull(number) || number < 0) {
return Result.fail(CodeEnum.NUMBER); return Result.fail(CodeEnum.NUMBER);
} }
@@ -128,7 +138,16 @@ public class OrderService {
return Result.fail(CodeEnum.PRODUCTSKUERROR); return Result.fail(CodeEnum.PRODUCTSKUERROR);
} }
// 台桌点单
if ((StrUtil.isNotBlank(tableId))) {
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, tableId)
.in(TbShopTable::getStatus, "idle", "using", "pending"));
if (shopTable == null) {
return Result.fail("台桌不处于开台或空闲状态");
}
}
// List<TbProskuCon> proskuConList= tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(skuId,shopInfo.getId(),product.getId()); // List<TbProskuCon> proskuConList= tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(skuId,shopInfo.getId(),product.getId());
// if(Objects.nonNull(proskuConList)&&proskuConList.size()>0){ // if(Objects.nonNull(proskuConList)&&proskuConList.size()>0){
@@ -144,16 +163,6 @@ public class OrderService {
// } // }
// } // }
String exists = redisUtil.getMessage(RedisCst.ORDER_CART_EXISTS + cartId); String exists = redisUtil.getMessage(RedisCst.ORDER_CART_EXISTS + cartId);
// 首次加入购物车,并且拥有起售数,设置为起售数 // 首次加入购物车,并且拥有起售数,设置为起售数
@@ -196,7 +205,7 @@ public class OrderService {
//查询现有规格商品 //查询现有规格商品
if("edit".equals(type)&&!cart.getSkuId().equals(skuId.toString())){ if("edit".equals(type)&&!cart.getSkuId().equals(skuId.toString())){
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid); TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid, tableId);
if(Objects.nonNull(cashierCart)){ if(Objects.nonNull(cashierCart)){
cashierCart.setNumber(cashierCart.getNumber()+number); cashierCart.setNumber(cashierCart.getNumber()+number);
cashierCart.setTotalNumber(cashierCart.getNumber()+number); cashierCart.setTotalNumber(cashierCart.getNumber()+number);
@@ -212,6 +221,7 @@ public class OrderService {
cart.setNumber(number); cart.setNumber(number);
cart.setIsGift(isGift); cart.setIsGift(isGift);
cart.setIsPack(isPack); cart.setIsPack(isPack);
if (isPack.equals("false")){ if (isPack.equals("false")){
cart.setPackFee(BigDecimal.ZERO); cart.setPackFee(BigDecimal.ZERO);
}else { }else {
@@ -227,13 +237,9 @@ public class OrderService {
cart.setUuid(uuid); cart.setUuid(uuid);
cashierCartMapper.updateByPrimaryKeySelective(cart); cashierCartMapper.updateByPrimaryKeySelective(cart);
} }
} else { } else {
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create"); List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid); TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid, tableId);
if (number > 0) { if (number > 0) {
if (Objects.isNull(cashierCart)) { if (Objects.isNull(cashierCart)) {
cashierCart = new TbCashierCart(); cashierCart = new TbCashierCart();
@@ -269,6 +275,7 @@ public class OrderService {
cashierCart.setNumber(number); cashierCart.setNumber(number);
cashierCart.setUuid(uuid); cashierCart.setUuid(uuid);
cashierCart.setCategoryId(product.getCategoryId()); cashierCart.setCategoryId(product.getCategoryId());
cashierCart.setTableId(tableId);
list.add(cashierCart); list.add(cashierCart);
cashierCartMapper.insert(cashierCart); cashierCartMapper.insert(cashierCart);
cart=cashierCart; cart=cashierCart;
@@ -285,7 +292,7 @@ public class OrderService {
cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee())); cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
} }
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getNumber()).multiply(skuWithBLOBs.getSalePrice()).add(cashierCart.getPackFee())); cashierCart.setTotalAmount(new BigDecimal(cashierCart.getNumber()).multiply(skuWithBLOBs.getSalePrice()).add(cashierCart.getPackFee()));
cashierCartMapper.updateByPrimaryKeySelective(cashierCart); mpCashierCartMapper.updateById(cashierCart);
} }
} else { } else {
cashierCartMapper.updateStatus(cashierCart.getId(), "close"); cashierCartMapper.updateStatus(cashierCart.getId(), "close");
@@ -344,27 +351,55 @@ public class OrderService {
} }
} }
public Result queryCart(String masterId, String shopId) { public Result queryCart(String masterId, String shopId, String tableId) {
if (StringUtils.isEmpty(shopId)) { if (StringUtils.isEmpty(shopId)) {
return Result.fail(CodeEnum.SHOPINFONOEXIST); return Result.fail(CodeEnum.SHOPINFONOEXIST);
} }
String day = DateUtils.getDay(); String day = DateUtils.getDay();
List<TbCashierCart> list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
if (list.size() < 1){ LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId), "refund",day); .eq(TbCashierCart::getShopId, shopId);
if (list.size() > 0){
if (list.size() < 1) { // 普通点单
if (StrUtil.isBlank(tableId)) {
queryWrapper.eq(TbCashierCart::getMasterId, masterId);
queryWrapper.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "");
// 台桌点单
}else if (StrUtil.isNotBlank(tableId)) {
String finalMasterId = masterId;
queryWrapper.eq(TbCashierCart::getTableId, tableId)
.and(query -> {
query.eq(TbCashierCart::getMasterId, finalMasterId)
.or()
.isNull(TbCashierCart::getMasterId);
});
}
// List<TbCashierCart> list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper.eq(TbCashierCart::getStatus, "create"));
if (list.isEmpty()){
list = mpCashierCartMapper.selectList(queryWrapper.eq(TbCashierCart::getStatus, "refund"));
// list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId), "refund",day);
if (!list.isEmpty()){
if (list.isEmpty()) {
return Result.fail(CodeEnum.CARTJH); return Result.fail(CodeEnum.CARTJH);
} }
int orderId = 0; int orderId = 0;
String uuid = ""; String uuid = "";
ArrayList<Integer> ids = new ArrayList<>();
for (TbCashierCart cashierCart : list) { for (TbCashierCart cashierCart : list) {
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
orderId = Integer.valueOf(cashierCart.getOrderId()); orderId = Integer.parseInt(cashierCart.getOrderId());
break;
} }
cashierCart.setStatus("create");
ids.add(cashierCart.getId());
} }
cashierCartMapper.updateStatusByMaster(Integer.valueOf(shopId), masterId, "create", day, uuid); // mpCashierCartMapper.insertOrUpdate(list);
// cashierCartMapper.updateStatusByMaster(Integer.valueOf(shopId), masterId, "create", day, uuid);
mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.set(TbCashierCart::getStatus, "create")
.in(TbCashierCart::getId, ids));
if (orderId > 0) { if (orderId > 0) {
tbOrderInfoMapper.updateStatusById(orderId, "cancelled"); tbOrderInfoMapper.updateStatusById(orderId, "cancelled");
orderDetailMapper.updateStatusByOrderId(orderId, "cancelled"); orderDetailMapper.updateStatusByOrderId(orderId, "cancelled");
@@ -373,10 +408,12 @@ public class OrderService {
} }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("list", list); map.put("list", list);
map.put("masterId", masterId);
BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal packAmount = BigDecimal.ZERO; BigDecimal packAmount = BigDecimal.ZERO;
for (TbCashierCart cashierCart : list) { for (TbCashierCart cashierCart : list) {
if (StrUtil.isNotBlank(cashierCart.getMasterId())) {
masterId = cashierCart.getMasterId();
}
totalAmount = totalAmount.add(cashierCart.getTotalAmount()); totalAmount = totalAmount.add(cashierCart.getTotalAmount());
if (cashierCart.getIsPack().equals("true")) { if (cashierCart.getIsPack().equals("true")) {
packAmount = packAmount.add(cashierCart.getPackFee()); packAmount = packAmount.add(cashierCart.getPackFee());
@@ -395,6 +432,9 @@ public class OrderService {
} }
// TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId())); // TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId()));
} }
map.put("masterId", masterId);
QueryCartPo queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId); QueryCartPo queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
queryCartPo.setPackAmount(packAmount); queryCartPo.setPackAmount(packAmount);
queryCartPo.setTotalAmount(totalAmount); queryCartPo.setTotalAmount(totalAmount);
@@ -446,9 +486,32 @@ public class OrderService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result createOrder(OrderVo orderVo, String clientType, String token) { public Result createOrder(OrderVo orderVo, String clientType, String token) {
String day = DateUtils.getDay(); String day = DateUtils.getDay();
List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(orderVo.getMasterId(), orderVo.getShopId(), day, "create", orderVo.getUuid());
if (list.size() < 1) { LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
list = cashierCartMapper.selectAllCreateOrder(orderVo.getMasterId(), orderVo.getShopId(), day, "create", orderVo.getUuid()); .eq(TbCashierCart::getShopId, orderVo.getShopId())
.eq(TbCashierCart::getStatus, "create");
// 普通点单
if (StrUtil.isBlank(orderVo.getTableId())) {
queryWrapper.eq(TbCashierCart::getMasterId, orderVo.getMasterId())
.eq(TbCashierCart::getTradeDay, day);
queryWrapper.isNull(TbCashierCart::getTableId);
// 台桌点单
}else if (StrUtil.isNotBlank(orderVo.getTableId()) && orderVo.getVipUserId() == null) {
queryWrapper.eq(TbCashierCart::getTableId, orderVo.getTableId())
.and(query -> {
query.eq(TbCashierCart::getMasterId, orderVo.getMasterId())
.or()
.isNull(TbCashierCart::getMasterId);
});
}
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper);
// List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(orderVo.getMasterId(), orderVo.getShopId(), day, "create", orderVo.getUuid());
if (list.isEmpty()) {
list = mpCashierCartMapper.selectList(queryWrapper);
// list = cashierCartMapper.selectAllCreateOrder(orderVo.getMasterId(), orderVo.getShopId(), day, "create", orderVo.getUuid());
} }
if(ObjectUtil.isEmpty(list)||ObjectUtil.isNull(list)||list.size()<=0){ if(ObjectUtil.isEmpty(list)||ObjectUtil.isNull(list)||list.size()<=0){
@@ -502,7 +565,7 @@ public class OrderService {
String orderNo = generateOrderNumber(); String orderNo = generateOrderNumber();
TbToken tbToken = tokenMapper.selectByToken(token); TbToken tbToken = tokenMapper.selectByToken(token);
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId); TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
if (orderId > 0) { if (orderId > 0 && orderInfo != null) {
// if (!orderInfo.getStatus().equals("unpaid")){ // if (!orderInfo.getStatus().equals("unpaid")){
// return Result.fail(CodeEnum.ORDERCREATE); // return Result.fail(CodeEnum.ORDERCREATE);
// } // }
@@ -528,6 +591,9 @@ public class OrderService {
orderInfo.setMasterId(masterId); orderInfo.setMasterId(masterId);
orderInfo.setRemark(orderVo.getRemark()); orderInfo.setRemark(orderVo.getRemark());
orderInfo.setUserId(orderVo.getUserId()); orderInfo.setUserId(orderVo.getUserId());
if (StrUtil.isNotBlank(orderVo.getTableId())) {
orderInfo.setTableId(orderVo.getTableId());
}
if (Objects.nonNull(tbToken)){ if (Objects.nonNull(tbToken)){
orderInfo.setTokenId(tbToken.getId()); orderInfo.setTokenId(tbToken.getId());
} }
@@ -596,6 +662,13 @@ public class OrderService {
} }
if (flag) { if (flag) {
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId()); redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId());
// 代课下单
if (!StrUtil.isBlank(orderVo.getTableId())) {
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
producer.printMechine(String.valueOf(orderInfo.getId()));
}
} }
JSONObject object=new JSONObject(); JSONObject object=new JSONObject();
@@ -618,8 +691,6 @@ public class OrderService {
redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(orderInfo.getShopId().toString()),object.toString()); redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(orderInfo.getShopId().toString()),object.toString());
log.info("创建订单发送更新耗材消息订单id{}", orderInfo.getId()); log.info("创建订单发送更新耗材消息订单id{}", orderInfo.getId());
//修改耗材数据 //修改耗材数据
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
@@ -641,6 +712,16 @@ public class OrderService {
return Result.success(CodeEnum.SUCCESS, orderInfo); return Result.success(CodeEnum.SUCCESS, orderInfo);
} }
public synchronized void addGlobalCode(String day, String clientType, String shopId) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day);
if (StrUtil.isBlank(code)) {
redisUtil.saveMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "1");
}else {
redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + (Integer.parseInt(code) + 1));
}
redisUtil.execsSet("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, "1");
}
public synchronized String generateOrderCode(String day, String clientType, String shopId) { public synchronized String generateOrderCode(String day, String clientType, String shopId) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day)+""; String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day)+"";
// 使用顺序递增的计数器生成取餐码 // 使用顺序递增的计数器生成取餐码
@@ -735,11 +816,34 @@ public class OrderService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result cartStatus(Integer shopId, String masterId, String status, String userId, String uuid, String clientType) { public Result cartStatus(Integer shopId, String masterId, String status, String userId, String uuid,
String clientType, Integer vipUserId, String tableId) {
String newUuid = redisUtil.getMessage("CART:UUID:" + shopId + userId)+""; String newUuid = redisUtil.getMessage("CART:UUID:" + shopId + userId)+"";
String day = DateUtils.getDay(); String day = DateUtils.getDay();
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId);
// 普通点单
if (StrUtil.isBlank(tableId)) {
queryWrapper.eq(TbCashierCart::getMasterId, masterId);
queryWrapper.isNull(TbCashierCart::getTableId);
// 台桌点单
}else if (StrUtil.isNotBlank(tableId) && vipUserId == null) {
queryWrapper.eq(TbCashierCart::getTableId, tableId)
.eq(TbCashierCart::getMasterId, masterId);
// 会员点单
}else {
queryWrapper
.eq(TbCashierCart::getTableId, tableId)
.eq(TbCashierCart::getUserId, vipUserId);
}
if ("true".equals(status)) { if ("true".equals(status)) {
List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(masterId, shopId, day, "create", uuid); List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper);
// List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(masterId, shopId, day, "create", uuid);
if (list.size() < 1) { if (list.size() < 1) {
return Result.fail(CodeEnum.CREATEORDER); return Result.fail(CodeEnum.CREATEORDER);
} }
@@ -810,31 +914,45 @@ public class OrderService {
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
flag = false; flag = false;
} }
cashierCart.setUserId(vipUserId);
cashierCart.setOrderId(orderId + ""); cashierCart.setOrderId(orderId + "");
cashierCart.setUpdatedAt(System.currentTimeMillis()); cashierCart.setUpdatedAt(System.currentTimeMillis());
cashierCart.setPendingAt(System.currentTimeMillis()); cashierCart.setPendingAt(System.currentTimeMillis());
cashierCart.setStatus("refund"); cashierCart.setStatus("refund");
cashierCart.setUuid(newUuid); cashierCart.setUuid(newUuid);
cashierCartMapper.updateByPrimaryKeySelective(cashierCart); mpCashierCartMapper.updateById(cashierCart);
} }
if (flag) { if (flag) {
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + shopId + ":" + day + userId); redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + shopId + ":" + day + userId);
} }
} else {
List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(masterId, shopId, "", "refund", uuid); mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
if (list.size() < 1) { .eq(TbShopTable::getQrcode, tableId)
.set(TbShopTable::getStatus, TableStateEnum.PENDING.getState()));
} else {
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper
.eq(TbCashierCart::getStatus, "refund"));
// List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(masterId, shopId, "", "refund", uuid);
if (list.isEmpty()) {
return Result.fail(CodeEnum.CARTJH); return Result.fail(CodeEnum.CARTJH);
} }
int orderId = 0; int orderId = 0;
ArrayList<Integer> ids = new ArrayList<>();
for (TbCashierCart cashierCart : list) { for (TbCashierCart cashierCart : list) {
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
orderId = Integer.valueOf(cashierCart.getOrderId()); orderId = Integer.parseInt(cashierCart.getOrderId());
break;
} }
ids.add(cashierCart.getId());
// cashierCart.setStatus("create");
// }
} }
cashierCartMapper.updateStatusByMaster(shopId, masterId, "create", day, uuid); mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.set(TbCashierCart::getStatus, "create")
.in(TbCashierCart::getId, ids));
// cashierCartMapper.updateStatusByMaster(shopId, masterId, "create", day, uuid);
if (orderId > 0) { if (orderId > 0) {
tbOrderInfoMapper.updateStatusById(orderId, "cancelled"); tbOrderInfoMapper.updateStatusById(orderId, "cancelled");
orderDetailMapper.updateStatusByOrderId(orderId, "cancelled"); orderDetailMapper.updateStatusByOrderId(orderId, "cancelled");
@@ -881,10 +999,32 @@ public class OrderService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result clearCart(CartVo cartVo) { public Result clearCart(CartVo cartVo) {
String day = DateUtils.getDay(); String day = DateUtils.getDay();
List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(cartVo.getMasterId(), Integer.valueOf(cartVo.getShopId()), day, "create", cartVo.getUuid()); LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, cartVo.getShopId())
.eq(TbCashierCart::getTradeDay, day)
.eq(TbCashierCart::getStatus, "create");
// 普通点单
if (StrUtil.isBlank(cartVo.getTableId())) {
queryWrapper.eq(TbCashierCart::getMasterId, cartVo.getMasterId());
queryWrapper.isNull(TbCashierCart::getTableId);
// 台桌点单
}else if (StrUtil.isNotBlank(cartVo.getTableId()) ) {
queryWrapper.eq(TbCashierCart::getTableId, cartVo.getTableId())
.and(query -> {
query.eq(TbCashierCart::getMasterId, cartVo.getMasterId())
.or()
.isNull(TbCashierCart::getMasterId);
});
// 会员点单
}
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper);
// List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(cartVo.getMasterId(), Integer.valueOf(cartVo.getShopId()), day, "create", cartVo.getUuid());
int orderId = 0; int orderId = 0;
List<ProductSkuPo> productSkuPos=new ArrayList<>(); List<ProductSkuPo> productSkuPos = new ArrayList<>();
List<String> skuIds=new ArrayList<>(); List<String> skuIds = new ArrayList<>();
for (TbCashierCart cashierCart : list) { for (TbCashierCart cashierCart : list) {
// 数量减少, 返还库存 // 数量减少, 返还库存
String message = redisUtil.getMessage(RedisCst.ORDER_PRODUCT_NUM + cashierCart.getId()); String message = redisUtil.getMessage(RedisCst.ORDER_PRODUCT_NUM + cashierCart.getId());
@@ -1379,4 +1519,19 @@ public class OrderService {
JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam)); JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam));
return jsonObject; return jsonObject;
} }
public Object updateVip(UpdateVipDTO updateVipDTO) {
LambdaUpdateWrapper<TbCashierCart> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(TbCashierCart::getTableId, updateVipDTO.getTableId())
.eq(TbCashierCart::getShopId, updateVipDTO.getShopId())
.eq(TbCashierCart::getMasterId, updateVipDTO.getMasterId());
if (updateVipDTO.getType().equals(0)) {
queryWrapper.set(TbCashierCart::getUserId, null);
queryWrapper.eq(TbCashierCart::getUserId, updateVipDTO.getVipUserId());
}else {
queryWrapper.set(TbCashierCart::getUserId, updateVipDTO.getVipUserId());
}
return mpCashierCartMapper.update(null, queryWrapper);
}
} }

View File

@@ -1,8 +1,10 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
@@ -11,6 +13,8 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq; import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
import com.chaozhanggui.system.cashierservice.model.ScanPayReq; import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserFlowMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -118,6 +122,10 @@ public class PayService {
@Autowired @Autowired
TbPlussShopStaffMapper tbPlussShopStaffMapper; TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired
private MpShopUserMapper mpShopUserMapper;
@Autowired
private MpShopUserFlowMapper mpShopUserFlowMapper;
public static void main(String[] args) { public static void main(String[] args) {
@@ -710,6 +718,82 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
public Result vipPay(String orderId, String token, Integer vipUserId) {
if (ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM);
}
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST);
}
if (!"unpaid".equals(orderInfo.getStatus())) {
return Result.fail(CodeEnum.ORDERSTATUSERROR);
}
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
if (count < 1) {
return Result.fail(CodeEnum.PAYTYPENOEXIST);
}
// 扣减会员余额
TbShopUser shopUser = mpShopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
.eq(TbShopUser::getStatus, 1)
.eq(TbShopUser::getId, vipUserId));
if (shopUser == null) {
return Result.fail("用户不存在或已被禁用");
}
long flag = mpShopUserMapper.decrBalance(vipUserId, orderInfo.getOrderAmount());
if (flag < 1) {
return Result.fail("余额不足或扣除余额失败");
}
TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount(orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount());
userFlow.setShopUserId(shopUser.getId());
userFlow.setBizCode("vipCardCash");
userFlow.setBizName("代客下单会员余额支付");
userFlow.setCreateTime(DateUtil.date());
userFlow.setType("-");
mpShopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
//更新购物车状态
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
log.info("更新购物车:{}", cartCount);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token);
jsonObject.put("type", "create");
jsonObject.put("orderId", orderId);
producer.putOrderCollect(jsonObject.toJSONString());
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result cashPay(String orderId, String token,BigDecimal payAmount,BigDecimal discountAmount) { public Result cashPay(String orderId, String token,BigDecimal payAmount,BigDecimal discountAmount) {
if (ObjectUtil.isEmpty(orderId)) { if (ObjectUtil.isEmpty(orderId)) {
@@ -782,6 +866,10 @@ public class PayService {
mqData.put("type", "pc"); mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData); producer.sendStockSaleMsg(mqData);
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -856,6 +944,8 @@ public class PayService {
mqData.put("type", "pc"); mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData); producer.sendStockSaleMsg(mqData);
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -1156,6 +1246,7 @@ public class PayService {
productStockDetailMapper.insert(tbProductStockDetail); productStockDetailMapper.insert(tbProductStockDetail);
} }
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -1254,6 +1345,8 @@ public class PayService {
} }
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + shopId + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.fail(CodeEnum.FAIL); return Result.fail(CodeEnum.FAIL);
@@ -1310,6 +1403,7 @@ public class PayService {
} }
} }
return Result.success(CodeEnum.SUCCESS, tbQuickPay); return Result.success(CodeEnum.SUCCESS, tbQuickPay);
} }

View File

@@ -81,7 +81,7 @@ public class ProductService {
String day = DateUtils.getDay(); String day = DateUtils.getDay();
if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){ if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){
tbProductWithBLOBs.parallelStream().forEach(it->{ tbProductWithBLOBs.parallelStream().forEach(it->{
Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day); Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day, "");
it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount); it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount);
TbProductSpec tbProductSpec= tbProductSpecMapper.selectByPrimaryKey(it.getSpecId()); TbProductSpec tbProductSpec= tbProductSpecMapper.selectByPrimaryKey(it.getSpecId());
if(ObjectUtil.isEmpty(tbProductSpec)){ if(ObjectUtil.isEmpty(tbProductSpec)){
@@ -110,7 +110,7 @@ public class ProductService {
} }
public Result queryNewCommodityInfo(String shopId, String categoryId, String commdityName, int page, int pageSize, String masterId) { public Result queryNewCommodityInfo(String shopId, String categoryId, String commdityName, String tableId, int page, int pageSize, String masterId) {
List<TbProductWithBLOBs> tbProductWithBLOBs=null; List<TbProductWithBLOBs> tbProductWithBLOBs=null;
PageHelperUtil.startPage(page,pageSize); PageHelperUtil.startPage(page,pageSize);
if(ObjectUtil.isEmpty(categoryId)){ if(ObjectUtil.isEmpty(categoryId)){
@@ -126,7 +126,7 @@ public class ProductService {
String day = DateUtils.getDay(); String day = DateUtils.getDay();
if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){ if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){
tbProductWithBLOBs.parallelStream().forEach(it->{ tbProductWithBLOBs.parallelStream().forEach(it->{
Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day); Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day, tableId);
it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount); it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount);
TbProductSpec tbProductSpec= tbProductSpecMapper.selectByPrimaryKey(it.getSpecId()); TbProductSpec tbProductSpec= tbProductSpecMapper.selectByPrimaryKey(it.getSpecId());
if(ObjectUtil.isEmpty(tbProductSpec)){ if(ObjectUtil.isEmpty(tbProductSpec)){

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.vo.TbShopTableVO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.DateUtils;
@@ -53,8 +54,9 @@ public class ShopInfoService {
} }
PageHelperUtil.startPage(page, pageSize); PageHelperUtil.startPage(page, pageSize);
List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status); // List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status);
PageInfo pageInfo=new PageInfo(shopTables); List<TbShopTableVO> tbShopTableVOList = tbShopTableMapper.selectTableInfo(shopId, areaId, status);
PageInfo pageInfo=new PageInfo(tbShopTableVOList);
return Result.success(CodeEnum.SUCCESS,pageInfo); return Result.success(CodeEnum.SUCCESS,pageInfo);
} }

View File

@@ -20,4 +20,5 @@ public class RedisCst {
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:";
public static final String ORDER_PRINT = "ORDER_PRINT:";
} }

View File

@@ -57,5 +57,8 @@ wx:
warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0 warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0
mybatis-plus:
global-config:
db-config:
id-type: auto

View File

@@ -58,6 +58,9 @@
<if test="uuid != null"> <if test="uuid != null">
and uuid = #{uuid} and uuid = #{uuid}
</if> </if>
<if test="tableId != null and tableId != ''">
and table_id = #{tableId}
</if>
</select> </select>
<select id="selectDetailByQrcode" resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart"> <select id="selectDetailByQrcode" resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">

View File

@@ -47,6 +47,7 @@
<result column="master_id" jdbcType="VARCHAR" property="masterId"/> <result column="master_id" jdbcType="VARCHAR" property="masterId"/>
<result column="table_name" jdbcType="VARCHAR" property="tableName"/> <result column="table_name" jdbcType="VARCHAR" property="tableName"/>
<result column="out_number" jdbcType="VARCHAR" property="outNumber"/> <result column="out_number" jdbcType="VARCHAR" property="outNumber"/>
<result column="use_type" jdbcType="VARCHAR" property="useType"/>
</resultMap> </resultMap>
@@ -56,7 +57,7 @@
discount_amount, table_id, small_change, send_type, order_type, product_type, status, 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, 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, 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`,out_number updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name`,out_number, use_type
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select select

View File

@@ -962,6 +962,7 @@
AND product_id = #{productId} AND product_id = #{productId}
AND `status` = 'create' AND `status` = 'create'
and master_id = #{masterId} and master_id = #{masterId}
and table_id = #{tableId}
and trade_day = #{day} and trade_day = #{day}
group by shop_id,product_id group by shop_id,product_id
</select> </select>

View File

@@ -350,7 +350,7 @@
<if test="spec != null and spec !=''"> <if test="spec != null and spec !=''">
and spec_snap = #{spec} and spec_snap = #{spec}
</if> </if>
order by id desc limit 1
</select> </select>
<select id="selectByProduct" <select id="selectByProduct"
resultType="com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs"> resultType="com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs">

View File

@@ -228,4 +228,20 @@
</select> </select>
<select id="selectTableInfo" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbShopTableVO">
select a.*, b.user_id, c.master_id, c.id as orderId, c.order_no as orderNo, c.amount as orderAmount from tb_shop_table a
left join tb_order_info b on a.qrcode=b.table_id and (b.`status`='unpaid' or b.`status`='paying') and b.user_id is not null
left join tb_order_info c on a.qrcode=c.table_id and (c.`status`='unpaid' or c.`status`='paying') and c.master_id is not null
where a.shop_id=#{shopId}
<if test="areaId != null and areaId !=''">
and a.area_id = #{areaId}
</if>
<if test="status != null and status !=''">
and a.status = #{status}
</if>
GROUP BY a.id
order by a.`sort` asc
</select>
</mapper> </mapper>