diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 2b543b9e..cb0749ce 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -167,9 +167,15 @@ - pro + pre - pro + pre + + + + prod + + prod diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/TableConstant.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/TableConstant.java index ac2e0605..1244125a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/TableConstant.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/TableConstant.java @@ -57,12 +57,17 @@ public interface TableConstant { @Getter public enum Status { REFUNDING("refunding"), REFUND("refund"), CLOSED("closed"), CREATE("create"), - UNPAID("unpaid"), PAYING("paying"), RETURN("return"); + UNPAID("unpaid"), PAYING("paying"), RETURN("return"), FINAL("final"); private final String value; Status(String value) { this.value = value; } + + public boolean equalsVals(String value) { + return this.value.equals(value); + } + } @Getter diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfo.java index e2231b25..bf2072af 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfo.java @@ -61,6 +61,10 @@ public class TbConsInfo implements Serializable { @ApiModelProperty(value = "单位换算") private BigDecimal conUnitTwoConvert; + @Column(name = "`default_unit`") + @ApiModelProperty(value = "默认入库单位") + private String defaultUnit; + @Column(name = "`laster_in_stock`") @ApiModelProperty(value = "最近一次入库量") private BigDecimal lasterInStock; @@ -102,9 +106,6 @@ public class TbConsInfo implements Serializable { @ApiModelProperty(value = "是否检测库存") private String isCheck; - @Transient - private List> product; - public void copy(TbConsInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfoV2.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfoV2.java index 111aeb04..7874d061 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfoV2.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsInfoV2.java @@ -63,6 +63,10 @@ public class TbConsInfoV2 implements Serializable { @ApiModelProperty(value = "单位换算") private BigDecimal conUnitTwoConvert; + @Column(name = "`default_unit`") + @ApiModelProperty(value = "默认入库单位") + private String defaultUnit; + @Column(name = "`laster_in_stock`") @ApiModelProperty(value = "最近一次入库量") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConsInfoDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConsInfoDto.java index a4b0bf17..e536c8ee 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConsInfoDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConsInfoDto.java @@ -39,6 +39,7 @@ public class TbConsInfoDto implements Serializable { private String conUnitTwo; private BigDecimal conUnitTwoConvert; + private String defaultUnit; /** 最近一次入库量 */ private BigDecimal lasterInStock; @@ -71,5 +72,4 @@ public class TbConsInfoDto implements Serializable { private String isCheck; - private List> product; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java index 3b7a1451..ab6a429d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java @@ -231,10 +231,18 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { } BigDecimal changeStock = conInfos.getStockNumber(); //副单位的实际修改值 - if (StringUtils.isNotBlank(conInfos.getUnit()) && conInfos.getUnit().equals(info.getConUnitTwo())) { + if(StringUtils.isNotBlank(conInfos.getUnit())){ + info.setDefaultUnit(conInfos.getUnit()); + if(conInfos.getUnit().equals(info.getConUnitTwo())){ + changeStock = conInfos.getStockNumber().multiply(info.getConUnitTwoConvert()).setScale(2, BigDecimal.ROUND_HALF_UP); + } + }else if(info.getConUnitTwo().equals(info.getDefaultUnit())) { + info.setDefaultUnit(info.getConUnitTwo()); changeStock = conInfos.getStockNumber().multiply(info.getConUnitTwoConvert()).setScale(2, BigDecimal.ROUND_HALF_UP); } + + TbConsSuppFlow suppFlow = new TbConsSuppFlow(); TbConsInfoFlow flow = new TbConsInfoFlow(); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopCouponController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopCouponController.java index bae5fed1..9184405f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopCouponController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopCouponController.java @@ -90,5 +90,11 @@ public class TbShopCouponController { tbShopCouponService.deleteReceive(ids); return new ResponseEntity<>(HttpStatus.OK); } + + @GetMapping("activateByOrderId") + @ApiOperation("根据订单id获取可用优惠券信息") + public ResponseEntity activateByOrderIds(@RequestParam Integer shopId, @RequestParam Integer orderId, @RequestParam(required = false) Integer memberId) { + return ResponseEntity.ok(tbShopCouponService.getActivateByOrderIds(shopId, orderId, memberId)); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index 0103d389..59ec269f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -175,8 +175,14 @@ public class TbPlaceController { JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-" + token))); String userName = userInfo.getString("userName"); String shopId = userInfo.getString("shopId"); - TbPlussShopStaff shopStaff = staffRepository.queryByAccount(userName, shopId); - TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.lambdaQuery().eq(TbMerchantAccount::getAccount, shopStaff.getAccount())); + TbPlussShopStaff shopStaff; + if (userName.contains("@")) { + shopStaff = staffRepository.queryMasterAccount(shopId); + }else { + shopStaff = staffRepository.queryByAccount(userName, shopId); + } + TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.lambdaQuery() + .eq(TbMerchantAccount::getAccount, shopStaff.getAccount())); Integer accountId = merchantAccount.getId(); Integer staffId = shopStaff.getId(); List onlineUserList = tbTokenRepository.findListByAccountIdAndStaffId(accountId, staffId); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java index efd3df02..7b814e1e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java @@ -26,7 +26,6 @@ public class SummaryController { //营业板块 上 @PostMapping("/trade") - @AnonymousPostMapping private Object shopSummaryDate(@RequestBody BaseQueryDto param) { return summaryService.trade(param); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigDto.java deleted file mode 100644 index b555cae6..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigDto.java +++ /dev/null @@ -1,37 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import java.io.Serializable; - -/** -* @website https://eladmin.vip -* @description / -* @author admin -* @date 2023-10-31 -**/ -@Data -public class BotButtonConfigDto implements Serializable { - - private Integer id; - - /** 按钮名称 */ - private String buttonName; - - /** 按钮值 */ - private String buttonValue; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigQueryCriteria.java deleted file mode 100644 index d789fd09..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotButtonConfigQueryCriteria.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import cn.ysk.cashier.annotation.Query; - -/** -* @website https://eladmin.vip -* @author admin -* @date 2023-10-31 -**/ -@Data -public class BotButtonConfigQueryCriteria{ - - /** 精确 */ - @Query - private String buttonName; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigDto.java deleted file mode 100644 index 1426d65d..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigDto.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import java.io.Serializable; - -/** -* @website https://eladmin.vip -* @description / -* @author admin -* @date 2023-10-31 -**/ -@Data -public class BotConfigDto implements Serializable { - - private Integer id; - - /** 元素键值 */ - private String configKey; - - /** 元素值 */ - private String configValue; - - /** 描述 */ - private String remark; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigQueryCriteria.java deleted file mode 100644 index ce14acb3..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotConfigQueryCriteria.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import cn.ysk.cashier.annotation.Query; - -/** -* @website https://eladmin.vip -* @author admin -* @date 2023-10-31 -**/ -@Data -public class BotConfigQueryCriteria{ - - /** 精确 */ - @Query - private String configKey; - - /** 精确 */ - @Query - private String configValue; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserDto.java deleted file mode 100644 index 93ee777f..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserDto.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import java.sql.Timestamp; -import java.math.BigDecimal; -import java.io.Serializable; - -/** -* @website https://eladmin.vip -* @description / -* @author admin -* @date 2023-10-30 -**/ -@Data -public class BotUserDto implements Serializable { - - private Integer id; - - private Integer fatherId; - - /** 父级电报号 */ - private String fatherTelegramId; - - /** 电报号 */ - private String userTelegramId; - - /** 用户名称 */ - private String userName; - - /** 组电报号 */ - private String groupTelegramId; - - /** 用户代码 */ - private String userCode; - - private String userPayPass; - - private String bombStatus; - - /** 用户状态 */ - private String botStatus; - - /** 总充值 */ - private BigDecimal usdtRechargeTotal; - - /** 总提现 */ - private BigDecimal usdtWithdrawTotal; - - /** 总资金 */ - private BigDecimal balance; - - /** 冻结资金 */ - private BigDecimal freezeBalance; - - /** 版本号 */ - private Integer version; - - /** 创建时间 */ - private Timestamp createTime; - - /** 更新时间 */ - private Timestamp updateTime; - - /** 语言 */ - private String userLanguage; - - /** 质押资金 */ - private BigDecimal chipBalance; - - /** 绑定时间 */ - private Timestamp fatherBindTime; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowDto.java deleted file mode 100644 index cc5a0e83..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowDto.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import java.sql.Timestamp; -import java.math.BigDecimal; -import java.io.Serializable; - -/** -* @website https://eladmin.vip -* @description / -* @author admin -* @date 2023-10-30 -**/ -@Data -public class BotUserFlowDto implements Serializable { - - private Integer id; - - /** 电报号 */ - private String userTelegramId; - - /** 用户名称 */ - private String userName; - - /** 业务代码 */ - private String bizCode; - - /** 变动金额 */ - private BigDecimal amount; - - /** 变动前金额 */ - private BigDecimal oldBalance; - - /** 变动后金额 */ - private BigDecimal newBalance; - - /** 创建时间 */ - private Timestamp createTime; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowQueryCriteria.java deleted file mode 100644 index d629ccf6..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserFlowQueryCriteria.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import cn.ysk.cashier.annotation.Query; - -/** -* @website https://eladmin.vip -* @author admin -* @date 2023-10-30 -**/ -@Data -public class BotUserFlowQueryCriteria{ - - /** 精确 */ - @Query - private String userTelegramId; - - /** 精确 */ - @Query - private String userName; - - /** 精确 */ - @Query - private String bizCode; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserQueryCriteria.java deleted file mode 100644 index e174c66c..00000000 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BotUserQueryCriteria.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package cn.ysk.cashier.dto; - -import lombok.Data; -import cn.ysk.cashier.annotation.Query; - -/** -* @website https://eladmin.vip -* @author admin -* @date 2023-10-30 -**/ -@Data -public class BotUserQueryCriteria{ - - /** 精确 */ - @Query - private String fatherTelegramId; - - /** 精确 */ - @Query - private String userTelegramId; - - /** 精确 */ - @Query - private String userName; - - /** 精确 */ - @Query - private String userCode; - - /** 精确 */ - @Query - private String botStatus; -} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCartInfoDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCartInfoDTO.java new file mode 100644 index 00000000..ad5ab1ed --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCartInfoDTO.java @@ -0,0 +1,19 @@ +package cn.ysk.cashier.dto.order; + +import cn.ysk.cashier.pojo.order.TbCashierCart; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Data +public class OrderCartInfoDTO { + private BigDecimal totalAmount = BigDecimal.ZERO; + private BigDecimal newAddTotalAmount = BigDecimal.ZERO; + private List newCashierCarts = new ArrayList<>(); + private List cashierCarts = new ArrayList<>(); + private List cashierCartIds = new ArrayList<>(); + private Integer orderId; + private TbCashierCart seatCart; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCouponInfoDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCouponInfoDTO.java new file mode 100644 index 00000000..e7895609 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderCouponInfoDTO.java @@ -0,0 +1,20 @@ +package cn.ysk.cashier.dto.order; + +import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord; +import cn.ysk.cashier.pojo.shop.TbShopUser; +import cn.ysk.cashier.vo.TbUserCouponVo; +import lombok.Data; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +@Data +public class OrderCouponInfoDTO { + private TbShopUser shopUser; + private List outRecordList = new ArrayList<>(); + // 满减优惠券 + private HashMap fullReductionCouponMap = new HashMap<>(); + // 商品优惠券 + private HashMap productCouponMap = new HashMap<>(); +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderPriceDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderPriceDTO.java new file mode 100644 index 00000000..b7b4249a --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/OrderPriceDTO.java @@ -0,0 +1,20 @@ +package cn.ysk.cashier.dto.order; + +import cn.ysk.cashier.pojo.order.TbOrderDetail; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Data +public class OrderPriceDTO { + private BigDecimal originAmount = BigDecimal.ZERO; + private BigDecimal totalAmount = BigDecimal.ZERO; + private BigDecimal packAmount = BigDecimal.ZERO; + private boolean hasNewInfo = false; + private List newOrderDetailList = new ArrayList<>(); + private List removeOrderDetailList = new ArrayList<>(); + private List removeOrderDetailIds = new ArrayList<>(); + private List orderDetailList = new ArrayList<>(); +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/UserCouponInfoDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/UserCouponInfoDTO.java new file mode 100644 index 00000000..0266aeea --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/order/UserCouponInfoDTO.java @@ -0,0 +1,12 @@ +package cn.ysk.cashier.dto.order; + +import lombok.Data; + +import javax.validation.constraints.Min; + +@Data +public class UserCouponInfoDTO { + private Integer userCouponId; + @Min(1) + private Integer num; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java index 73dfde96..558fd8b8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java @@ -1,7 +1,11 @@ package cn.ysk.cashier.dto.shoptable; +import cn.ysk.cashier.dto.order.UserCouponInfoDTO; import lombok.Data; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.ArrayList; @@ -19,9 +23,11 @@ public class CreateOrderDTO { private Integer orderId; @NotEmpty private String useType; - private String vipUserId; + private Integer vipUserId; // 使用的优惠券 - private List userCouponIds = new ArrayList<>(); + @Valid + private List userCouponInfos = new ArrayList<>(); // 使用的积分抵扣数量 - private Integer pointsNum ; + private Integer pointsNum; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/PayDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/PayDTO.java index aafea9f8..7402fc5a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/PayDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/PayDTO.java @@ -1,11 +1,15 @@ package cn.ysk.cashier.dto.shoptable; +import cn.ysk.cashier.dto.order.UserCouponInfoDTO; import lombok.Data; +import javax.validation.Valid; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; @Data public class PayDTO { @@ -20,6 +24,11 @@ public class PayDTO { private Double discount; private Integer vipUserId; private String code; - private String token; + // 使用的优惠券 + @Valid + private List userCouponInfos = new ArrayList<>(); + // 使用的积分抵扣数量 + private Integer pointsNum; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/UpdateVipDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/UpdateVipDTO.java index 693c2c76..ba1a6f0b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/UpdateVipDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/UpdateVipDTO.java @@ -13,7 +13,7 @@ public class UpdateVipDTO { private String tableId; @NotNull private String masterId; - + private Integer orderId; private Integer vipUserId; @NotNull @Range(min = 0, max = 1) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java index 4401388e..7a384e26 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import cn.ysk.cashier.mybatis.entity.TbActivateInRecord; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; @@ -17,7 +18,9 @@ import java.util.List; public interface TbActivateInRecordMapper extends BaseMapper { @Select("SELECT" + - " inRecord.coupon_id as id," + + " inRecord.id as id," + + " inRecord.full_amount as fullAmount," + + " inRecord.discount_amount as discountAmount," + " inRecord.coupon_id as couponId," + " pro.id as proId," + " CASE" + @@ -34,14 +37,19 @@ public interface TbActivateInRecordMapper extends BaseMapper " inRecord.vip_user_id = #{vipUserId}" + " and inRecord.shop_id = #{shopId}" + " and inRecord.over_num != 0" + - " and inRecord.use_start_time < now()" + - " and inRecord.use_end_time > now()" + + " and inRecord.use_start_time < now()" + + " and inRecord.use_end_time > now()" + " order by inRecord.use_end_time asc") List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); - @Select("update tb_activate_in_record" + + @Update("update tb_activate_in_record" + " set over_num = #{overNum}" + " where id = #{id}") int updateOverNum(@Param("id") Integer id, @Param("overNum") Integer overNum); + + @Update("update tb_activate_in_record" + + " set over_num = over_num-#{overNum}" + + " where id = #{id} and over_num-#{overNum} >= 0") + int decrOverNum(@Param("id") Integer id, @Param("overNum") Integer decrOverNum); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateOutRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateOutRecordMapper.java index ba81e80a..59ff3064 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateOutRecordMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateOutRecordMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; /** * 活动赠送商品使用记录表(TbActivateOutRecord)表数据库访问层 @@ -13,7 +14,7 @@ import org.apache.ibatis.annotations.Select; */ public interface TbActivateOutRecordMapper extends BaseMapper { - @Select("update tb_activate_out_record" + + @Update("update tb_activate_out_record" + " set ref_num = ref_num + #{refNum}" + " where id = #{id}") int updateRefNum(@Param("id") Integer id, @Param("refNum") Integer refNum); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java index 3df120e9..ded16692 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java @@ -64,5 +64,11 @@ public interface MpCashierCartService extends IService { */ List selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId); + /** + * 根据订单id和状态获取购物车数据 + * @param orderId 订单id + * @param status 状态 可为空 + */ + List selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status status); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java index 49ec5ada..2030b662 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.mybatis.service; +import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO; import cn.ysk.cashier.enums.OrderStatusEnums; import cn.ysk.cashier.pojo.order.TbFullOrderDetail; @@ -42,6 +43,11 @@ public interface MpOrderDetailService extends IService { */ List selectByOrderId(Integer orderId); + /** + * 根据订单id和状态获取订单详情 + */ + List selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state); + /** * 根据购物车id和订单id查询订单详情 * @param shopId 店铺id @@ -49,6 +55,6 @@ public interface MpOrderDetailService extends IService { * @param orderId 订单id * @return 详情信息 */ - List selectByCartIdOrOrderId(Integer shopId, ArrayList cartIdList, Integer orderId); + List selectByCartIdOrOrderId(Integer shopId, List cartIdList, Integer orderId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderInfoService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderInfoService.java index d20c67d3..fe49c351 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderInfoService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderInfoService.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.mybatis.service; +import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.enums.OrderStatusEnums; import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderInfo; @@ -15,19 +16,29 @@ import java.util.List; */ public interface MpOrderInfoService extends IService { - /** - * 根据原始订单查询退款订单 - * @param orderId 原始订单id - * @return 对应的退款订单 - */ - TbOrderInfo selectReturnOrderByOrderId(Integer orderId); + /** + * 根据原始订单查询退款订单 + * + * @param orderId 原始订单id + * @return 对应的退款订单 + */ + TbOrderInfo selectReturnOrderByOrderId(Integer orderId); + + /** + * 修改订单的就餐类型和tableId + * + * @param orderId 订单id + * @param useType 就餐类型 + * @return 是否成功 + */ + boolean updateTableIdAndUseTypeById(Integer orderId, String useType, String tableId); /** - * 修改订单的就餐类型和tableId + * 根据状态和id获取订单信息 * @param orderId 订单id - * @param useType 就餐类型 - * @return 是否成功 + * @param status 状态枚举 */ - boolean updateTableIdAndUseTypeById(Integer orderId, String useType, String tableId); + TbOrderInfo selectOrderByIdAndState(Integer orderId, TableConstant.OrderInfo.Status status); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopUserService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopUserService.java new file mode 100644 index 00000000..199ba7dc --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopUserService.java @@ -0,0 +1,16 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.enums.TableStateEnum; +import cn.ysk.cashier.pojo.shop.TbShopTable; +import cn.ysk.cashier.pojo.shop.TbShopUser; +import com.baomidou.mybatisplus.extension.service.IService; + +public interface MpShopUserService extends IService { + /** + * 根据店铺id和用户id查询会员信息 + * @param userId 用户id + * @param shopId 店铺id + * @return 会员信息 + */ + TbShopUser selectByUserIdAndShopId(Integer userId, Integer shopId); +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopCouponService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopCouponService.java index a635fb40..3fccc20e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopCouponService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopCouponService.java @@ -2,18 +2,26 @@ package cn.ysk.cashier.mybatis.service; import cn.ysk.cashier.dto.CouponDto; import cn.ysk.cashier.dto.QueryReceiveDto; +import cn.ysk.cashier.mybatis.entity.TbActivateInRecord; import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord; import cn.ysk.cashier.mybatis.entity.TbCouponProduct; import cn.ysk.cashier.mybatis.vo.TbShopCouponVo; +import cn.ysk.cashier.pojo.order.TbCashierCart; +import cn.ysk.cashier.pojo.order.TbOrderDetail; +import cn.ysk.cashier.pojo.order.TbOrderInfo; +import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.vo.QueryReceiveVo; +import cn.ysk.cashier.vo.TbUserCouponVo; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import cn.ysk.cashier.mybatis.entity.TbShopCoupon; import cn.ysk.cashier.dto.TbShopCouponQueryCriteria; import org.springframework.http.ResponseEntity; +import java.math.BigDecimal; import java.util.List; import java.util.Map; +import java.util.Set; /** * 优惠券(TbShopCoupon)表服务接口 @@ -30,6 +38,16 @@ public interface TbShopCouponService extends IService { boolean update(TbShopCouponVo param); boolean delete(Integer[] ids); + + /** + * 根据金额获取可用优惠券数据 + * @param tbShopUser 店铺id + * @param orderAmount 用户id + * @param productIds 商品id + * @return 优惠券信息 + */ + List getActivateCoupon(TbShopUser tbShopUser, BigDecimal orderAmount, Integer shopId, Set productIds); + boolean deleteReceive(Integer[] ids); ResponseEntity find(CouponDto param); @@ -39,5 +57,20 @@ public interface TbShopCouponService extends IService { boolean refund(List param); List findActivatePros(Integer couponId); + + /** + * 根据优惠券id查询优惠券信息 + * @param couponIds 优惠券id + */ + List selectByIds(List couponIds); + + /** + * 根据订单id获取当前用户可用优惠券信息 + * @param shopId 店铺id + * @param orderId 订单id + * @param memberId 会员id + */ + Object getActivateByOrderIds(Integer shopId, Integer orderId, Integer memberId); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java index 6375f994..da4e44fa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java @@ -15,6 +15,7 @@ import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.pojo.shop.TbShopTable; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @@ -122,5 +123,14 @@ public class MpCashierCartServiceImpl extends ServiceImpl selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status status) { + LambdaQueryChainWrapper queryChainWrapper = lambdaQuery().eq(TbCashierCart::getOrderId, orderId); + if (status != null) { + queryChainWrapper.eq(TbCashierCart::getStatus, status.getValue()); + } + return queryChainWrapper.list(); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java index 2db52b2f..eedafbf7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.mybatis.service.impl; +import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO; import cn.ysk.cashier.enums.OrderStatusEnums; import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper; @@ -48,7 +49,14 @@ public class MpOrderDetailServiceImpl extends ServiceImpl selectByCartIdOrOrderId(Integer shopId, ArrayList cartIdList, Integer orderId) { + public List selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state) { + return list(new LambdaQueryWrapper() + .eq(TbOrderDetail::getStatus, state.getValue()) + .eq(TbOrderDetail::getOrderId, orderId)); + } + + @Override + public List selectByCartIdOrOrderId(Integer shopId, List cartIdList, Integer orderId) { return list(new LambdaQueryWrapper() .and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, orderId)) .eq(TbOrderDetail::getShopId, shopId)); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderInfoServiceImpl.java index ea67276a..3251aa54 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderInfoServiceImpl.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.mybatis.service.impl; +import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper; import cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper; import cn.ysk.cashier.mybatis.service.MpCashierCartService; @@ -33,5 +34,12 @@ public class MpOrderInfoServiceImpl extends ServiceImpl() + .eq(TbOrderInfo::getId, orderId) + .eq(TbOrderInfo::getStatus, status.getValue())); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopUserServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopUserServiceImpl.java new file mode 100644 index 00000000..4873f9c0 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopUserServiceImpl.java @@ -0,0 +1,23 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import cn.ysk.cashier.enums.TableStateEnum; +import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper; +import cn.ysk.cashier.mybatis.mapper.TbShopUserMapper; +import cn.ysk.cashier.mybatis.service.MpShopTableService; +import cn.ysk.cashier.mybatis.service.MpShopUserService; +import cn.ysk.cashier.pojo.shop.TbShopTable; +import cn.ysk.cashier.pojo.shop.TbShopUser; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +@Service +public class MpShopUserServiceImpl extends ServiceImpl implements MpShopUserService { + @Override + public TbShopUser selectByUserIdAndShopId(Integer userId, Integer shopId) { + return getOne(new LambdaQueryWrapper() + .eq(TbShopUser::getUserId, userId) + .eq(TbShopUser::getShopId, shopId)); + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index ce4b3b1a..3dfd63b4 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -4,17 +4,19 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; +import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.dto.CouponDto; import cn.ysk.cashier.dto.QueryReceiveDto; import cn.ysk.cashier.dto.TbShopCouponQueryCriteria; +import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.*; import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper; import cn.ysk.cashier.mybatis.mapper.TbActivateOutRecordMapper; +import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper; import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper; -import cn.ysk.cashier.mybatis.service.TbActivateInRecordService; -import cn.ysk.cashier.mybatis.service.TbCouponProductService; -import cn.ysk.cashier.mybatis.service.TbShopCouponService; +import cn.ysk.cashier.mybatis.service.*; import cn.ysk.cashier.mybatis.vo.TbShopCouponVo; +import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderInfo; import cn.ysk.cashier.pojo.product.TbProduct; @@ -70,6 +72,19 @@ public class TbShopCouponServiceImpl extends ServiceImpl page = new Page<>(criteria.getPage(), criteria.getSize()); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("shop_id", criteria.getShopId()); - if (criteria.getType()!=null) { + if (criteria.getType() != null) { wrapper.eq("type", criteria.getType()); } wrapper.orderByDesc("create_time"); @@ -149,6 +164,72 @@ public class TbShopCouponServiceImpl extends ServiceImpl getActivateCoupon(TbShopUser tbShopUser, BigDecimal orderAmount, Integer shopId, Set productIds) { + List tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), shopId); + if (tbUserCouponVos.isEmpty()) { + return tbUserCouponVos; + } + String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周"); + LocalTime now = LocalTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + //券id 券使用描述 + Map coupons = new HashMap<>(); + for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) { + if (!coupons.containsKey(tbUserCouponVo.getCouponId())) { + setCouponInfo(coupons, tbUserCouponVo, orderAmount, week, now, formatter); + } + JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId()); + tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString()); + if (tbUserCouponVo.getType().equals(1)) { + tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean()); + } else if (tbUserCouponVo.getType().equals(2) && couponJson.get("isUse").getAsBoolean()) { + if (!productIds.contains(tbUserCouponVo.getProId().toString())) { + tbUserCouponVo.setUse(false); + } + } + } + tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime)); + return tbUserCouponVos; + } + + private void setCouponInfo(Map coupons, TbUserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) { + JsonObject json = new JsonObject(); + boolean isUse = true; + TbShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId()); + StringBuilder useRestrictions = new StringBuilder("每天 "); + if (tbShopCoupon.getType().equals(1)) { + if (amount.compareTo(new BigDecimal(tbShopCoupon.getFullAmount())) < 0) { + isUse = false; + } + } + if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) { + String[] split = tbShopCoupon.getUserDays().split(","); + if (split.length != 7) { + useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " "); + } + if (!tbShopCoupon.getUserDays().contains(week)) { + isUse = false; + } + } + if (tbShopCoupon.getUseTimeType().equals("custom")) { + if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) { + isUse = false; + } + useRestrictions.append( + tbShopCoupon.getUseStartTime().format(formatter) + + "-" + + tbShopCoupon.getUseEndTime().format(formatter)); + } else { + useRestrictions.append("全时段"); + } + useRestrictions.append(" 可用"); + json.addProperty("isUse", isUse); + json.addProperty("useRestrictions", useRestrictions.toString()); + + coupons.put(tbUserCouponVo.getCouponId(), json); + } + @Override public ResponseEntity find(CouponDto param) { @@ -225,14 +306,15 @@ public class TbShopCouponServiceImpl extends ServiceImpl param) { + public boolean use(Integer shopId, Integer orderId, Integer vipUserId, List param) { for (TbActivateOutRecord outRecord : param) { TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId()); inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum()); @@ -251,14 +333,15 @@ public class TbShopCouponServiceImpl extends ServiceImpl param) { for (TbActivateOutRecord outRecord : param) { outRecord.setUpdateTime(new Date()); - outRecordMapper.updateRefNum(outRecord.getId(),outRecord.getRefNum()); + outRecordMapper.updateRefNum(outRecord.getId(), outRecord.getRefNum()); TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId()); inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum()); inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum()); @@ -284,5 +367,50 @@ public class TbShopCouponServiceImpl extends ServiceImpl(); } + + @Override + public List selectByIds(List couponIds) { + return listByIds(couponIds); + } + + @Override + public Object getActivateByOrderIds(Integer shopId, Integer orderId, Integer memberId) { + TbOrderInfo orderInfo = mpOrderInfoService.selectOrderByIdAndState(orderId, TableConstant.OrderInfo.Status.UNPAID); + if (orderInfo == null) { + throw new BadRequestException("订单信息不存在"); + } + + if (memberId == null && orderInfo.getMemberId() == null) { + throw new BadRequestException("请先选择对应的会员信息"); + } + + if (memberId == null) { + memberId = Integer.valueOf(orderInfo.getMemberId()); + } + + TbShopUser shopUser = shopUserService.getById(memberId); + if (shopUser == null) { + throw new BadRequestException("用户信息不存在"); + } + + List cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderId, TableConstant.OrderInfo.Status.UNPAID); + List activateCouponList = getActivateCoupon(shopUser, orderInfo.getOrderAmount(), shopId, cashierCarts.stream().map(TbCashierCart::getProductId).collect(Collectors.toSet())); + // 将优惠券分类为满减和商品 + ArrayList fullReductionCoupon = new ArrayList<>(); + ArrayList productCoupon = new ArrayList<>(); + activateCouponList.forEach(item -> { + if (TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.equalsVals(item.getType())) { + fullReductionCoupon.add(item); + } else { + productCoupon.add(item); + } + }); + return new HashMap(){{ + put("fullReductionCoupon", fullReductionCoupon); + put("productCoupon", productCoupon); + }}; + } + + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java index e437561b..164d8beb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java @@ -163,6 +163,8 @@ public class TbCashierCart implements Serializable { private String useType; @Column(name = "platform_type") private String platformType; + // 优惠券id + private Integer userCouponId; public void copy(TbCashierCart source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java index 00c63939..2e3313af 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java @@ -246,9 +246,11 @@ public class TbOrderInfo implements Serializable { // 使用的积分数量 private Integer pointsNum; // 用户优惠券id - private String activateInInfoList; + private String couponInfoList; // 优惠券折扣金额 - private BigDecimal activateInDiscountAmount; + private BigDecimal productCouponDiscountAmount; + // 满减抵扣金额 + private BigDecimal fullCouponDiscountAmount; public void copy(TbOrderInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java index 00876641..c33366b8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java @@ -38,4 +38,7 @@ public interface TbPlussShopStaffRepository extends JpaRepository() - .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .in(TbShopTable::getStatus, "idle", "using")); - if (tbShopTable == null) { - throw new BadRequestException("台桌未开台或不存在"); - } + TbShopUser shopUser = null; + if (createOrderDTO.getVipUserId() != null) { + shopUser = tbShopUserMapper.selectById(createOrderDTO.getVipUserId()); } - + TbShopTable shopTable = checkTableState(createOrderDTO); // 就餐模式信息 ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getUseType()); - // 传递orderId直接取否则取当前缓存id - Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ? - getCurrentOrderId(shopEatTypeInfoDTO) : null; - List allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, createOrderDTO.getMasterId()); - List cashierCarts = new ArrayList<>(); - TbCashierCart seatCart = null; - for (TbCashierCart allCashierCart : allCashierCarts) { - if (TableConstant.CART_SEAT_ID.equals(allCashierCart.getProductId())) { - seatCart = allCashierCart; - } -// if (OrderStatusEnums.CREATE.getValue().equals(allCashierCart.getStatus())) { -// cashierCarts.add(allCashierCart); -// } - cashierCarts.add(allCashierCart); + OrderCartInfoDTO cartInfoDTO = getCartForCreateOrder(shopEatTypeInfoDTO, createOrderDTO.getMasterId()); + if (cartInfoDTO.getOrderId() == null) { + createOrderDTO.setOrderId(shopEatTypeInfoDTO.isDineInAfter() ? + getCurrentOrderId(shopEatTypeInfoDTO) : null); } - - if (StrUtil.isNotBlank(createOrderDTO.getTableId()) - && (cashierCarts.isEmpty() || - (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart != null && cashierCarts.size() < 2) - || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart == null))) { - throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费"); - } - - if (cashierCarts.isEmpty()) { - throw new BadRequestException("购物车为空"); - } - - ArrayList cartIdList = new ArrayList<>(); - for (TbCashierCart tbCashierCart : cashierCarts) { - if (tbCashierCart.getOrderId() != null) { - orderId = tbCashierCart.getOrderId(); - } - cartIdList.add(tbCashierCart.getId()); - } - // 查询历史orderDetail - List oldOrderDetailList = mpOrderDetailService.selectByCartIdOrOrderId(createOrderDTO.getShopId(), cartIdList, orderId); - - ArrayList removeOrderDetailIds = new ArrayList<>(); - ArrayList removeOrderDetailList = new ArrayList<>(); - HashMap oldOrderDetailMap = new HashMap<>(); - oldOrderDetailList.forEach(item -> { - if (cartIdList.contains(item.getCartId())) { - oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item); - } else { - removeOrderDetailIds.add(item.getId()); - removeOrderDetailList.add(item); - } - }); - - BigDecimal totalAmount = BigDecimal.ZERO; - BigDecimal packAMount = BigDecimal.ZERO; - BigDecimal feeAmount = BigDecimal.ZERO; - BigDecimal saleAmount = BigDecimal.ZERO; - // 当前下单次数 - int placeNum = getCurrentPlaceNum(shopEatTypeInfoDTO); - List orderDetails = new ArrayList<>(); - List addOrderDetails = new ArrayList<>(); - - boolean hasNewInfo = false; - for (TbCashierCart cashierCart : cashierCarts) { - if (!"return".equals(cashierCart.getStatus())) { - totalAmount = totalAmount.add(cashierCart.getTotalAmount()); - packAMount = packAMount.add(cashierCart.getPackFee()); - feeAmount = cashierCart.getPackFee(); - } - - TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); - TbOrderDetail orderDetail = null; - if (cashierCart.getOrderId() != null) { - orderDetail = oldOrderDetailMap.get(cashierCart.getOrderId().toString() + cashierCart.getId()); - } - - if (orderDetail == null) { - orderDetail = new TbOrderDetail(); - hasNewInfo = true; - addOrderDetails.add(orderDetail); - } - - if (Objects.nonNull(productSku)) { - saleAmount = saleAmount.add(productSku.getSalePrice()); - orderDetail.setProductSkuName(productSku.getSpecSnap()); - } - - orderDetail.setNote(cashierCart.getNote()); - orderDetail.setCreateTime(DateUtil.date().toTimestamp()); - orderDetail.setNum(cashierCart.getNumber()); - orderDetail.setPrice(cashierCart.getSalePrice()); - orderDetail.setPriceAmount(cashierCart.getTotalAmount()); - orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId())); - orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId())); - orderDetail.setProductName(cashierCart.getName()); - orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId())); - orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid"); - orderDetail.setUseType(shopEatTypeInfoDTO.getUseType()); - orderDetail.setProductImg(cashierCart.getCoverImg()); - orderDetail.setCartId(cashierCart.getId()); - if (cashierCart.getOrderId() != null) { - orderId = cashierCart.getOrderId(); - } - orderDetail.setOrderId(orderId); - orderDetails.add(orderDetail); - } - // 查询订单 TbOrderInfo orderInfo = null; - if (orderId != null) { - orderInfo = orderInfoMapper.selectById(orderId); + if (cartInfoDTO.getOrderId() != null) { + orderInfo = orderInfoMapper.selectById(cartInfoDTO.getOrderId()); } - TbShopUser shopUser = null; - if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) { - shopUser = tbShopUserMapper.selectById(createOrderDTO.getVipUserId()); - if (shopUser == null) { - throw new BadRequestException("用户不存在"); - } - } +// OrderCouponInfoDTO couponInfo = null; +// if (createOrderDTO.getUserCouponInfos().isEmpty() && createOrderDTO.getVipUserId() != null) { +// // 获取优惠券信息 +// couponInfo = getCouponInfo(createOrderDTO, orderInfo, cartInfoDTO.getNewAddTotalAmount(), cartInfoDTO.getCashierCarts()); +// +// // 根据优惠券信息重新计算购物车相关价格 +// calcCartPriceWithCoupon(cartInfoDTO.getNewCashierCarts(), couponInfo, couponInfo.getShopUser().getId()); +// } + + // 创建订单详情 + OrderPriceDTO detailPriceDTO = createOrderDetailWithCoupon(cartInfoDTO.getCashierCarts(), cartInfoDTO.getOrderId(), createOrderDTO.getShopId(), true); // 是否是第一次创建订单 - boolean isFirst = false; - // 修改订单信息 - if (orderInfo != null) { - // 更新取餐号 - orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString()); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(totalAmount); - orderInfo.setOrderAmount(totalAmount); - orderInfo.setRemark(createOrderDTO.getNote()); - orderInfo.setFreightAmount(feeAmount); - orderInfo.setProductAmount(saleAmount); - orderInfo.setTradeDay(DateUtils.getDay()); - orderInfo.setUseType(shopEatTypeInfoDTO.getUseType()); - orderInfo.setCreatedAt(DateUtil.current()); - if (seatCart != null) { - orderInfo.setSeatAmount(seatCart.getTotalAmount()); - orderInfo.setSeatCount(seatCart.getNumber()); - } - if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) { - orderInfo.setMemberId(createOrderDTO.getVipUserId()); - orderInfo.setUserId(shopUser.getUserId()); - } - orderInfo.setSendType(shopEatTypeInfoDTO.getSendType()); - // 存在新添加的商品,增加下单次数 - if (hasNewInfo) { - orderInfo.setPlaceNum(placeNum); - } - orderInfoMapper.updateById(orderInfo); - } else { - isFirst = true; - String orderNo = generateOrderNumber(null); - orderInfo = new TbOrderInfo(); - orderInfo.setOrderNo(orderNo); - orderInfo.setAmount(totalAmount); - orderInfo.setPayAmount(BigDecimal.ZERO); - orderInfo.setPackFee(packAMount); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setOriginAmount(totalAmount); - orderInfo.setProductAmount(saleAmount); - orderInfo.setOrderAmount(totalAmount); - orderInfo.setFreightAmount(feeAmount); - orderInfo.setTableId(createOrderDTO.getTableId()); - orderInfo.setSendType("table"); - orderInfo.setOrderType("cash"); - orderInfo.setShopId(createOrderDTO.getShopId().toString()); - orderInfo.setRefundAble(1); - orderInfo.setTradeDay(cn.ysk.cashier.utils.DateUtils.getDay()); - orderInfo.setMasterId(createOrderDTO.getMasterId()); - orderInfo.setOutNumber(createOrderDTO.getMasterId()); - orderInfo.setRemark(createOrderDTO.getNote()); - orderInfo.setCreatedAt(DateUtil.current()); - orderInfo.setTableName(tbShopTable != null ? tbShopTable.getName() : null); - orderInfo.setPlaceNum(placeNum); - orderInfo.setUseType(shopEatTypeInfoDTO.getUseType()); - if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) { - orderInfo.setUserId(createOrderDTO.getVipUserId()); - orderInfo.setUserId(shopUser.getUserId()); - } - if (seatCart != null) { - orderInfo.setSeatAmount(seatCart.getTotalAmount()); - orderInfo.setSeatCount(seatCart.getNumber()); - } - orderInfo.setSendType(shopEatTypeInfoDTO.getSendType()); - TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper() - .eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId()) - .eq(TbMerchantAccount::getStatus, 1)); - if (merchantAccount == null) { - throw new BadRequestException("商户信息不存在"); - } - orderInfo.setMerchantId(merchantAccount.getId().toString()); - orderInfoMapper.insert(orderInfo); - } + orderInfo = createOrderWithAction(createOrderDTO, detailPriceDTO, shopEatTypeInfoDTO, + orderInfo, cartInfoDTO.getSeatCart(), shopUser, shopTable); - // 添加订单详细数据 - orderId = orderInfo.getId(); - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - if (orderDetail.getPlaceNum() == null) { - orderDetail.setPlaceNum(placeNum); - } - } - // 删除已经移除购物车的订单 修改并保存数据 - if (!orderDetails.isEmpty()) { - mpOrderDetailService.saveOrUpdateBatch(orderDetails); - } + // 修改订单详情并打票 + updateDetailAndPrint(orderInfo, detailPriceDTO, shopEatTypeInfoDTO); - // 更新购物车记录的orderId - for (TbCashierCart cashierCart : cashierCarts) { - if (!"-999".equals(cashierCart.getProductId())) { - TbProduct product = productMapper.selectById(cashierCart.getProductId()); - TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); - - log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId()); - CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber())); - // 已经添加的商品,修改数量 - updateStock(cashierCart); - } - - cashierCart.setOrderId(orderId); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus()); - if (cashierCart.getPlaceNum() == null) { - cashierCart.setPlaceNum(placeNum); - } - - // 先付费模式,结束购物车状态 - if (!shopEatTypeInfoDTO.isDineInAfter() || StrUtil.isBlank(createOrderDTO.getTableId())) { - cashierCart.setStatus("final"); - } - cashierCartMapper.updateById(cashierCart); - } - - // 菜品票 - if (!addOrderDetails.isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) { - rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, addOrderDetails.toArray(new TbOrderDetail[0])); - } - - if (!removeOrderDetailIds.isEmpty()) { - // 退单票 - orderDetailMapper.deleteBatchIds(removeOrderDetailIds); - if (shopEatTypeInfoDTO.isDineInAfter()) { - rabbitMsgUtils.printDishesTicket(orderInfo.getId(), true, removeOrderDetailList.toArray(new TbOrderDetail[0])); - } - } - - if (isFirst) { - // 后付费,不增加当前台桌取餐号 - if (!shopEatTypeInfoDTO.isIncrMaterId()) { - addGlobalCode(cn.ysk.cashier.utils.DateUtils.getDay(), "pc", String.valueOf(createOrderDTO.getShopId())); - } - - if (shopEatTypeInfoDTO.isIncrMaterId() || "pending".equals(orderInfo.getStatus())) { - String key = RedisConstant.getMasterIdKey(createOrderDTO.getShopId(), cn.ysk.cashier.utils.DateUtils.getDay(), orderInfo.getTableId()); - redisTemplate.delete(key); - } - } + // 修改购物车状态和库存 + updateCartAndStock(cartInfoDTO.getNewCashierCarts(), orderInfo, shopEatTypeInfoDTO); // 推送耗材信息 - pushConsMsg(orderInfo, cashierCarts); + pushConsMsg(orderInfo, cartInfoDTO.getNewCashierCarts()); - if (!shopEatTypeInfoDTO.isTakeout() && StrUtil.isNotBlank(createOrderDTO.getTableId())) { - // 清空台桌信息 - if (shopEatTypeInfoDTO.isDineInBefore()) { - mpShopTableMapper.update(null, new LambdaUpdateWrapper() - .eq(TbShopTable::getShopId, createOrderDTO.getShopId()) - .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .set(TbShopTable::getProductNum, 0) - .set(TbShopTable::getTotalAmount, 0) - .set(TbShopTable::getRealAmount, 0) - .set(TbShopTable::getUseNum, 0) - .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); - // 设置台桌信息 - } else { - LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() - .eq(TbShopTable::getShopId, createOrderDTO.getShopId()) - .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .set(TbShopTable::getProductNum, cashierCarts.size()) - .set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount()) - .set(TbShopTable::getRealAmount, orderInfo.getOrderAmount()) - .set(TbShopTable::getUseNum, seatCart != null ? seatCart.getNumber() : null) - .set(TbShopTable::getStatus, TableStateEnum.USING.getState()); - if (isFirst) { - wrapper.set(TbShopTable::getUseTime, DateUtil.date()); - } - mpShopTableMapper.update(null, wrapper); + updateTableState(shopEatTypeInfoDTO, orderInfo, cartInfoDTO.getCashierCarts(), cartInfoDTO.getSeatCart()); - } - } - - - if (StrUtil.isNotBlank(createOrderDTO.getTableId())) { - String tableCartKey = RedisConstant.getTableCartKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); - redisTemplate.delete(tableCartKey); - } return orderInfo; }, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CREATE_ORDER, createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getMasterId(), createOrderDTO.getUseType())); } - private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List userCouponList, Integer pointsNum) { + private BigDecimal calcCartPriceWithCoupon(List newCashierCarts, OrderCouponInfoDTO couponInfoDTO, Integer memberId, TbOrderInfo orderInfo) { + ArrayList balanceCartList = new ArrayList<>(); + BigDecimal discountAmount = BigDecimal.ZERO; + HashMap couponMap = new HashMap<>(); + couponInfoDTO.getProductCouponMap().values().forEach(item -> { + couponMap.put(item.getProId().toString(), item); + }); + HashMap usedCouponMap = new HashMap<>(); + ArrayList outRecords = new ArrayList<>(); + for (TbCashierCart cashierCart : newCashierCarts) { + TbUserCouponVo couponVo = couponMap.get(cashierCart.getProductId()); + boolean useCoupon; + if (couponVo != null && couponVo.getCurrentUseNum() > 0) { + BigDecimal currentUseNum = BigDecimal.ZERO; + if (cashierCart.getNumber() < couponVo.getCurrentUseNum()) { + currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum()); + BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber()); + BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP); + cashierCart.setPackFee(singlePackFee.multiply(currentUseNum)); + cashierCart.setTotalAmount(cashierCart.getSalePrice().multiply(currentUseNum).add(singlePackFee.multiply(currentUseNum))); + cashierCart.setNumber(couponVo.getCurrentUseNum()); + cashierCart.setTotalNumber(couponVo.getCurrentUseNum()); + cashierCart.setUserCouponId(couponVo.getId()); + discountAmount = discountAmount.add(cashierCart.getTotalAmount()); + couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber()); + } + usedCouponMap.put(Integer.valueOf(cashierCart.getProductId()), couponVo); + // 优惠券数量小于购物车数量,分割购物车数据 + if (cashierCart.getNumber() > couponVo.getCurrentUseNum()) { + currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum()); + BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber()); + int balanceNum = cashierCart.getTotalNumber() - couponVo.getCurrentUseNum(); + BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP); + cashierCart.setPackFee(singlePackFee.multiply(currentUseNum)); + cashierCart.setTotalAmount(cashierCart.getSalePrice().multiply(currentUseNum).add(singlePackFee.multiply(currentUseNum))); + cashierCart.setNumber(couponVo.getCurrentUseNum()); + cashierCart.setTotalNumber(couponVo.getCurrentUseNum()); + cashierCart.setUserCouponId(couponVo.getId()); + discountAmount = discountAmount.add(cashierCart.getTotalAmount()); + couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber()); + + + // 创建结余购物车 + TbCashierCart balanceCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class); + BigDecimal num = BigDecimal.valueOf(balanceNum); + balanceCart.setUserCouponId(null); + balanceCart.setId(null); + balanceCart.setNumber(balanceNum); + balanceCart.setTotalNumber(balanceNum); + balanceCart.setPackFee(singlePackFee.multiply(num)); + balanceCart.setTotalAmount(cashierCart.getSalePrice().multiply(num).add(balanceCart.getPackFee())); + balanceCartList.add(balanceCart); + } else { + currentUseNum = BigDecimal.valueOf(cashierCart.getNumber()); + discountAmount = discountAmount.add(cashierCart.getTotalAmount()); + cashierCart.setUserCouponId(couponVo.getId()); + couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber()); + } + // 消耗并返还商品优惠券 + Integer shopId = Integer.valueOf(cashierCart.getShopId()); + TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord(); + tbActivateOutRecord.setShopId(shopId); + tbActivateOutRecord.setGiveId(couponVo.getId()); + tbActivateOutRecord.setVipUserId(memberId); + tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue()); + tbActivateOutRecord.setUseNum(currentUseNum.toBigInteger().intValue()); + tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue()); + tbActivateOutRecord.setCreateTime(DateUtil.date()); + tbActivateOutRecord.setRefNum(0); + outRecords.add(tbActivateOutRecord); + } + } + + if (!balanceCartList.isEmpty()) { + newCashierCarts.addAll(balanceCartList); + mpCashierCartService.saveBatch(balanceCartList); + } + // 更新购物车信息 + mpCashierCartService.updateBatchById(newCashierCarts); + + couponInfoDTO.setOutRecordList(outRecords); + couponInfoDTO.setProductCouponMap(usedCouponMap); + + return discountAmount; + } + + private OrderCouponInfoDTO getCouponInfo(Integer memberId, Integer shopId, List userCouponInfoDTOList, BigDecimal orderAmount, Set productIds) { + OrderCouponInfoDTO infoDTO = new OrderCouponInfoDTO(); + // 查询优惠券信息 + TbShopUser shopUser = null; + if (memberId != null) { + shopUser = tbShopUserMapper.selectById(memberId); + if (shopUser == null) { + throw new BadRequestException("用户不存在"); + } + // 获取当前用户可用的优惠券 + List activateCouponList = shopCouponService.getActivateCoupon(shopUser, orderAmount, shopId, productIds); + // 将优惠券分类为满减和商品 + HashMap fullReductionCoupon = new HashMap<>(); + HashMap productCoupon = new HashMap<>(); + if (activateCouponList.isEmpty()) { + throw new BadRequestException("未查询到相关优惠券"); + } + activateCouponList.forEach(item -> { + if (TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.equalsVals(item.getType())) { + fullReductionCoupon.put(item.getId(), item); + } else { + productCoupon.put(item.getId(), item); + } + }); + + userCouponInfoDTOList.forEach(item -> { + TbUserCouponVo couponVo = fullReductionCoupon.get(item.getUserCouponId()); + if (couponVo != null) { + if (couponVo.getNum() < item.getNum()) { + throw new BadRequestException(couponVo.getName() + "数量不足: " + couponVo.getNum()); + } + couponVo.setCurrentUseNum(item.getNum()); + infoDTO.getFullReductionCouponMap().put(couponVo.getId(), couponVo); + return; + } + couponVo = productCoupon.get(item.getUserCouponId()); + if (couponVo == null) { + throw new BadRequestException("存在不可用优惠券"); + } + couponVo.setCurrentUseNum(item.getNum()); + infoDTO.getProductCouponMap().put(item.getUserCouponId(), couponVo); + }); + + } + infoDTO.setShopUser(shopUser); + + return infoDTO; + } + + private OrderCartInfoDTO getCartForCreateOrder(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId) { + OrderCartInfoDTO cartInfoDTO = new OrderCartInfoDTO(); + + List allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, masterId); + TbCashierCart seatCart = null; + for (TbCashierCart cashierCart : allCashierCarts) { + if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) { + seatCart = cashierCart; + cartInfoDTO.setSeatCart(cashierCart); + } + if (OrderStatusEnums.CREATE.getValue().equals(cashierCart.getStatus())) { + cartInfoDTO.getNewCashierCarts().add(cashierCart); + } + cartInfoDTO.getCashierCarts().add(cashierCart); + } + + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId()) + && (cartInfoDTO.getCashierCarts().isEmpty() || + (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart != null && cartInfoDTO.getCashierCarts().size() < 2) + || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart == null))) { + throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费"); + } + + if (cartInfoDTO.getCashierCarts().isEmpty()) { + throw new BadRequestException("购物车为空"); + } + + ArrayList cartIdList = new ArrayList<>(); + // 订单总价 + for (TbCashierCart tbCashierCart : cartInfoDTO.getCashierCarts()) { + if (tbCashierCart.getOrderId() != null) { + cartInfoDTO.setOrderId(tbCashierCart.getOrderId()); + } + cartIdList.add(tbCashierCart.getId()); + if (TableConstant.CashierCart.Status.CREATE.equalsVals(tbCashierCart.getStatus())) { + cartInfoDTO.setNewAddTotalAmount(cartInfoDTO.getNewAddTotalAmount().add(tbCashierCart.getTotalAmount())); + } + + cartInfoDTO.setTotalAmount(cartInfoDTO.getTotalAmount().add(tbCashierCart.getTotalAmount())); + } + cartInfoDTO.setCashierCartIds(cartIdList); + return cartInfoDTO; + } + + private void consumeCoupon(List outRecordList, Integer memberId, TbOrderInfo orderInfo) { + boolean use = shopCouponService.use(Integer.valueOf(orderInfo.getShopId()), orderInfo.getId(), memberId, outRecordList); + if (!use) { + throw new BadRequestException("消耗券失败"); + } + } + + private void returnCoupon(TbOrderInfo orderInfo) { + // 返还优惠券 + if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) { + OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class); + // 券返还 + if (!couponInfoDTO.getOutRecordList().isEmpty()) { + couponInfoDTO.getOutRecordList().forEach(item -> { + item.setRefNum(item.getUseNum()); + }); + shopCouponService.refund(couponInfoDTO.getOutRecordList()); + couponInfoDTO.setOutRecordList(new ArrayList<>()); + orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO)); + } + } + + } + + /** + * 根据商品优惠券 + * + * @param fullCashierCarts + * @param orderId + * @param shopId + * @param updateState + * @return + */ + private OrderPriceDTO createOrderDetailWithCoupon(List fullCashierCarts, Integer orderId, Integer shopId, boolean updateState) { + OrderPriceDTO priceDTO = new OrderPriceDTO(); + + List cartIds = fullCashierCarts.stream().map(TbCashierCart::getId).collect(Collectors.toList()); + // 查询历史orderDetail + List oldOrderDetailList = mpOrderDetailService + .selectByCartIdOrOrderId(shopId, cartIds, orderId); + HashMap oldOrderDetailMap = new HashMap<>(); + oldOrderDetailList.forEach(item -> { + if (cartIds.contains(item.getCartId())) { + oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item); + } else { + priceDTO.getRemoveOrderDetailIds().add(item.getId()); + priceDTO.getRemoveOrderDetailList().add(item); + } + }); + + for (TbCashierCart cashierCart : fullCashierCarts) { + // 已经退款和使用优惠券的商品不进行统计金额 + if (!"return".equals(cashierCart.getStatus()) && cashierCart.getUserCouponId() == null) { + priceDTO.setTotalAmount(priceDTO.getTotalAmount().add(cashierCart.getTotalAmount())); + priceDTO.setPackAmount(priceDTO.getPackAmount().add(cashierCart.getPackFee())); + priceDTO.setOriginAmount(priceDTO.getOriginAmount().add(cashierCart.getTotalAmount())); + } + + TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); + TbOrderDetail orderDetail = null; + if (cashierCart.getOrderId() != null) { + orderDetail = oldOrderDetailMap.get(cashierCart.getOrderId().toString() + cashierCart.getId()); + } + + if (orderDetail == null) { + orderDetail = new TbOrderDetail(); + priceDTO.setHasNewInfo(true); + priceDTO.getNewOrderDetailList().add(orderDetail); + } + + if (Objects.nonNull(productSku)) { + orderDetail.setProductSkuName(productSku.getSpecSnap()); + } + + orderDetail.setNote(cashierCart.getNote()); + orderDetail.setCreateTime(DateUtil.date().toTimestamp()); + orderDetail.setNum(cashierCart.getNumber()); + orderDetail.setPrice(cashierCart.getSalePrice()); + orderDetail.setPriceAmount(cashierCart.getTotalAmount()); + orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId())); + orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId())); + orderDetail.setProductName(cashierCart.getName()); + orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId())); + orderDetail.setPackAmount(cashierCart.getPackFee()); + if (updateState) { + orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid"); + } + orderDetail.setUseType(cashierCart.getUseType()); + orderDetail.setProductImg(cashierCart.getCoverImg()); + orderDetail.setCartId(cashierCart.getId()); + if (cashierCart.getOrderId() != null) { + orderId = cashierCart.getOrderId(); + } + orderDetail.setOrderId(orderId); + priceDTO.getOrderDetailList().add(orderDetail); + } + return priceDTO; + } + + private TbOrderInfo createOrderWithAction(CreateOrderDTO createOrderDTO, OrderPriceDTO priceDTO, ShopEatTypeInfoDTO eatTypeInfoDTO, + TbOrderInfo orderInfo, TbCashierCart seatCart, TbShopUser shopUser, TbShopTable shopTable) { + int placeNum = getCurrentPlaceNum(eatTypeInfoDTO); + boolean isFirst = false; + // 修改订单信息 + if (orderInfo == null) { + isFirst = true; + String orderNo = generateOrderNumber(null); + orderInfo = new TbOrderInfo(); + orderInfo.setOrderNo(orderNo); + orderInfo.setCreatedAt(DateUtil.current()); + orderInfo.setTradeDay(cn.ysk.cashier.utils.DateUtils.getDay()); + orderInfo.setRefundAble(1); + orderInfo.setOrderType("cash"); + orderInfo.setShopId(createOrderDTO.getShopId().toString()); + orderInfo.setTableId(createOrderDTO.getTableId()); + orderInfo.setTableName(shopTable != null ? shopTable.getName() : null); + orderInfo.setMasterId(createOrderDTO.getMasterId()); + TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper() + .eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId()) + .eq(TbMerchantAccount::getStatus, 1)); + if (merchantAccount == null) { + throw new BadRequestException("商户信息不存在"); + } + orderInfo.setMerchantId(merchantAccount.getId().toString()); + } + // 更新取餐号 + orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString()); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + orderInfo.setSettlementAmount(priceDTO.getTotalAmount()); + orderInfo.setAmount(priceDTO.getTotalAmount()); + orderInfo.setOriginAmount(priceDTO.getOriginAmount()); + orderInfo.setOrderAmount(priceDTO.getTotalAmount()); + orderInfo.setRemark(createOrderDTO.getNote()); + orderInfo.setFreightAmount(BigDecimal.ZERO); + orderInfo.setProductAmount(BigDecimal.ZERO); + orderInfo.setTradeDay(DateUtils.getDay()); + orderInfo.setUseType(eatTypeInfoDTO.getUseType()); + orderInfo.setCreatedAt(DateUtil.current()); + if (seatCart != null) { + orderInfo.setSeatAmount(seatCart.getTotalAmount()); + orderInfo.setSeatCount(seatCart.getNumber()); + } + if (createOrderDTO.getVipUserId() != null) { + orderInfo.setMemberId(String.valueOf(shopUser.getId())); + orderInfo.setUserId(shopUser.getUserId()); + } + orderInfo.setSendType(eatTypeInfoDTO.getSendType()); + // 存在新添加的商品,增加下单次数 + if (priceDTO.isHasNewInfo()) { + orderInfo.setPlaceNum(placeNum); + } + orderInfoMapper.insertOrUpdate(orderInfo); + + if (isFirst) { + // 后付费,不增加当前台桌取餐号 + if (!eatTypeInfoDTO.isIncrMaterId()) { + addGlobalCode(cn.ysk.cashier.utils.DateUtils.getDay(), "pc", String.valueOf(createOrderDTO.getShopId())); + } + + if (eatTypeInfoDTO.isIncrMaterId() || "pending".equals(orderInfo.getStatus())) { + String key = RedisConstant.getMasterIdKey(createOrderDTO.getShopId(), cn.ysk.cashier.utils.DateUtils.getDay(), orderInfo.getTableId()); + redisTemplate.delete(key); + } + } + + return orderInfo; + } + + private void updateDetailAndPrint(TbOrderInfo orderInfo, OrderPriceDTO priceDTO, ShopEatTypeInfoDTO shopEatTypeInfoDTO) { + // 添加订单详细数据 + Integer orderId = orderInfo.getId(); + for (TbOrderDetail orderDetail : priceDTO.getOrderDetailList()) { + orderDetail.setOrderId(orderId); + if (orderDetail.getPlaceNum() == null) { + orderDetail.setPlaceNum(orderInfo.getPlaceNum()); + } + } + // 删除已经移除购物车的订单 修改并保存数据 + if (!priceDTO.getOrderDetailList().isEmpty()) { + mpOrderDetailService.saveOrUpdateBatch(priceDTO.getOrderDetailList()); + } + + // 菜品票 + if (!priceDTO.getNewOrderDetailList().isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) { + rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, priceDTO.getNewOrderDetailList().toArray(new TbOrderDetail[0])); + } + + if (!priceDTO.getRemoveOrderDetailIds().isEmpty()) { + // 退单票 + orderDetailMapper.deleteBatchIds(priceDTO.getRemoveOrderDetailIds()); + if (shopEatTypeInfoDTO.isDineInAfter()) { + rabbitMsgUtils.printDishesTicket(orderInfo.getId(), true, priceDTO.getRemoveOrderDetailList().toArray(new TbOrderDetail[0])); + } + } + } + + private void updateCartAndStock(List newAddCashierCarts, TbOrderInfo orderInfo, ShopEatTypeInfoDTO shopEatTypeInfoDTO) { + // 更新购物车记录的orderId + for (TbCashierCart cashierCart : newAddCashierCarts) { + if (!"-999".equals(cashierCart.getProductId())) { + TbProduct product = productMapper.selectById(cashierCart.getProductId()); + TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); + + log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId()); + CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber())); + // 已经添加的商品,修改数量 + updateStock(cashierCart); + } + + cashierCart.setOrderId(orderInfo.getId()); + cashierCart.setUpdatedAt(System.currentTimeMillis()); + cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus()); + if (cashierCart.getPlaceNum() == null) { + cashierCart.setPlaceNum(orderInfo.getPlaceNum()); + } + + // 先付费模式,结束购物车状态 + if (!shopEatTypeInfoDTO.isDineInAfter() || StrUtil.isBlank(shopEatTypeInfoDTO.getTableId())) { + cashierCart.setStatus("final"); + } + cashierCartMapper.updateById(cashierCart); + } + } + + + private void updateTableState(ShopEatTypeInfoDTO shopEatTypeInfoDTO, TbOrderInfo orderInfo, List fullCashierCarts, TbCashierCart seatCart) { + if (!shopEatTypeInfoDTO.isTakeout() && StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + // 清空台桌信息 + if (shopEatTypeInfoDTO.isDineInBefore()) { + mpShopTableMapper.update(null, new LambdaUpdateWrapper() + .eq(TbShopTable::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbShopTable::getQrcode, shopEatTypeInfoDTO.getTableId()) + .set(TbShopTable::getProductNum, 0) + .set(TbShopTable::getTotalAmount, 0) + .set(TbShopTable::getRealAmount, 0) + .set(TbShopTable::getUseNum, 0) + .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); + // 设置台桌信息 + } else { + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() + .eq(TbShopTable::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbShopTable::getQrcode, shopEatTypeInfoDTO.getTableId()) + .set(TbShopTable::getProductNum, fullCashierCarts.size()) + .set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount()) + .set(TbShopTable::getRealAmount, orderInfo.getOrderAmount()) + .set(TbShopTable::getUseNum, seatCart != null ? seatCart.getNumber() : null) + .set(TbShopTable::getStatus, TableStateEnum.USING.getState()); + if (orderInfo.getPlaceNum() == 1) { + wrapper.set(TbShopTable::getUseTime, DateUtil.date()); + } + mpShopTableMapper.update(null, wrapper); + + } + } + + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + String tableCartKey = RedisConstant.getTableCartKey(shopEatTypeInfoDTO.getTableId(), shopEatTypeInfoDTO.getShopId().toString()); + redisTemplate.delete(tableCartKey); + } + } + + private TbShopTable checkTableState(CreateOrderDTO createOrderDTO) { + + // 非堂食校验台桌状态 + TbShopTable tbShopTable = null; + if (StrUtil.isNotBlank(createOrderDTO.getTableId())) { + tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) + .in(TbShopTable::getStatus, "idle", "using")); + if (tbShopTable == null) { + throw new BadRequestException("台桌未开台或不存在"); + } + } + return tbShopTable; + } + + private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List mineUserCouponList, Integer pointsNum) { BigDecimal shouldPayAmount = BigDecimal.ZERO; if (pointsNum != null) { Long memberId = Long.valueOf(orderInfo.getMemberId()); @@ -1442,8 +1645,42 @@ public class TbShopTableServiceImpl implements TbShopTableService { memberPointsService.deductPoints(memberId, pointsNum, "霸王餐充值抵扣", Long.valueOf(orderInfo.getId())); } - if (!userCouponList.isEmpty()) { + if (!mineUserCouponList.isEmpty()) { + CouponDto couponDto = new CouponDto(); + couponDto.setShopId(Integer.valueOf(orderInfo.getShopId())); + couponDto.setUserId(Integer.valueOf(orderInfo.getUserId())); + couponDto.setStatus(1); + couponDto.setOrderId(orderInfo.getId()); + List userCouponList = (List) shopCouponService.find(couponDto).getBody(); + if (userCouponList == null || userCouponList.isEmpty()) { + throw new BadRequestException("存在不可用优惠券"); + } + ArrayList activateInInfoVOS = new ArrayList<>(); + for (Integer userCouponId : mineUserCouponList) { + TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(userCouponId)).findFirst().orElse(null); + if (userCouponVo == null) { + throw new BadRequestException("存在不可用优惠券"); + } + + shouldPayAmount = shouldPayAmount.subtract(userCouponVo.getDiscountAmount()); + ActivateInInfoVO activateInInfoVO = new ActivateInInfoVO() + .setId(userCouponVo.getId()) + .setCouponId(userCouponVo.getCouponId()) + .setType(userCouponVo.getType()) + .setNum(1); + activateInInfoVOS.add(activateInInfoVO); + } + + List tbShopCoupons = shopCouponService.listByIds(activateInInfoVOS.stream().map(ActivateInInfoVO::getCouponId).collect(Collectors.toList())); + if (tbShopCoupons.size() != mineUserCouponList.size()) { + throw new BadRequestException("存在不可用优惠券"); + } + + // 设置优惠券信息 + orderInfo.setCouponInfoList(JSONObject.toJSONString(activateInInfoVOS)); + orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum))); +// record.setCouponInfo(JSONObject.toJSONString(userCouponList)); } } @@ -1588,7 +1825,118 @@ public class TbShopTableServiceImpl implements TbShopTableService { return payTypeRepository.findByShopId(String.valueOf(shopId)); } + private TbActivateOutRecord calcOrderInfoDiscount(PayDTO payDTO, TbOrderInfo orderInfo, OrderCouponInfoDTO couponInfo) { + if (payDTO.getVipUserId() != null) { + BigDecimal finalAmount = orderInfo.getOrderAmount(); + TbActivateOutRecord tbActivateOutRecord = null; + if (!couponInfo.getFullReductionCouponMap().isEmpty()) { + TbUserCouponVo couponVo = couponInfo.getFullReductionCouponMap().values().stream().findFirst().orElse(null); + finalAmount = finalAmount.subtract(couponVo.getDiscountAmount()); + orderInfo.setFullCouponDiscountAmount(couponVo.getDiscountAmount()); + + tbActivateOutRecord = new TbActivateOutRecord(); + tbActivateOutRecord.setShopId(Integer.valueOf(orderInfo.getShopId())); + tbActivateOutRecord.setGiveId(couponVo.getId()); + tbActivateOutRecord.setVipUserId(payDTO.getVipUserId()); + tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue()); + tbActivateOutRecord.setUseNum(couponVo.getCurrentUseNum()); + tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue()); + tbActivateOutRecord.setCreateTime(DateUtil.date()); + tbActivateOutRecord.setRefNum(0); + + } + + // 计算积分优惠 + if (payDTO.getPointsNum() != null && payDTO.getPointsNum() != 0) { + BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, payDTO.getPointsNum()); + finalAmount = finalAmount.subtract(discountPointsAmount); + orderInfo.setPointsDiscountAmount(discountPointsAmount); + } + + if (finalAmount.compareTo(BigDecimal.ZERO) < 0) { + finalAmount = BigDecimal.ZERO; + orderInfo.setFullCouponDiscountAmount(orderInfo.getOrderAmount()); + } + + orderInfo.setSettlementAmount(finalAmount); + orderInfo.setOrderAmount(finalAmount); + orderInfo.setAmount(finalAmount); + + return tbActivateOutRecord; + } + + return null; + + } + + private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, int pointsNum) { + Long memberId = Long.valueOf(orderInfo.getMemberId()); + + if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) { + memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId())); + } + + OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount()); + if (!memberUsablePoints.getUsable()) { + throw new BadRequestException(memberUsablePoints.getUnusableReason()); + } + if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) { + throw new BadRequestException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]"); + } + + BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum); + orderInfo.setPointsNum(pointsNum); + orderInfo.setPointsDiscountAmount(discountAmount); + memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId())); + return discountAmount; + } + + private void calcDiscountAndUpdateInfo(PayDTO payDTO, TbOrderInfo orderInfo) { + // 返还上次使用的券 + returnCoupon(orderInfo); + + Set productIdSet = new HashSet<>(); + List cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId(), null); + ArrayList activateCartInfo = new ArrayList<>(); + for (TbCashierCart cashierCart : cashierCarts) { + productIdSet.add(cashierCart.getProductId()); + if (TableConstant.OrderInfo.Status.CREATE.equalsVals(cashierCart.getStatus()) || TableConstant.OrderInfo.Status.FINAL.equalsVals(cashierCart.getStatus())) { + activateCartInfo.add(cashierCart); + } + } + + // 获取优惠券信息 + OrderCouponInfoDTO couponInfo = new OrderCouponInfoDTO(); + if (!payDTO.getUserCouponInfos().isEmpty()) { + couponInfo = getCouponInfo(payDTO.getVipUserId(), payDTO.getShopId(), payDTO.getUserCouponInfos(), + orderInfo.getOrderAmount(), productIdSet); + } + + BigDecimal productDiscount = calcCartPriceWithCoupon(activateCartInfo, couponInfo, payDTO.getVipUserId(), orderInfo); + orderInfo.setProductCouponDiscountAmount(productDiscount); + + OrderPriceDTO priceDTO = createOrderDetailWithCoupon(activateCartInfo, orderInfo.getId(), payDTO.getShopId(), false); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + orderInfo.setSettlementAmount(priceDTO.getTotalAmount()); + orderInfo.setAmount(priceDTO.getTotalAmount()); + orderInfo.setOrderAmount(priceDTO.getTotalAmount()); + + // 计算订单优惠 + TbActivateOutRecord outRecord = calcOrderInfoDiscount(payDTO, orderInfo, couponInfo); + if (outRecord != null) { + couponInfo.getOutRecordList().add(outRecord); + } + + // 消耗优惠券并返回上次未使用的券 + consumeCoupon(couponInfo.getOutRecordList(), payDTO.getVipUserId(), orderInfo); + + orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo)); + // 更新订单信息 + + } + @Override +// @Transactional public Object pay(PayDTO payDTO) { return Utils.runFunAndCheckKey(() -> { long count = tbShopPayTypeMapper.selectCount(new LambdaQueryWrapper() @@ -1599,9 +1947,13 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("未知支付方式"); } - TbOrderInfo orderInfo = orderInfoMapper.selectById(payDTO.getOrderId()); + // 计算优惠券价格信息 + if (payDTO.getVipUserId() != null) { + calcDiscountAndUpdateInfo(payDTO, orderInfo); + } + if (ObjectUtil.isEmpty(orderInfo)) { throw new BadRequestException("订单不存在"); } @@ -1754,40 +2106,45 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object updateVip(UpdateVipDTO updateVipDTO) { - ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateVipDTO.getShopId(), updateVipDTO.getTableId()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .in(TbCashierCart::getStatus, "create", "return") - .eq(TbCashierCart::getShopId, updateVipDTO.getShopId()) - .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) - .and(q -> q.eq(TbCashierCart::getMasterId, updateVipDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId)); + Integer orderId = updateVipDTO.getOrderId(); + if (orderId == null) { + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateVipDTO.getShopId(), updateVipDTO.getTableId()); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .in(TbCashierCart::getStatus, "create", "return") + .eq(TbCashierCart::getShopId, updateVipDTO.getShopId()) + .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) + .and(q -> q.eq(TbCashierCart::getMasterId, updateVipDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId)); - if (!shopEatTypeInfoDTO.isTakeout()) { - queryWrapper.eq(TbCashierCart::getTableId, updateVipDTO.getTableId()); - } else { - queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) - .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); - } - - List tbCashierCarts = cashierCartMapper.selectList(queryWrapper.isNotNull(TbCashierCart::getOrderId)); - if (!tbCashierCarts.isEmpty()) { - Integer orderId = tbCashierCarts.get(0).getOrderId(); - if (updateVipDTO.getType() == 0) { - TbShopUser shopUser = tbShopUserMapper.selectById(updateVipDTO.getVipUserId()); - if (shopUser == null) { - throw new BadRequestException("用户信息不存在"); - } - return orderInfoMapper.update(null, new LambdaUpdateWrapper() - .eq(TbOrderInfo::getId, orderId) - .set(TbOrderInfo::getUserId, shopUser.getUserId()) - .set(TbOrderInfo::getMemberId, updateVipDTO.getVipUserId())); + if (!shopEatTypeInfoDTO.isTakeout()) { + queryWrapper.eq(TbCashierCart::getTableId, updateVipDTO.getTableId()); } else { - return orderInfoMapper.update(null, new LambdaUpdateWrapper() - .eq(TbOrderInfo::getId, orderId) - .set(TbOrderInfo::getUserId, null) - .set(TbOrderInfo::getMemberId, null)); + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) + .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); + } + + List tbCashierCarts = cashierCartMapper.selectList(queryWrapper.isNotNull(TbCashierCart::getOrderId)); + for (TbCashierCart item : tbCashierCarts) { + if (item.getOrderId() != null) { + orderId = item.getOrderId(); + } } } - return true; + + if (updateVipDTO.getType() == 0) { + TbShopUser shopUser = tbShopUserMapper.selectById(updateVipDTO.getVipUserId()); + if (shopUser == null) { + throw new BadRequestException("用户信息不存在"); + } + return orderInfoMapper.update(null, new LambdaUpdateWrapper() + .eq(TbOrderInfo::getId, orderId) + .set(TbOrderInfo::getUserId, shopUser.getUserId()) + .set(TbOrderInfo::getMemberId, updateVipDTO.getVipUserId())); + } else { + return orderInfoMapper.update(null, new LambdaUpdateWrapper() + .eq(TbOrderInfo::getId, orderId) + .set(TbOrderInfo::getUserId, null) + .set(TbOrderInfo::getMemberId, null)); + } } @@ -2025,9 +2382,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbProduct product = productMap.get(item.getProductId()); // 设置打包费 mpCashierCartService.update(new LambdaUpdateWrapper() - .eq(TbCashierCart::getId, item.getId()) + .eq(TbCashierCart::getId, item.getId()) .set(TbCashierCart::getPackFee, product.getPackFee() != null ? - product.getPackFee().multiply(BigDecimal.valueOf(item.getNumber())) : BigDecimal.ZERO) + product.getPackFee().multiply(BigDecimal.valueOf(item.getNumber())) : BigDecimal.ZERO) .set(TbCashierCart::getTableId, null) .set(TbCashierCart::getUseType, OrderUseTypeEnum.TAKEOUT.getValue()) .set(TbCashierCart::getIsPack, "true")); @@ -2121,7 +2478,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .add(returnPackFee)); orderDetail.setPackAmount(returnPackFee); orderDetail.setRefundNumber(returnNum); - orderDetail.setStatus("refunding"); + orderDetail.setStatus(isOnline ? "refunding" : "refund"); } if (returnAmount.compareTo(BigDecimal.ZERO) <= 0) { @@ -2141,7 +2498,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { returnOrder.setOrderNo(orderNo); returnOrder.setRefundAmount(returnAmount); returnOrder.setOrderType("return"); - returnOrder.setStatus("refunding"); + returnOrder.setStatus(isOnline ? "refunding" : "refund"); returnOrder.setUpdatedAt(null); returnOrder.setSystemTime(DateUtil.current()); returnOrder.setCreatedAt(DateUtil.current()); @@ -2221,12 +2578,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { if ("1".equals(shopInfo.getIsReturn())) { // TODO 密码校验 } - - HashMap returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, true); + String payType = orderInfo.getPayType(); + HashMap returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, "scanCode".equals(payType) || "wx_lite".equals(payType)); TbOrderInfo returnOrderInfo = (TbOrderInfo) returnInfoData.get("returnOrder"); BigDecimal returnAmount = (BigDecimal) returnInfoData.get("returnAmount"); String shopId = orderInfo.getShopId(); - String payType = orderInfo.getPayType(); // // 线上退款 orderInfo.setRefundAmount(returnOrderInfo.getRefundAmount()); @@ -2264,6 +2620,20 @@ public class TbShopTableServiceImpl implements TbShopTableService { long cartCount = mpCashierCartService.countByTableId(shopId, tableId, OrderStatusEnums.CREATE, OrderStatusEnums.RETURN); Map map = BeanUtil.beanToMap(tbShopTable, false, false); map.put("cartCount", cartCount); + + TbOrderInfo orderInfo = null; + if (StrUtil.isNotBlank(tbShopTable.getQrcode())) { + try { + + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(tbShopTable.getShopId(), tbShopTable.getQrcode()); + orderInfo = getCurrentOrder(shopEatTypeInfoDTO); + } catch (Exception e) { + log.info(e.getMessage()); + } + } + map.put("orderId", orderInfo == null ? null : orderInfo.getId()); + map.put("useType", orderInfo == null ? null : orderInfo.getUseType()); + map.put("masterId", orderInfo == null ? null : orderInfo.getMasterId()); return map; } return null; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/ActivateInInfoVO.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ActivateInInfoVO.java new file mode 100644 index 00000000..9bf08cea --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ActivateInInfoVO.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.vo; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class ActivateInInfoVO { + private Integer id; + private Integer couponId; + private Integer num; + // 1满减 2商品 + private Integer type; +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbUserCouponVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbUserCouponVo.java index 459ac51c..76af2bfb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbUserCouponVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbUserCouponVo.java @@ -2,11 +2,14 @@ package cn.ysk.cashier.vo; import lombok.Data; +import java.math.BigDecimal; import java.util.Date; @Data public class TbUserCouponVo { private Integer id; + private BigDecimal fullAmount; + private BigDecimal discountAmount; private Integer couponId; private Integer proId; //优惠券名称 @@ -20,6 +23,8 @@ public class TbUserCouponVo { private Long expireTime; private String useRestrictions; private boolean isUse = false; + //当前使用数量 + private Integer currentUseNum; public void setEndTime(Date endTime) {