1.代客下单 新增后付款下单
This commit is contained in:
parent
830271a838
commit
376af15266
|
|
@ -2,11 +2,15 @@ package cn.ysk.cashier.controller.product;
|
|||
|
||||
import cn.ysk.cashier.annotation.AnonymousAccess;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.shoptable.*;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.service.product.TbProductService;
|
||||
import cn.ysk.cashier.service.shop.TbShopTableService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.Validator;
|
||||
|
|
@ -14,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/place")
|
||||
|
|
@ -38,10 +43,11 @@ public class TbPlaceController {
|
|||
return new ResponseEntity<>(tbProductService.activateProduct(page, size, categoryId, shopId, productId),HttpStatus.OK);
|
||||
}
|
||||
|
||||
public TbPlaceController(TbShopTableService tbShopTableService, TbProductService tbProductService, Validator validator) {
|
||||
public TbPlaceController(TbShopTableService tbShopTableService, TbProductService tbProductService, Validator validator, RabbitTemplate rabbitTemplate) {
|
||||
this.tbShopTableService = tbShopTableService;
|
||||
this.tbProductService = tbProductService;
|
||||
this.validator = validator;
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
|
|
@ -179,6 +185,7 @@ public class TbPlaceController {
|
|||
) {
|
||||
return ResponseEntity.ok(tbShopTableService.pay(payDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PutMapping("/updateVip")
|
||||
@Log("代客下单 查询购物车")
|
||||
|
|
@ -189,4 +196,17 @@ public class TbPlaceController {
|
|||
return ResponseEntity.ok(tbShopTableService.updateVip(updateVipDTO));
|
||||
}
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
@AnonymousAccess
|
||||
@GetMapping("/test")
|
||||
public void test() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", "2980");
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, jsonObject.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, "2980", new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,6 @@ public class CreateOrderDTO {
|
|||
@NotEmpty
|
||||
private Long tableId;
|
||||
private String note;
|
||||
private boolean postPay;
|
||||
private boolean print;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.enums;
|
||||
|
||||
public enum TableStateEnum {
|
||||
IDLE("idle"),
|
||||
CLOSED("closed"), PAYING("paying");
|
||||
private String state = "closed";
|
||||
|
||||
TableStateEnum(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface MpShopTableMapper extends BaseMapper<TbShopTable> {
|
||||
}
|
||||
|
|
@ -226,6 +226,8 @@ public class TbOrderInfo implements Serializable {
|
|||
@Column(name = "`is_use_coupon`")
|
||||
@ApiModelProperty(value = "是否使用优惠券")
|
||||
private String isUseCoupon;
|
||||
@Column(name = "`use_type`")
|
||||
private String useType;
|
||||
public void copy(TbOrderInfo source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||
import cn.ysk.cashier.cons.RedisConstant;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.shoptable.*;
|
||||
import cn.ysk.cashier.enums.ShopWxMsgTypeEnum;
|
||||
import cn.ysk.cashier.enums.TableStateEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
|
|
@ -101,11 +103,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final WxAccountUtil wxAccountUtil;
|
||||
private final WxMsgUtils wxMsgUtils;
|
||||
private final TbShopPayTypeRepository payTypeRepository;
|
||||
private final MpShopTableMapper mpShopTableMapper;
|
||||
|
||||
/**
|
||||
* 桌码前缀
|
||||
*/
|
||||
private final String QRCODE = "https://kysh.sxczgkj.cn/codeplate?code=";
|
||||
private final RabbitMsgUtils rabbitMsgUtils;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) {
|
||||
|
|
@ -276,8 +280,26 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
return tbCashierCart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 台桌状态校验
|
||||
* @param tableId 桌码
|
||||
* @return z
|
||||
*/
|
||||
private TbShopTable checkTableIsOpen(String tableId) {
|
||||
TbShopTable shopTable = tbShopTableRepository.findByQrcode(tableId);
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("桌码不存在,桌码" + tableId);
|
||||
}
|
||||
if (!shopTable.getStatus().equals("opening") && !shopTable.getStatus().equals("idle")) {
|
||||
throw new BadRequestException("当前台桌非开台状态");
|
||||
}
|
||||
return shopTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
|
||||
checkTableIsOpen(addCartDTO.getTableId());
|
||||
|
||||
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId());
|
||||
TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId());
|
||||
|
||||
|
|
@ -291,11 +313,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException("商品库存不足");
|
||||
}
|
||||
|
||||
TbShopTable shopTable = tbShopTableRepository.findByQrcode(addCartDTO.getTableId());
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("桌码不存在,桌码" + addCartDTO.getTableId());
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
||||
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
||||
|
|
@ -774,6 +791,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderInfo.setTableId(String.valueOf(createOrderDTO.getTableId()));
|
||||
orderInfo.setSendType("table");
|
||||
orderInfo.setOrderType("cash");
|
||||
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
||||
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
||||
orderInfo.setRefundAble(1);
|
||||
orderInfo.setTradeDay(day);
|
||||
|
|
@ -784,7 +802,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// 添加订单详细数据
|
||||
orderId = orderInfo.getId();
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
|
|
@ -816,6 +833,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
// 推送耗材信息
|
||||
pushConsMsg(orderInfo, cashierCarts);
|
||||
|
||||
// 后付款订单,修改台桌状态并打票
|
||||
if (createOrderDTO.isPostPay()) {
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.set(TbShopTable::getStatus, "opening"));
|
||||
|
||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
||||
}
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
|
|
@ -947,6 +974,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
return new BadRequestException("此订单不处于未支付状态");
|
||||
}
|
||||
|
||||
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.PAYING.getState()));
|
||||
// int count = shopInfoRepository.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
|
||||
// if (count < 1) {
|
||||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
|
|
@ -977,13 +1008,21 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, jsonObject.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
// 打印消息
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, payDTO.getOrderId().toString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
if (StrUtil.isBlank(orderInfo.getUseType()) || orderInfo.getUseType().equals("afterPay")) {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, payDTO.getOrderId().toString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
// 发送库存记录mq消息
|
||||
JSONObject mqData = new JSONObject();
|
||||
mqData.put("orderId", payDTO.getOrderId());
|
||||
mqData.put("type", "pc");
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
// 修改台桌状态
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集");
|
||||
}
|
||||
|
||||
public void printTicket(String content){
|
||||
public void printTicket(String orderId){
|
||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, content, correlationId);
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, orderId, correlationId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue