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/cdn/CdnUserWalletController.java |  171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 171 insertions(+), 0 deletions(-)

diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/cdn/CdnUserWalletController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/cdn/CdnUserWalletController.java
new file mode 100644
index 0000000..3bcb27f
--- /dev/null
+++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/cdn/CdnUserWalletController.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
+ *
+ * https://www.mall4j.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+package com.yami.shop.api.controller.cdn;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.yami.shop.bean.model.CdnFlow;
+import com.yami.shop.bean.model.CdnUserWallet;
+import com.yami.shop.bean.model.User;
+import com.yami.shop.common.constants.DictConstant;
+import com.yami.shop.common.constants.ResultMsg;
+import com.yami.shop.common.response.ResponseEnum;
+import com.yami.shop.common.response.ServerResponseEntity;
+import com.yami.shop.common.util.PageParam;
+import com.yami.shop.common.util.PayUtil;
+import com.yami.shop.security.api.util.SecurityUtils;
+import com.yami.shop.service.CdnConfigService;
+import com.yami.shop.service.CdnFlowService;
+import com.yami.shop.service.CdnUserWalletService;
+import com.yami.shop.service.UserService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @author LGH
+ */
+@RestController
+@RequestMapping("/cdn/userWaller")
+@Tag(name = "用户钱包接口")
+@AllArgsConstructor
+public class CdnUserWalletController {
+
+    @Resource
+    private CdnFlowService cdnFlowService;
+    @Resource
+    private CdnUserWalletService cdnUserWalletService;
+    @Resource
+    private UserService userService;
+    @Resource
+    private CdnConfigService cdnConfigService;
+
+    @GetMapping("/page")
+    @Operation(summary = "分页查询用户钱包列表信息")
+    public ServerResponseEntity<IPage<CdnUserWallet>> getCdnUserWalletPage(PageParam<CdnUserWallet> page,CdnUserWallet cdnUserWallet) {
+        IPage<CdnUserWallet> userInvoicePage = cdnUserWalletService.getCdnUserWalletPage(page,cdnUserWallet );
+        return ServerResponseEntity.success(userInvoicePage);
+    }
+
+    @GetMapping("/info/{id}")
+    @Operation(summary = "通过用户钱包id查询用户钱包信息")
+    @Parameter(name = "id", description = "用户钱包id" , required = true)
+    public ServerResponseEntity<CdnUserWallet> getCdnUserWalletById(@PathVariable("id") Long id) {
+        CdnUserWallet card = cdnUserWalletService.getById(id);
+        return ServerResponseEntity.success(card);
+    }
+
+    @PostMapping("/getCdnUserWallets")
+    @Operation(summary = "获取用户钱包信息")
+    public ServerResponseEntity<List<CdnUserWallet>> getCdnUserWallets(@RequestBody  CdnUserWallet cdnUserWallet) {
+        List<CdnUserWallet> list = cdnUserWalletService.getCdnUserWallets(cdnUserWallet);
+        return ServerResponseEntity.success(list);
+    }
+    @PostMapping("/getCdnUserWallet")
+    @Operation(summary = "获取用户钱包信息")
+    public ServerResponseEntity<CdnUserWallet> getCdnUserWallet(@RequestBody  CdnUserWallet cdnUserWallet) {
+        CdnUserWallet returnWallet = cdnUserWalletService.getCdnUserWallet(cdnUserWallet);
+        return ServerResponseEntity.success(returnWallet);
+    }
+
+    @PostMapping("/exchange")
+    @Operation(summary = "红积分兑换绿积分")
+    public ServerResponseEntity<String> exchange(@RequestBody  CdnUserWallet cdnUserWallet) {
+        String userId = cdnUserWallet.getUserId();
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
+        List<CdnFlow> cdnFlow = cdnFlowService.list(Wrappers.<CdnFlow>lambdaQuery()
+                        .eq(CdnFlow::getUserId, userId)
+                        .eq(CdnFlow::getMemo, ResultMsg.RED_TRAN_GREEN)
+                        .eq(CdnFlow::getDelStatus, 0)
+                        .between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
+        if (!cdnFlow.isEmpty()){
+            return ServerResponseEntity.showFailMsg("1分钟内只能兑换一次");
+        }
+        if (cdnUserWallet.getPayPassword().length() > 6) {
+            return ServerResponseEntity.showFailMsg("密码格式错误");
+        }
+        //校验支付密码
+        User user = userService.getById(userId);
+        if (user != null) {
+            if (user.getPayPassword() == null) {
+                return ServerResponseEntity.showFailMsg("支付密码还未设置,请先设置支付密码");
+            }
+            String ppw = PayUtil.encryptWithMD5(cdnUserWallet.getPayPassword());
+            if (user.getPayPassword().equals(ppw)) {
+                //转换
+                if(null != cdnUserWallet.getMoney()){
+                    String multiple = cdnConfigService.selectValueByName("withdrawal_multiple");
+                    BigDecimal divide = cdnUserWallet.getMoney().divide(new BigDecimal(multiple));
+                    if(divide.scale() <= 0 || divide.stripTrailingZeros().scale() <= 0){
+//                String userId = "3";
+                        String msg = cdnUserWalletService.exchange(cdnUserWallet,userId);
+                        if(ResponseEnum.OK.getMsg().equals(msg)){
+                            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
+                        }else {
+                            return ServerResponseEntity.showFailMsg(msg);
+                        }
+                    }else{
+                        return ServerResponseEntity.showFailMsg(ResultMsg.ERROR_HUNDRED);
+                    }
+                }else{
+                    return ServerResponseEntity.showFailMsg(ResultMsg.EXCHANGE_MONEYIS_EMPTY);
+                }
+            }else{
+                return ServerResponseEntity.showFailMsg("支付密码错误");
+            }
+        } else {
+            return ServerResponseEntity.showFailMsg("用户不存在");
+        }
+    }
+
+    @PostMapping("/saveCdnUserWallet")
+    @Operation(summary = "新增用户钱包信息")
+    public ServerResponseEntity<String> saveCdnUserWallet(@RequestBody CdnUserWallet cdnUserWallet) {
+        Integer num = cdnUserWalletService.saveCdnUserWallet(cdnUserWallet);
+        if(num >0 ){
+            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
+        }else{
+            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
+        }
+    }
+
+    @PostMapping("/updateCdnUserWallet")
+    @Operation(summary = "修改用户钱包信息")
+    public ServerResponseEntity<String> updateCdnUserWallet(@RequestBody  CdnUserWallet cdnUserWallet) {
+        Integer num = cdnUserWalletService.updateCdnUserWallet(cdnUserWallet);
+        if(num >0 ){
+            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
+        }else{
+            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
+        }
+    }
+
+    @GetMapping("/delete/{id}")
+    @Operation(summary = "通过寄售流水id查询寄售信息")
+    @Parameter(name = "id", description = "寄售id" , required = true)
+    public ServerResponseEntity<String> deleteCdnUserWalletById(@PathVariable("id") Long id) {
+        Integer num = cdnUserWalletService.deleteCdnUserWallet(id);
+        if(num >0 ){
+            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
+        }else{
+            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
+        }
+    }
+
+}

--
Gitblit v1.9.3