1.代课下单支持赠送

This commit is contained in:
2024-08-13 09:02:44 +08:00
parent 66ae922dc4
commit 7f1c028fed
4 changed files with 13 additions and 9 deletions

View File

@@ -5,19 +5,17 @@ import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shoptable.AddCartDTO; import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO; import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO; import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.service.product.TbProductService; import cn.ysk.cashier.service.product.TbProductService;
import cn.ysk.cashier.service.shop.TbShopTableService; import cn.ysk.cashier.service.shop.TbShopTableService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator; import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import javax.xml.bind.ValidationException;
@RestController @RestController
@RequestMapping("/api/place") @RequestMapping("/api/place")
@@ -51,9 +49,8 @@ public class TbPlaceController {
@PostMapping("/addCart") @PostMapping("/addCart")
@Log("代客下单:#addCartDTO.tableId") @Log("代客下单:#addCartDTO.tableId")
@ApiOperation("代客下单/shop/table") @ApiOperation("代客下单/shop/table")
public ResponseEntity<Object> addCartForUser(@Valid @RequestBody AddCartDTO addCartDTO) { public ResponseEntity<TbCashierCart> addCartForUser(@Valid @RequestBody AddCartDTO addCartDTO) {
tbShopTableService.addCartForUser(addCartDTO); return ResponseEntity.ok(tbShopTableService.addCartForUser(addCartDTO));
return new ResponseEntity<>(HttpStatus.OK);
} }
@AnonymousAccess @AnonymousAccess
@DeleteMapping("/removeCart") @DeleteMapping("/removeCart")

View File

@@ -19,4 +19,5 @@ public class AddCartDTO {
@Min(0) @Min(0)
private Integer num; private Integer num;
private boolean isPack; private boolean isPack;
private boolean isGift;
} }

View File

@@ -203,7 +203,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
@Override @Override
public void addCartForUser(AddCartDTO addCartDTO) { public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId()); TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId());
TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId()); TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId());
@@ -248,6 +248,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee())); tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
} }
tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift()));
if (addCartDTO.isGift()) {
tbCashierCart.setTotalAmount(BigDecimal.ZERO);
}
tbCashierCart.setTotalNumber(addCartDTO.getNum()); tbCashierCart.setTotalNumber(addCartDTO.getNum());
tbCashierCart.setNumber(addCartDTO.getNum()); tbCashierCart.setNumber(addCartDTO.getNum());
tbCashierCart.setCategoryId(product.getCategoryId()); tbCashierCart.setCategoryId(product.getCategoryId());
@@ -258,12 +262,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 数量0删除 // 数量0删除
if (tbCashierCart.getNumber() == 0) { if (tbCashierCart.getNumber() == 0) {
cashierCartRepository.deleteById(tbCashierCart.getId()); cashierCartRepository.deleteById(tbCashierCart.getId());
return; return null;
} }
tbCashierCart.setUpdatedAt(DateUtil.current()); tbCashierCart.setUpdatedAt(DateUtil.current());
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice())); tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
cashierCartRepository.save(tbCashierCart); cashierCartRepository.save(tbCashierCart);
} }
return tbCashierCart;
} }
@Override @Override

View File

@@ -98,7 +98,7 @@ public interface TbShopTableService {
*/ */
void download(List<TbShopTableDto> all, HttpServletResponse response) throws IOException; void download(List<TbShopTableDto> all, HttpServletResponse response) throws IOException;
void addCartForUser(AddCartDTO addCartDTO); TbCashierCart addCartForUser(AddCartDTO addCartDTO);
void removeCart(RemoveCartDTO removeCartDTO); void removeCart(RemoveCartDTO removeCartDTO);