From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001 From: lee <4766465@qq.com> Date: Wed, 18 Dec 2024 13:27:00 +0800 Subject: [PATCH] init --- yami-shop-api/src/main/java/com/yami/shop/api/controller/ShopBankCardController.java | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 168 insertions(+), 0 deletions(-) diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/ShopBankCardController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/ShopBankCardController.java new file mode 100644 index 0000000..5e544c4 --- /dev/null +++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/ShopBankCardController.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ +package com.yami.shop.api.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.yami.shop.bean.model.ShopBankCard; +import com.yami.shop.bean.model.ShopDetail; +import com.yami.shop.bean.model.ShopWithdrawCash; +import com.yami.shop.common.config.Constant; +import com.yami.shop.common.exception.YamiShopBindException; +import com.yami.shop.common.response.ServerResponseEntity; +import com.yami.shop.security.api.util.SecurityUtils; +import com.yami.shop.service.ShopBankCardService; +import com.yami.shop.service.ShopDetailService; +import com.yami.shop.service.ShopWithdrawCashService; +import com.yami.shop.sys.common.model.ShopEmployee; +import com.yami.shop.sys.common.service.ShopEmployeeService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Objects; + + +/** + * 商家提现申请信息 + * + * @author YXF + * * @date 2020-04-07 14:22:08 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/p/shop/shopBankCard" ) +@Tag(name = "银行卡接口") +public class ShopBankCardController { + + private final ShopBankCardService shopBankCardService; + private final ShopWithdrawCashService shopWithdrawCashService; + private final ShopDetailService shopDetailService; + private final ShopEmployeeService shopEmployeeService; + + @GetMapping("/getShopBankCardList") + @Operation(summary = "获取店铺下的银行卡列表" , description = "获取店铺下的银行卡列表") + public ServerResponseEntity<List<ShopBankCard>> getShopBankCardList() { + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); + if (Objects.isNull(shopDetail)){{ + return ServerResponseEntity.success(); + }} + Long shopId = shopDetail.getShopId(); + List<ShopBankCard> list = shopBankCardService.list(new LambdaQueryWrapper<ShopBankCard>().eq(ShopBankCard::getShopId, shopId).eq(ShopBankCard::getStatus,1)); + return ServerResponseEntity.success(list); + } + + @GetMapping + @Operation(summary = "根据银行卡id获取银行卡信息" , description = "根据银行卡id获取银行卡信息") + public ServerResponseEntity<ShopBankCard> getById(@RequestParam("shopBankCardId") Long shopBankCardId) { + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); + if (Objects.isNull(shopDetail)){{ + return ServerResponseEntity.success(); + }} + Long shopId = shopDetail.getShopId(); + ShopBankCard shopBankCard = shopBankCardService.getOne(Wrappers.lambdaQuery(ShopBankCard.class) + .eq(ShopBankCard::getShopBankCardId, shopBankCardId) + .eq(ShopBankCard::getShopId, shopId) + ); + return ServerResponseEntity.success(shopBankCard); + } + + @PutMapping + @Operation(summary = "更新银行卡信息" , description = "更新银行卡信息") + @PreAuthorize("@pms.hasPermission('shop:shopBankCard:update')") + public ServerResponseEntity<Void> update(@RequestBody @Valid ShopBankCard shopBankCard) { + shopBankCardService.updateByShopId(shopBankCard, shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId()); + return ServerResponseEntity.success(); + } + + @PostMapping + @Operation(summary = "添加单个银行卡信息" , description = "添加单个银行卡信息") + @PreAuthorize("@pms.hasPermission('shop:shopBankCard:save')") + public ServerResponseEntity<Long> save(@RequestBody @Valid ShopBankCard shopBankCard) { + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); + if (Objects.isNull(shopDetail)){{ + return ServerResponseEntity.success(); + }} + Long shopId = shopDetail.getShopId(); + shopBankCard.setShopId(shopId); + int count = shopBankCardService.count(new LambdaQueryWrapper<ShopBankCard>().eq(ShopBankCard::getShopId, shopId).eq(ShopBankCard::getStatus, 1)); + if (count >= Constant.MAX_SHOP_BANK_CARD) { + throw new YamiShopBindException("yami.shop.max.card.num"); + } + return ServerResponseEntity.success(shopBankCardService.insertSelective(shopBankCard)); + } + + @PutMapping("/setDefault") + @Operation(summary = "设置为默认银行卡" , description = "设置为默认银行卡") + @PreAuthorize("@pms.hasPermission('shop:shopBankCard:default')") + public ServerResponseEntity<Void> setDefault(@RequestBody @Valid ShopBankCard shopBankCard) { + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); + if (Objects.isNull(shopDetail)){{ + return ServerResponseEntity.success(); + }} + Long shopId = shopDetail.getShopId(); + shopBankCardService.setDefault(shopBankCard.getShopBankCardId(),shopId); + return ServerResponseEntity.success(); + } + + @PutMapping("/setNotDefault") + @Operation(summary = "取消默认银行卡" , description = "取消默认银行卡") + @PreAuthorize("@pms.hasPermission('shop:shopBankCard:noDefault')") + public ServerResponseEntity<Void> setNotDefault(@RequestParam(value = "shopBankCardId") Long shopBankCardId) { + shopBankCardService.setNotDefault(shopBankCardId, shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId()); + return ServerResponseEntity.success(); + } + + @DeleteMapping("/{shopBankCardId}") + @Operation(summary = "根据银行卡id删除银行卡信息" , description = "根据银行卡id删除银行卡信息") + @PreAuthorize("@pms.hasPermission('shop:shopBankCard:delete')") + public ServerResponseEntity<Void> removeById(@PathVariable("shopBankCardId") Long shopBankCardId) { + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); + if (Objects.isNull(shopDetail)){{ + return ServerResponseEntity.success(); + }} + Long shopId = shopDetail.getShopId(); + ShopBankCard shopBankCard = shopBankCardService.getById(shopBankCardId); + if (Objects.equals(shopBankCard.getIsDefault(),1)){ + // 不能删除默认银行卡 + throw new YamiShopBindException("yami.shop.cannot.delete.card"); + } + // 检查是否是最后一张银行卡 + if (shopBankCardService.count(Wrappers.lambdaQuery(ShopBankCard.class).eq(ShopBankCard::getShopId, shopId).eq(ShopBankCard::getStatus, 1)) == 1) { + throw new YamiShopBindException("yami.shop.least.one.card"); + } + int count = shopWithdrawCashService.count(new LambdaQueryWrapper<ShopWithdrawCash>() + .eq(ShopWithdrawCash::getShopBankCardId, shopBankCardId).eq(ShopWithdrawCash::getStatus, 0)); + if(count > 0){ + // 正在用于申请提现的银行卡不能删除 + throw new YamiShopBindException("yami.shop.cannot.delete.check"); + } + // 进行逻辑删除 + shopBankCardService.update(new LambdaUpdateWrapper<ShopBankCard>().set(ShopBankCard::getStatus,-1).eq(ShopBankCard::getShopBankCardId,shopBankCardId).eq(ShopBankCard::getShopId, shopId)); + return ServerResponseEntity.success(); + } + + @PostMapping("/saveAndApplyShop") + @Operation(summary = "批量保存店铺银行卡信息并提交店铺审核信息" , description = "批量保存店铺银行卡信息并提交店铺审核信息") + public ServerResponseEntity<Void> saveAndApplyShop(@Valid @RequestBody List<ShopBankCard> shopBankCards) { + String id = SecurityUtils.getUser().getUserId(); + ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(id); + Long shopId = shopDetail.getShopId(); + Long employeeId = shopEmployeeService.getShopEmployeeByUserId(shopId); + shopBankCardService.insertBatchAndSubmitApply(shopBankCards, shopId, employeeId,id); + return ServerResponseEntity.success(); + } +} -- Gitblit v1.9.3