1.代客下单规格修改接口

This commit is contained in:
SongZhang 2024-08-13 09:48:03 +08:00
parent 7f1c028fed
commit fd5b79d6ec
4 changed files with 85 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.service.product.TbProductService;
import cn.ysk.cashier.service.shop.TbShopTableService;
@ -45,6 +46,7 @@ public class TbPlaceController {
this.tbProductService = tbProductService;
this.validator = validator;
}
@AnonymousAccess
@PostMapping("/addCart")
@Log("代客下单:#addCartDTO.tableId")
@ -52,6 +54,16 @@ public class TbPlaceController {
public ResponseEntity<TbCashierCart> addCartForUser(@Valid @RequestBody AddCartDTO addCartDTO) {
return ResponseEntity.ok(tbShopTableService.addCartForUser(addCartDTO));
}
@AnonymousAccess
@PutMapping("/updateCart")
@Log("代客下单")
@ApiOperation("代客下单/shop/table")
public ResponseEntity<TbCashierCart> updateCart(@Valid @RequestBody UpdateCartDTO updateCartDTO) {
return ResponseEntity.ok(tbShopTableService.updateCart(updateCartDTO));
}
@AnonymousAccess
@DeleteMapping("/removeCart")
@Log("代客下单 删除购物车商品")

View File

@ -0,0 +1,22 @@
package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Data
public class UpdateCartDTO {
@NotNull
private Integer cartId;
@NotNull
private Integer skuId;
@NotNull
private Integer productId;
@NotNull
private Integer shopId;
@NotNull
@Min(0)
private Integer num;
}

View File

@ -20,6 +20,7 @@ import cn.hutool.core.date.DateUtil;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
import cn.ysk.cashier.mybatis.mapper.TbProductMapper;
@ -201,6 +202,51 @@ public class TbShopTableServiceImpl implements TbShopTableService {
FileUtil.downloadExcel(list, response);
}
@Override
public TbCashierCart updateCart(UpdateCartDTO updateCartDTO) {
TbCashierCart tbCashierCart = cashierCartMapper.selectById(updateCartDTO.getCartId());
if (tbCashierCart == null) {
throw new BadRequestException("购物车商品不存在");
}
if (updateCartDTO.getNum() == 0) {
cashierCartRepository.deleteById(updateCartDTO.getCartId());
return null;
}
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getSkuId());
TbProduct product = productMapper.selectByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getProductId());
if (product == null || productSku == null) {
throw new BadRequestException("商品不存在或已下架, id: " + updateCartDTO.getSkuId());
}
tbCashierCart.setCoverImg(product.getCoverImg());
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setIsSku(product.getTypeEnum());
tbCashierCart.setName(product.getName());
tbCashierCart.setProductId(String.valueOf(product.getId()));
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setSkuId(productSku.getId().toString());
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setTotalAmount(new BigDecimal(updateCartDTO.getNum()).multiply(productSku.getSalePrice()));
if (tbCashierCart.getIsPack().equals("false")){
tbCashierCart.setPackFee(BigDecimal.ZERO);
}else {
tbCashierCart.setPackFee(new BigDecimal(updateCartDTO.getNum()).multiply(product.getPackFee()));
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
}
if (tbCashierCart.getIsGift().equals("true")) {
tbCashierCart.setTotalAmount(BigDecimal.ZERO);
}
tbCashierCart.setTotalNumber(updateCartDTO.getNum());
tbCashierCart.setNumber(updateCartDTO.getNum());
tbCashierCart.setCategoryId(product.getCategoryId());
cashierCartRepository.save(tbCashierCart);
return tbCashierCart;
}
@Override
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
@ -237,8 +283,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setShopId(String.valueOf(addCartDTO.getShopId()));
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setIsPack(String.valueOf(false));
tbCashierCart.setIsGift(String.valueOf(false));
tbCashierCart.setIsPack(String.valueOf(addCartDTO.isPack()));
tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift()));
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
if (!addCartDTO.isPack()){
@ -248,7 +294,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
}
tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift()));
if (addCartDTO.isGift()) {
tbCashierCart.setTotalAmount(BigDecimal.ZERO);
}

View File

@ -18,6 +18,7 @@ package cn.ysk.cashier.service.shop;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.UpdateCartDTO;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.dto.shop.TbShopTableDto;
@ -105,4 +106,6 @@ public interface TbShopTableService {
void clearCart(ClearCartDTO clearCartDTO);
Page<TbCashierCart> getCart(Long tableId, Integer page, Integer size, Integer shopId);
TbCashierCart updateCart(UpdateCartDTO updateCartDTO);
}