From 0c51a577db337520452022d9d6a22b720ef858d4 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期二, 31 十二月 2024 14:13:01 +0800
Subject: [PATCH] 全部代码、数据库提交

---
 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java |  297 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 239 insertions(+), 58 deletions(-)

diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java
index 12a7eed..3152ce1 100644
--- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java
+++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java
@@ -1,31 +1,44 @@
 package com.xinquan.user.controller.client;
 
 
+import com.alibaba.nacos.common.utils.UuidUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xinquan.common.core.domain.R;
 import com.xinquan.common.core.utils.page.CollUtils;
 import com.xinquan.common.core.utils.page.PageDTO;
 import com.xinquan.common.core.web.domain.BaseModel;
+import com.xinquan.common.security.service.TokenService;
 import com.xinquan.common.security.utils.SecurityUtils;
+import com.xinquan.course.api.domain.Course;
+import com.xinquan.course.api.feign.RemoteCourseService;
+import com.xinquan.meditation.api.domain.Meditation;
+import com.xinquan.meditation.api.feign.RemoteMeditationService;
 import com.xinquan.order.api.domain.Order;
 import com.xinquan.order.api.feign.RemoteOrderService;
 import com.xinquan.system.api.domain.AppUser;
 import com.xinquan.system.api.domain.AppUserWalletRecord;
+import com.xinquan.system.api.domain.AppUserWithdraw;
 import com.xinquan.system.api.domain.vo.InviteRankListVO;
 import com.xinquan.system.api.domain.vo.OrderDetailVO;
 import com.xinquan.system.api.domain.vo.OrderListVO;
+import com.xinquan.system.api.model.LoginUser;
 import com.xinquan.user.api.domain.dto.UserBalanceDetailDTO;
+import com.xinquan.user.api.domain.dto.UserChildDTO;
 import com.xinquan.user.service.AppUserService;
 import com.xinquan.user.service.AppUserWalletRecordService;
+import com.xinquan.user.service.AppUserWithdrawService;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.expression.spel.ast.OpNE;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -45,7 +58,72 @@
     @Resource
     private AppUserWalletRecordService walletRecordService;
     @Resource
+    private AppUserWithdrawService appUserWithdrawService;
+    @Resource
+    private AppUserWalletRecordService appUserWalletRecordService;
+    @Resource
     private RemoteOrderService remoteOrderService;
+    @Resource
+    private RemoteCourseService remoteCourseService;
+    @Resource
+    private RemoteMeditationService remoteMeditationService;
+    // 用户获得分佣收益 新增一条余额明细记录
+    @PostMapping("/addBalanceRecord")
+    public R addBalanceRecord(@RequestBody AppUserWalletRecord appUserWalletRecord) {
+        appUserWalletRecordService.save(appUserWalletRecord);
+        if(appUserWalletRecord.getReason().contains("分佣")){
+            AppUser byId = appUserService.getById(appUserWalletRecord.getAppUserId());
+            byId.setBalance(byId.getBalance().add(appUserWalletRecord.getAmount()));
+            appUserService.updateById(byId);
+        }
+        if (appUserWalletRecord.getChangeType() == 2){
+            AppUser byId = appUserService.getById(appUserWalletRecord.getAppUserId());
+            byId.setBalance(byId.getBalance().subtract(appUserWalletRecord.getAmount()));
+            appUserService.updateById(byId);
+        }
+        return R.ok();
+    }
+
+    @PostMapping("/childUserList")
+    @ApiOperation(value = "用户详情-下级用户列表",tags = "管理后台-用户管理")
+    public R<PageDTO<AppUser>> childUserList(@RequestBody UserChildDTO dto) {
+        String startTime = null;
+        String endTime = null;
+        if (org.springframework.util.StringUtils.hasLength(dto.getTime())){
+            String[] split = dto.getTime().split(" - ");
+            startTime = split[0]+" 00:00:00";
+            endTime = split[1]+" 23:59:59";
+        }
+        String userId = dto.getUid();
+        LambdaQueryWrapper<AppUser> appUserWalletRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        appUserWalletRecordLambdaQueryWrapper.between(startTime!=null,BaseModel::getCreateTime,startTime,endTime);
+        appUserWalletRecordLambdaQueryWrapper.eq(AppUser::getInviteUserId, userId);
+        appUserWalletRecordLambdaQueryWrapper.like(StringUtils.hasLength(dto.getCellPhone()),AppUser::getCellPhone,dto.getCellPhone());
+        appUserWalletRecordLambdaQueryWrapper.like(StringUtils.hasLength(dto.getNickName()),AppUser::getNickname,dto.getNickName());
+        appUserWalletRecordLambdaQueryWrapper.eq(StringUtils.hasLength(dto.getUserStatus()),AppUser::getUserStatus,dto.getUserStatus());
+        appUserWalletRecordLambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime);
+        Page<AppUser> page = appUserService
+                .page(new Page<>(dto.getPageCurr(), dto.getPageSize()),appUserWalletRecordLambdaQueryWrapper);
+        if (CollUtils.isEmpty(page.getRecords())){
+            PageDTO<AppUser> empty = PageDTO.empty(page);
+            return R.ok(empty);
+        }
+        for (AppUser record : page.getRecords()) {
+            // 查询该用户带来收益
+            List<AppUserWalletRecord> list = appUserWalletRecordService.lambdaQuery()
+                    .eq(AppUserWalletRecord::getAppUserId, userId)
+                    .eq(AppUserWalletRecord::getChildAppUserId, record.getId()).list();
+            BigDecimal bigDecimal = new BigDecimal("0");
+            record.setMoney(new BigDecimal("0"));
+            for (AppUserWalletRecord appUserWalletRecord : list) {
+                if (appUserWalletRecord.getAmount()!=null && appUserWalletRecord.getChangeType() == 1){
+                    bigDecimal = bigDecimal.add(appUserWalletRecord.getAmount());
+                }
+                record.setMoney(bigDecimal);
+            }
+        }
+        return R.ok(PageDTO.of(page, AppUser.class));
+    }
     @PostMapping("/userBalanceList")
     @ApiOperation(value = "用户详情-余额明细",tags = "管理后台-用户管理")
     public R<PageDTO<OrderListVO>> userBalanceList(@RequestBody UserBalanceDetailDTO dto) {
@@ -53,8 +131,8 @@
         String endTime = null;
         if (org.springframework.util.StringUtils.hasLength(dto.getTime())){
             String[] split = dto.getTime().split(" - ");
-            startTime = split[0]+"00:00:00";
-            endTime = split[1]+"23:59:59";
+            startTime = split[0]+" 00:00:00";
+            endTime = split[1]+" 23:59:59";
         }
         String userId = dto.getUid();
         LambdaQueryWrapper<AppUserWalletRecord> appUserWalletRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -68,8 +146,24 @@
             PageDTO<OrderListVO> empty = PageDTO.empty(page);
             return R.ok(empty);
         }
+        for (AppUserWalletRecord record : page.getRecords()) {
+            if (record.getReason().equals("后台退款")){
+                record.setId(record.getOrderId());
+            }
+            if (record.getReason().contains("课程")){
+                record.setId(record.getOrderId());
+            }
+            if (record.getReason().contains("疗愈")){
+                record.setId(record.getOrderId());
+            }
+            if (record.getReason().contains("会员")){
+                record.setId(record.getOrderId());
+            }
+        }
         return R.ok(PageDTO.of(page, OrderListVO.class));
     }
+    @Autowired
+    private TokenService tokenService;
     /**
      * 爱心助力榜单-分页
      *
@@ -85,13 +179,17 @@
             @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer")
     })
     public R<PageDTO<OrderListVO>> balanceList(Integer state,Integer pageCurr, Integer pageSize) {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
         LambdaQueryWrapper<AppUserWalletRecord> appUserWalletRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
         if (state!=1){
-            appUserWalletRecordLambdaQueryWrapper.eq(AppUserWalletRecord::getChangeType, state);
+            appUserWalletRecordLambdaQueryWrapper.eq(AppUserWalletRecord::getChangeType, state-1);
         }
         appUserWalletRecordLambdaQueryWrapper.eq(AppUserWalletRecord::getAppUserId, userId);
+        appUserWalletRecordLambdaQueryWrapper.ne(AppUserWalletRecord::getAmount, 0);
         appUserWalletRecordLambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime);
         Page<AppUserWalletRecord> page = walletRecordService
                 .page(new Page<>(pageCurr, pageSize),appUserWalletRecordLambdaQueryWrapper);
@@ -114,46 +212,62 @@
         AppUserWalletRecord byId = walletRecordService.getById(uid);
         if (byId.getOrderId()!=null){
             if (byId.getReason().equals("提现")){
-                // 远程查询提现记录
+                AppUserWithdraw byId1 = appUserWithdrawService.getById(byId.getOrderId());
                 orderDetailVO.setType("提现");
+                orderDetailVO.setRemark("银行卡提现");
+                orderDetailVO.setPayOrderNo(byId1.getSerialNo());
+                orderDetailVO.setWithdrawType(byId1.getWithdrawType());
+                orderDetailVO.setAmount(byId1.getAmount());
+                orderDetailVO.setChangeType(byId.getChangeType());
+                orderDetailVO.setPaymentTime(byId1.getCreateTime());
             }else if (byId.getReason().equals("充值")){
                 Order one = remoteOrderService.getOrderById(byId.getOrderId()).getData();
-                if (byId.getChildAppUserId() == null && one!=null){
-                    if (one.getOrderFrom()!=null){
-                        switch (one.getOrderFrom()){
-                            case 1:
-                                orderDetailVO.setType("购买疗愈");
-                                break;
-                            case 2:
-                                orderDetailVO.setType("购买课程");
-                                break;
-                            case 3:
-                                orderDetailVO.setType("购买会员");
-                                break;
-                            case 4:
-                                orderDetailVO.setType("充值");
-                                break;
-                        }
+                if (one!=null){
+                    orderDetailVO.setType("充值");
+                    orderDetailVO.setPayType(one.getPayType());
+                    orderDetailVO.setPayOrderNo(one.getPayOrderNo());
+                    if (one.getPayType()==1){
+                        orderDetailVO.setRemark("微信支付");
+                    }else if (one.getPayType()==2){
+                        orderDetailVO.setRemark("支付宝支付");
+                    }else if (one.getPayType() == 3){
+                        orderDetailVO.setRemark("IOS内购");
                     }
-                    orderDetailVO.setRemark(one.getRemark());
+                    orderDetailVO.setChangeType(byId.getChangeType());
+                    orderDetailVO.setAmount(byId.getAmount());
                     orderDetailVO.setPaymentTime(one.getPaymentTime());
                     return R.ok(orderDetailVO);
-                }else if (byId.getChildAppUserId()!=null && one!=null){
+                }
+            }else if (byId.getReason().equals("分佣收益")){
+                Order one = remoteOrderService.getOrderById(byId.getOrderId()).getData();
+                if (byId.getChildAppUserId()!=null && one!=null){
                     orderDetailVO.setType("分佣");
                     orderDetailVO.setPayOrderNo(one.getPayOrderNo());
+                    orderDetailVO.setPaymentTime(byId.getCreateTime());
+                    orderDetailVO.setChangeType(byId.getChangeType());
+                    orderDetailVO.setAmount(byId.getAmount());
+                    orderDetailVO.setRemark("分佣收益");
                     if (one.getCommissionId()!=null){
                         AppUser appUserById = appUserService.getById(one.getCommissionId());
                         orderDetailVO.setUserName(appUserById.getNickname());
                         orderDetailVO.setAvatar(appUserById.getAvatar());
                     }
-                    return R.ok(new OrderDetailVO());
+                    return R.ok(orderDetailVO);
                 }
-            }else if (byId.getReason().equals("分佣收益")){
-
             }else if (byId.getReason().equals("提现回退")){
+                AppUserWithdraw byId1 = appUserWithdrawService.getById(byId.getOrderId());
+                orderDetailVO.setType("提现回退");
+                orderDetailVO.setPayOrderNo(byId1.getSerialNo());
+                orderDetailVO.setWithdrawType(byId1.getWithdrawType());
+                orderDetailVO.setAmount(byId1.getAmount());
+                orderDetailVO.setChangeType(byId.getChangeType());
+                orderDetailVO.setPaymentTime(byId1.getUpdateTime());
+                orderDetailVO.setRemark(byId1.getReason());
+                return R.ok(orderDetailVO);
+
+            }
         }
-        }
-        return R.ok();
+        return R.ok(orderDetailVO);
     }
 
     @PostMapping("/balanceDetail")
@@ -162,50 +276,117 @@
             @ApiImplicitParam(name = "id", value = "id", dataType = "Long", required = true),
     })
     public R<OrderDetailVO> balanceDetail(Long id) {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
         OrderDetailVO orderDetailVO = new OrderDetailVO();
         AppUserWalletRecord byId = walletRecordService.getById(id);
         if (byId.getOrderId()!=null){
-            if (byId.getReason().equals("提现")){
-                // 远程查询提现记录
+            if (byId.getReason().contains("提现")){
+                AppUserWithdraw byId1 = appUserWithdrawService.getById(byId.getOrderId());
                 orderDetailVO.setType("提现");
-            }else{
+                orderDetailVO.setPayOrderNo(byId1.getSerialNo());
+                orderDetailVO.setWithdrawType(byId1.getWithdrawType());
+                orderDetailVO.setAmount(byId1.getAmount());
+                orderDetailVO.setChangeType(byId.getChangeType());
+                orderDetailVO.setPaymentTime(byId1.getUpdateTime());
+                orderDetailVO.setRemark("银行卡提现");
+            }else if (byId.getReason().equals("充值")){
                 Order one = remoteOrderService.getOrderById(byId.getOrderId()).getData();
-                if (byId.getChildAppUserId() == null && one!=null){
-                    orderDetailVO.setId(id);
-                    if (one.getOrderFrom()!=null){
-                        switch (one.getOrderFrom()){
-                            case 1:
-                                orderDetailVO.setType("购买疗愈");
-                                break;
-                            case 2:
-                                orderDetailVO.setType("购买课程");
-                                break;
-                            case 3:
-                                orderDetailVO.setType("购买会员");
-                                break;
-                            case 4:
-                                orderDetailVO.setType("充值");
-                                break;
-                        }
-                    }
+                    orderDetailVO.setType("充值");
+                    orderDetailVO.setPayType(one.getPayType());
+                    orderDetailVO.setPayOrderNo(one.getBizOrderNo());
                     orderDetailVO.setRemark(one.getRemark());
+                    orderDetailVO.setChangeType(byId.getChangeType());
+                    orderDetailVO.setAmount(byId.getAmount());
                     orderDetailVO.setPaymentTime(one.getPaymentTime());
-                    return R.ok(orderDetailVO);
-                }else if (byId.getChildAppUserId()!=null && one!=null){
+                    if (one.getPayType()==1){
+                        orderDetailVO.setRemark("微信支付");
+                    }else if (one.getPayType()==2){
+                        orderDetailVO.setRemark("支付宝支付");
+                    }else if (one.getPayType() == 3){
+                        orderDetailVO.setRemark("IOS内购");
+                    }
+
+                return R.ok(orderDetailVO);
+            }else if (byId.getReason().equals("分佣收益")){
+                Order one = remoteOrderService.getOrderById(byId.getOrderId()).getData();
+                if (byId.getChildAppUserId()!=null && one!=null){
                     orderDetailVO.setType("分佣");
-                    orderDetailVO.setPayOrderNo(one.getPayOrderNo());
+                    orderDetailVO.setPayOrderNo(one.getBizOrderNo());
+                    orderDetailVO.setPaymentTime(byId.getCreateTime());
+                    orderDetailVO.setChangeType(byId.getChangeType());
+                    orderDetailVO.setAmount(byId.getAmount());
+                    orderDetailVO.setRemark(one.getRemark());
+                    orderDetailVO.setRemark("分佣收益");
                     if (one.getCommissionId()!=null){
-                        AppUser appUserById = appUserService.getById(one.getCommissionId());
+                        AppUser appUserById = appUserService.getById(one.getAppUserId());
                         orderDetailVO.setUserName(appUserById.getNickname());
                         orderDetailVO.setAvatar(appUserById.getAvatar());
                     }
-                    return R.ok(new OrderDetailVO());
+                    return R.ok(orderDetailVO);
                 }
+            }else if (byId.getReason().equals("提现回退")){
+                AppUserWithdraw byId1 = appUserWithdrawService.getById(byId.getOrderId());
+                orderDetailVO.setType("提现回退");
+                orderDetailVO.setPayOrderNo(byId1.getSerialNo());
+                orderDetailVO.setWithdrawType(byId1.getWithdrawType());
+                orderDetailVO.setAmount(byId1.getAmount());
+                orderDetailVO.setChangeType(byId.getChangeType());
+                orderDetailVO.setPaymentTime(byId1.getUpdateTime());
+                orderDetailVO.setRemark(byId1.getReason());
+                return R.ok(orderDetailVO);
+            }else if (byId.getReason().contains("课程")){
+                Order data = remoteOrderService.getOrderById(byId.getOrderId()).getData();
+                if (data!=null){
+                    Course data1 = remoteCourseService.getCourseById(data.getBusinessId()).getData();
+                    orderDetailVO.setType("课程购买");
+                    orderDetailVO.setPayOrderNo(data.getBizOrderNo());
+                    orderDetailVO.setAmount(data.getBalance());
+                    orderDetailVO.setChangeType(byId.getChangeType());
+                    orderDetailVO.setPaymentTime(data.getPaymentTime());
+                    if (data1!=null)orderDetailVO.setRemark("课程购买【"+data1.getCourseTitle()+"】");
+
+                }
+                return R.ok(orderDetailVO);
+
+            } else if (byId.getReason().contains("疗愈")) {
+                Order data = remoteOrderService.getOrderById(byId.getOrderId()).getData();
+                if (data!=null){
+                    Meditation data1 = remoteMeditationService.getMeditationById(data.getBusinessId()).getData();
+                    orderDetailVO.setType("疗愈购买");
+                    orderDetailVO.setPayOrderNo(data.getBizOrderNo());
+                    orderDetailVO.setAmount(data.getBalance());
+                    orderDetailVO.setChangeType(2);
+                    orderDetailVO.setPaymentTime(data.getPaymentTime());
+                    if (data1!=null)orderDetailVO.setRemark("疗愈购买【"+data1.getMeditationTitle()+"】");
+                }
+                return R.ok(orderDetailVO);
+            }else if (byId.getReason().contains("退款")){
+                Order data = remoteOrderService.getOrderById(byId.getOrderId()).getData();
+                if (data!=null){
+                    orderDetailVO.setType("后台退款");
+                    orderDetailVO.setPayOrderNo(data.getRefundCode());
+                    orderDetailVO.setAmount(byId.getAmount());
+                    orderDetailVO.setChangeType(1);
+                    orderDetailVO.setPaymentTime(data.getRefundTime());
+                    switch (data.getOrderFrom()){
+                        case 1:
+                            Meditation data1 = remoteMeditationService.getMeditationById(data.getBusinessId()).getData();
+                            if (data1!=null)orderDetailVO.setRemark("疗愈购买【"+data1.getMeditationTitle()+"】");
+                            break;
+                        case 2:
+                            Course data2 = remoteCourseService.getCourseById(data.getBusinessId()).getData();
+                            if (data2!=null)orderDetailVO.setRemark("课程购买【"+data2.getCourseTitle()+"】");
+                            break;
+                    }
+                }
+
             }
         }
-        return R.ok();
+        return R.ok(orderDetailVO);
     }
 }
 

--
Gitblit v1.7.1