From 2ed6444f45d227e2acc6de65c3e8b582440fb83a Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期四, 06 三月 2025 09:20:40 +0800
Subject: [PATCH] 迭代版本:2.28

---
 ruoyi-service/ruoyi-account/pom.xml                                                                    |    6 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java |  253 +++++++++++++++++++++++-----
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommissionDetail.java                   |   33 +++
 ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java                   |    6 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/SaveWithdrawalAccount.java                  |    1 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopWithdrawController.java         |   41 +++-
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java                 |   47 ++++
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java      |   17 +
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatementCopy.java       |    2 
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java             |    9 +
 a.json                                                                                                 |   15 +
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatement.java           |    4 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommission.java                         |   42 ++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopBalanceStatementDetailPage.java         |   13 +
 14 files changed, 414 insertions(+), 75 deletions(-)

diff --git a/a.json b/a.json
index 2b046d5..92807e7 100644
--- a/a.json
+++ b/a.json
@@ -1,6 +1,13 @@
 {
-  "address": "四川省成都市武侯区锦辉西二街天府新谷9号楼二单元1005A",
-  "days": 1,
-  "name": "张三",
-  "phone": "19912351325"
+  "total": "总数",
+  "pageSize": "每页大小",
+  "pageNum": "页码",
+  "records": [
+    {
+      "item": "项目名称",
+      "time": "时间",
+      "amount": "变动金额",
+      "type": "加或减标记: 1 加 2 减"
+    }
+  ]
 }
\ No newline at end of file
diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java
index 220e3da..9a165cd 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java
@@ -4,6 +4,7 @@
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.core.annotation.Excel;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiParam;
@@ -39,6 +40,7 @@
 
     @ApiModelProperty(value = "变动类型(1-消费,2-返佣,3-拉新,4-每日分享,5-每日签到,6-使用时长, 7-注册积分, 8-门店业绩," +
             "9-门店返佣,14-下级门店返佣,10-技师业绩,11-兑换商品,12-他人赠送,13-赠与他人,15-兑换券)")
+    @Excel(name = "变动类型", readConverterExp = "1=消费积分,2=返佣积分,3=拉新人积分,4=每日分享,5=每日签到,6=使用时长,7=注册积分,8=门店业绩,9=门店返佣,14=下级门店返佣,10=技师业绩,11=兑换商品,12=他人赠送,13=赠与他人,15=兑换券")
     @TableField("type")
     private Integer type;
 
@@ -48,6 +50,7 @@
 
     @ApiModelProperty(value = "变动金额")
     @TableField("variable_point")
+    @Excel(name = "变动金额")
     private Integer variablePoint;
 
     @ApiModelProperty(value = "变动后余额")
@@ -56,6 +59,7 @@
 
     @ApiModelProperty(value = "变动时间")
     @TableField("create_time")
+    @Excel(name = "变动时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime createTime;
 
     @ApiModelProperty(value = "变动用户id")
@@ -71,6 +75,7 @@
     private String extention;
 
     @ApiModelProperty(value = "用户名称")
+    @Excel(name = "用户名称")
     @TableField(exist = false)
     private String userName;
     @ApiModelProperty(value = "变动类型 0未变化1增加2减少")
@@ -78,6 +83,7 @@
     private Integer variableType;
 
     @ApiModelProperty(value = "联系电话")
+    @Excel(name = "联系电话")
     @TableField(exist = false)
     private String phone;
 
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatement.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatement.java
index 7aac151..1215ebb 100644
--- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatement.java
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatement.java
@@ -50,9 +50,9 @@
     @TableField(exist = false)
     @Excel(name = "联系电话")
     private String phone;
-    @ApiModelProperty(value = "变动类型(1=绑定门店分佣,2=下级门店分佣,3=核销门店服务费,4=提现)")
+    @ApiModelProperty(value = "变动类型(1=服务商分佣,2=高级服务商分佣,3=核销门店服务费,4=提现)")
     @TableField("type")
-    @Excel(name = "变更类型",readConverterExp = "1=绑定门店分佣,2=下级门店分佣,3=核销门店服务费,4=提现")
+    @Excel(name = "变更类型",readConverterExp = "1=服务商分佣,2=高级服务商分佣,3=核销门店服务费")
     private Integer type;
 
     @ApiModelProperty(value = "历史余额")
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatementCopy.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatementCopy.java
index f8eb465..cf86d9c 100644
--- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatementCopy.java
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/ShopBalanceStatementCopy.java
@@ -52,7 +52,7 @@
     private String phone;
     @ApiModelProperty(value = "变动类型(1=绑定门店分佣,2=下级门店分佣,3=核销门店服务费,4=提现)")
     @TableField("type")
-    @Excel(name = "变更类型",readConverterExp = "1=绑定门店分佣,2=下级门店分佣,3=核销门店服务费,4=提现")
+    @Excel(name = "变更类型",readConverterExp = "1=服务商分佣,2=高级服务商分佣,3=核销门店服务费,4=提现")
     private Integer type;
 
     @ApiModelProperty(value = "历史余额")
diff --git a/ruoyi-service/ruoyi-account/pom.xml b/ruoyi-service/ruoyi-account/pom.xml
index 2da90af..e46d473 100644
--- a/ruoyi-service/ruoyi-account/pom.xml
+++ b/ruoyi-service/ruoyi-account/pom.xml
@@ -132,6 +132,12 @@
             <artifactId>aliyun-sdk-oss</artifactId>
             <version>3.8.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-modules-other</artifactId>
+            <version>3.6.2</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
index 40d20b5..f511ca8 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
@@ -7,6 +7,9 @@
 import com.ruoyi.account.service.AppUserService;
 import com.ruoyi.account.service.AppUserShopService;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.system.api.model.LoginUser;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -24,6 +27,8 @@
     private AppUserShopService appUserShopService;
     @Resource
     private AppUserService appUserService;
+    @Resource
+    private TokenService tokenService;
 
 
 
@@ -75,4 +80,16 @@
     public void saveAppUserShop(@RequestBody AppUserShop appUserShop){
         appUserShopService.save(appUserShop);
     }
+
+    /**
+     * 校验登录用户是否为门店店长
+     */
+    @GetMapping("/checkUserIsShopManager")
+    public R<Boolean> checkUserIsShopManager(){
+        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        List<AppUserShop> list = appUserShopService.list(new LambdaQueryWrapper<AppUserShop>()
+                .eq(AppUserShop::getAppUserId, loginUserApplet.getUserid())
+                .eq(AppUserShop::getRoleType, 1));
+        return R.ok(!CollectionUtils.isEmpty(list));
+    }
 }
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index e0d7b19..bd0bbc2 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -543,6 +543,7 @@
             balanceChangeRecord.setCreateTime(LocalDateTime.now());
             balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord);
 
+
             //退回获得的消费积分
             //需要先检查会员等级时候回回退,使用回退后的会员等级查询配置
             Integer lavePoint = appUser.getLavePoint();
@@ -660,6 +661,10 @@
 
         order.setRefundStatus(2);
         order.setRefundTime(LocalDateTime.now());
+
+        shopPointClient.deleteShopPointCopy(order.getId(), Arrays.asList(1,2,3));
+        appUserGiveawayTemporaryClient.delAppUserGiveawayTemporary(order.getId());
+        shopGiveawayTemporaryClient.delShopGiveawayTemporary(order.getId());
         return R.ok();
     }
 
@@ -933,6 +938,10 @@
         if (order_express.size() > 0) {
             for (Long id : order_express) {
                 Order order = this.getById(id);
+                if (order == null){
+                    redisTemplate.opsForZSet().remove("order_express", id);
+                    continue;
+                }
                 if (order.getOrderStatus() != 2) {
                     redisTemplate.opsForZSet().remove("order_express", id);
                     continue;
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java
index a0d0585..4919d97 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java
@@ -1,27 +1,36 @@
 package com.ruoyi.other.controller;
 
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.domain.Shop;
 import com.ruoyi.other.api.domain.ShopBalanceStatement;
 import com.ruoyi.other.api.domain.ShopBalanceStatementCopy;
+import com.ruoyi.other.api.domain.ShopWithdraw;
 import com.ruoyi.other.dto.ShopBalanceDto;
 import com.ruoyi.other.mapper.ShopBalanceStatementCopyMapper;
 import com.ruoyi.other.mapper.ShopBalanceStatementMapper;
 import com.ruoyi.other.service.ShopBalanceStatementService;
 import com.ruoyi.other.service.ShopService;
+import com.ruoyi.other.service.ShopWithdrawService;
+import com.ruoyi.other.vo.ShopBalanceStatementDetailPage;
+import com.ruoyi.other.vo.ShopCommission;
+import com.ruoyi.other.vo.ShopCommissionDetail;
 import com.ruoyi.other.vo.ShopCommissionStatisticsVO;
 import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.api.feignClient.SysUserClient;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
+import org.apache.commons.lang3.tuple.Pair;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -29,13 +38,15 @@
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
-import java.util.Collection;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 import java.util.List;
-import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * <p>
- *  前端控制器
+ * 前端控制器
  * </p>
  *
  * @author luodangjia
@@ -57,10 +68,9 @@
     private SysUserClient sysUserClient;
     @Resource
     private ShopBalanceStatementCopyMapper shopBalanceStatementCopyMapper;
-    
-    
-    
-    
+    @Resource
+    private ShopWithdrawService shopWithdrawService;
+
 
     /**
      * 门店分佣统计
@@ -69,26 +79,28 @@
     @ApiOperation("门店分佣统计")
     public R<ShopCommissionStatisticsVO> shopCommissionStatistics(@ApiParam("页码") @RequestParam Integer pageNum,
                                                                   @ApiParam("每一页数据大小") Integer pageSize,
-                                                                  ShopBalanceStatement shopBalanceStatement){
+                                                                  ShopBalanceStatement shopBalanceStatement) {
         ShopCommissionStatisticsVO shopCommissionStatisticsVO = shopBalanceStatementService.shopCommissionStatistics(Page.of(pageNum, pageSize), shopBalanceStatement);
         return R.ok(shopCommissionStatisticsVO);
     }
+
     /**
      * 导出门店分佣统计
      */
     @GetMapping("/export")
     @ApiOperation("导出门店分佣统计")
-    public void export(HttpServletResponse response , ShopBalanceStatement shopBalanceStatement){
+    public void export(HttpServletResponse response, ShopBalanceStatement shopBalanceStatement) {
         ShopCommissionStatisticsVO shopCommissionStatisticsVO = shopBalanceStatementService.shopCommissionStatistics(Page.of(1, Integer.MAX_VALUE), shopBalanceStatement);
         IPage<ShopBalanceStatement> statementIPage = shopCommissionStatisticsVO.getStatementIPage();
         ExcelUtil<ShopBalanceStatement> util = new ExcelUtil<>(ShopBalanceStatement.class);
         util.exportExcel(response, statementIPage.getRecords(), "用户积分统计");
     }
+
     @GetMapping("/commissionStatistics/list")
     @ApiOperation(value = "门店余额明细", notes = "门店余额明细", tags = {"门店后台"})
     public R<Page<ShopBalanceStatement>> shopCommissionStatisticslist(@ApiParam("页码") @RequestParam Integer pageNum,
-                                                                  @ApiParam("每一页数据大小") Integer pageSize,
-                                                                  ShopBalanceStatement shopBalanceStatement){
+                                                                      @ApiParam("每一页数据大小") Integer pageSize,
+                                                                      ShopBalanceStatement shopBalanceStatement) {
         Long userid = tokenService.getLoginUser().getUserid();
         R<SysUser> sysUserR = sysUserClient.getSysUser(userid);
         SysUser sysUser = sysUserR.getData();
@@ -102,17 +114,17 @@
 
     }
 
-   
+
     @GetMapping("/commissionStatistics/info")
     @ApiOperation(value = "门店余额明细上方数据", notes = "门店余额明细", tags = {"门店后台"})
-    public R<ShopBalanceDto> shopCommissionStatisticsinfo(Integer type){
+    public R<ShopBalanceDto> shopCommissionStatisticsinfo(Integer type) {
         Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
         ShopBalanceDto dto = new ShopBalanceDto();
         Shop byId = shopService.getById(objectId);
 
-        if (type==null){
-            List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 3).list();
-            List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 1).list();
+        if (type == null) {
+            List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 3).list();
+            List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 1).list();
             BigDecimal bigDecimal1 = new BigDecimal(0);
             for (ShopBalanceStatement shopBalanceStatement : list) {
                 bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
@@ -122,20 +134,20 @@
             }
             dto.setBigDecimal1(bigDecimal1);
 
-            BigDecimal bigDecimal2= new BigDecimal(0);
+            BigDecimal bigDecimal2 = new BigDecimal(0);
             for (ShopBalanceStatement shopBalanceStatement : list) {
                 bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
             }
             dto.setBigDecimal2(bigDecimal2);
 
-            BigDecimal bigDecimal3= new BigDecimal(0);
+            BigDecimal bigDecimal3 = new BigDecimal(0);
             for (ShopBalanceStatement shopBalanceStatement : list1) {
                 bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
             }
             dto.setBigDecimal3(bigDecimal3);
 
-            List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 2).list();
-            BigDecimal bigDecimal4= new BigDecimal(0);
+            List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
+            BigDecimal bigDecimal4 = new BigDecimal(0);
             for (ShopBalanceStatement shopBalanceStatement : list2) {
                 bigDecimal4 = bigDecimal4.add(shopBalanceStatement.getVariableAmount());
             }
@@ -144,12 +156,12 @@
             dto.setBigDecimal5(byId.getCanWithdrawMoney());
             dto.setBigDecimal6(byId.getWithdrawMoney());
             return R.ok(dto);
-        }else{
-            switch (type){
+        } else {
+            switch (type) {
                 case 1:
                     // 关联用户分拥
                     BigDecimal bigDecimal = new BigDecimal("0");
-                    List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 1).list();
+                    List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 1).list();
                     for (ShopBalanceStatement shopBalanceStatement : list1) {
                         bigDecimal = bigDecimal.add(shopBalanceStatement.getVariableAmount());
                     }
@@ -158,8 +170,8 @@
                     break;
                 case 2:
                     // 下级门店分佣
-                    BigDecimal bigDecimal2= new BigDecimal(0);
-                    List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 2).list();
+                    BigDecimal bigDecimal2 = new BigDecimal(0);
+                    List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
                     for (ShopBalanceStatement shopBalanceStatement : list2) {
                         bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
                     }
@@ -168,8 +180,8 @@
                     break;
                 case 3:
                     // 服务费分佣
-                    List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId,objectId).eq(ShopBalanceStatement::getType, 3).list();
-                    BigDecimal bigDecimal3= new BigDecimal(0);
+                    List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 3).list();
+                    BigDecimal bigDecimal3 = new BigDecimal(0);
                     for (ShopBalanceStatement shopBalanceStatement : list) {
                         bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
                     }
@@ -186,72 +198,221 @@
     }
 
 
-
-
-
-
     @PostMapping("/getList")
-    public R<List<ShopBalanceStatement>> getList(@RequestBody ShopBalanceStatement shopBalanceStatement){
+    public R<List<ShopBalanceStatement>> getList(@RequestBody ShopBalanceStatement shopBalanceStatement) {
         return R.ok(shopBalanceStatementMapper.selectShopBalanceStatementList(shopBalanceStatement));
     }
-    
-    
+
+
     /**
      * 保存门店余额流水
+     *
      * @param shopBalanceStatement
      */
     @PostMapping("/saveShopBalanceStatement")
-    public void saveShopBalanceStatement(@RequestBody ShopBalanceStatement shopBalanceStatement){
+    public void saveShopBalanceStatement(@RequestBody ShopBalanceStatement shopBalanceStatement) {
         shopBalanceStatementService.save(shopBalanceStatement);
     }
 
     @PostMapping("/saveShopBalanceStatementCopy")
-    public void saveShopBalanceStatementCopy(@RequestBody ShopBalanceStatementCopy shopBalanceStatementCopy){
+    public void saveShopBalanceStatementCopy(@RequestBody ShopBalanceStatementCopy shopBalanceStatementCopy) {
         shopBalanceStatementCopyMapper.insert(shopBalanceStatementCopy);
     }
 
     @DeleteMapping("/deleteShopBalanceStatementCopy")
-    public R<Boolean> deleteShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type){
+    public R<Boolean> deleteShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) {
         shopBalanceStatementCopyMapper.delete(new LambdaQueryWrapper<ShopBalanceStatementCopy>().in(ShopBalanceStatementCopy::getType, type)
                 .eq(ShopBalanceStatementCopy::getObjectId, orderId));
         return R.ok();
     }
-    
-    
+
+
     @PostMapping("/getShopBalanceStatementCopy")
-    public R<List<ShopBalanceStatementCopy>> getShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type){
+    public R<List<ShopBalanceStatementCopy>> getShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) {
         List<ShopBalanceStatementCopy> shopBalanceStatementCopies = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().in(ShopBalanceStatementCopy::getType, type)
                 .eq(ShopBalanceStatementCopy::getObjectId, orderId));
         return R.ok(shopBalanceStatementCopies);
     }
-    
 
 
     /**
      * 获取门店流水数据
+     *
      * @param types
      * @param objectId
      * @return
      */
     @PostMapping("/getShopBalanceStatementList")
-    public R<List<ShopBalanceStatement>> getShopBalanceStatementList(@RequestParam("types") Collection<Integer> types, @RequestParam(value = "objectId",required = false) Long objectId){
+    public R<List<ShopBalanceStatement>> getShopBalanceStatementList(@RequestParam("types") Collection<Integer> types, @RequestParam(value = "objectId", required = false) Long objectId) {
         List<ShopBalanceStatement> list = shopBalanceStatementService.list(new LambdaQueryWrapper<ShopBalanceStatement>()
-                .eq(objectId != null,ShopBalanceStatement::getObjectId, objectId)
-                .in(types !=null && !types.isEmpty(),ShopBalanceStatement::getType, types));
+                .eq(objectId != null, ShopBalanceStatement::getObjectId, objectId)
+                .in(types != null && !types.isEmpty(), ShopBalanceStatement::getType, types));
         return R.ok(list);
     }
 
     @PostMapping("/getShopBalanceStatementList2")
     public R<List<ShopBalanceStatement>> getShopBalanceStatementList2(@RequestParam("type") Integer type, @RequestParam(value = "shopId") Integer shopId,
-                                                                      @RequestParam(value = "date") LocalDateTime date){
+                                                                      @RequestParam(value = "date") LocalDateTime date) {
         LambdaQueryWrapper<ShopBalanceStatement> queryWrapper = new LambdaQueryWrapper<ShopBalanceStatement>()
                 .eq(ShopBalanceStatement::getType, type)
                 .between(ShopBalanceStatement::getCreateTime, date.with(LocalTime.MIN), date.with(LocalTime.MAX));
-        if(null != shopId && 0 != shopId){
+        if (null != shopId && 0 != shopId) {
             queryWrapper.eq(ShopBalanceStatement::getShopId, shopId);
         }
         List<ShopBalanceStatement> list = shopBalanceStatementService.list(queryWrapper);
         return R.ok(list);
     }
+
+
+    /**
+     * 获取门店佣金
+     *
+     * @param shopId
+     * @return
+     */
+    @GetMapping("getShopCommission")
+    @ApiOperation(value = "获取门店佣金", notes = "获取门店佣金", tags = {"小程序-个人中心-门店管理-门店钱包"})
+    public R<ShopCommission> getShopCommission(@RequestParam("shopId") Integer shopId) {
+        // 合并查询逻辑
+        List<ShopBalanceStatementCopy> copies = shopBalanceStatementCopyMapper.selectList(
+                new LambdaQueryWrapper<ShopBalanceStatementCopy>()
+                        .eq(ShopBalanceStatementCopy::getShopId, shopId));
+
+        List<ShopBalanceStatement> statements = shopBalanceStatementService.list(
+                new LambdaQueryWrapper<ShopBalanceStatement>()
+                        .eq(ShopBalanceStatement::getShopId, shopId));
+
+        // 合并计算
+        Map<Integer, BigDecimal> result = Stream.concat(
+                copies.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount())),
+                statements.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount()))
+        ).collect(Collectors.groupingBy(
+                Pair::getKey,
+                Collectors.mapping(Pair::getValue, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
+        ));
+
+        // 待审核佣金
+        BigDecimal waitingAudit = shopWithdrawService.list(new LambdaQueryWrapper<ShopWithdraw>()
+                        .eq(ShopWithdraw::getShopId, shopId)
+                        .eq(ShopWithdraw::getAuditStatus, 0))
+                .stream()
+                .map(ShopWithdraw::getMoney)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        // 店铺信息校验
+        Shop shop = shopService.getById(shopId);
+        if (shop == null) {
+            throw new ServiceException("店铺不存在");
+        }
+
+        // 构建结果
+
+        List<ShopWithdraw> list = shopWithdrawService.lambdaQuery().eq(ShopWithdraw::getShopId, shopId)
+                .eq(ShopWithdraw::getAuditStatus, 0).list();
+        BigDecimal withdrawAuditMoney = list.stream().map(ShopWithdraw::getMoney).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
+
+        ShopCommission commission = new ShopCommission();
+        commission.setCanWithdrawCommission(shop.getCanWithdrawMoney());
+        commission.setWithdrawnCommission(shop.getWithdrawMoney().subtract(withdrawAuditMoney));
+        commission.setCommissionAmount(
+                result.getOrDefault(1, BigDecimal.ZERO)
+                        .add(result.getOrDefault(2, BigDecimal.ZERO)
+                                .add(result.getOrDefault(3, BigDecimal.ZERO))
+                        ));
+        commission.setWaitingAuditCommission(waitingAudit);
+        commission.setTotalAmount(commission.getCommissionAmount());
+
+        return R.ok(commission);
+    }
+
+    /**
+     * 获取门店佣金明细
+     */
+    @GetMapping("/getshopCommissionStatisticsDetail")
+    @ApiOperation(value = "门店返佣明细", notes = "门店返佣明细", tags = {"小程序-个人中心-门店管理-门店钱包"})
+    public R<ShopBalanceStatementDetailPage> shopCommissionStatisticsDetail(@ApiParam("店铺id") Integer shopId,
+                                                                            @ApiParam("类型") Integer type,
+                                                                            @ApiParam("开始时间") String createTime,
+                                                                            @ApiParam("页码") Integer pageNum,
+                                                                            @ApiParam("每一页数据大小") Integer pageSize) {
+
+        LocalDateTime startDate = null;
+        LocalDateTime endDate = null;
+        if (StringUtils.isNotEmpty(createTime)){
+            startDate = LocalDateTime.parse(createTime + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+            endDate = LocalDateTime.parse(createTime + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        }
+
+        List<ShopBalanceStatementCopy> copies = shopBalanceStatementCopyMapper.selectList(
+                new LambdaQueryWrapper<ShopBalanceStatementCopy>()
+                        .eq(ShopBalanceStatementCopy::getShopId, shopId)
+                        .eq(type != null, ShopBalanceStatementCopy::getType, type)
+                        .between(startDate != null && endDate != null, ShopBalanceStatementCopy::getCreateTime,
+                                startDate, endDate));
+
+        List<ShopBalanceStatement> statements = shopBalanceStatementService.list(
+                new LambdaQueryWrapper<ShopBalanceStatement>()
+                        .eq(ShopBalanceStatement::getShopId, shopId)
+                        .eq(type != null, ShopBalanceStatement::getType, type)
+                        .between(startDate != null && endDate != null, ShopBalanceStatement::getCreateTime,
+                                startDate, endDate));
+
+        Map<Integer, String> itemMap = new HashMap<>();
+        itemMap.put(1, "服务商分佣");
+        itemMap.put(2, "高级服务商分佣");
+        itemMap.put(3, "核销门店服务费");
+        itemMap.put(4, "提现");
+
+        List<ShopCommissionDetail> list = new ArrayList<>();
+        for (ShopBalanceStatementCopy copy : copies) {
+            ShopCommissionDetail detail = new ShopCommissionDetail();
+            detail.setItem(itemMap.get(copy.getType()));
+            detail.setTime(copy.getCreateTime());
+            detail.setAmount(copy.getVariableAmount());
+
+            BigDecimal beforeAmount = copy.getHistoricalBalance();
+            BigDecimal afterAmount = copy.getBalance();
+            if (beforeAmount.compareTo(afterAmount) > 0) {
+                detail.setType(2);
+            } else {
+                detail.setType(1);
+            }
+            list.add(detail);
+        }
+
+        for (ShopBalanceStatement statement : statements) {
+            ShopCommissionDetail detail = new ShopCommissionDetail();
+            detail.setItem(itemMap.get(statement.getType()));
+            detail.setTime(statement.getCreateTime());
+            detail.setAmount(statement.getVariableAmount());
+
+            BigDecimal beforeAmount = statement.getHistoricalBalance();
+            BigDecimal afterAmount = statement.getBalance();
+            if (beforeAmount.compareTo(afterAmount) > 0) {
+                detail.setType(2);
+            } else {
+                detail.setType(1);
+            }
+            list.add(detail);
+        }
+
+        // 按时间排序加手动分页
+        Integer total = list.size();
+        list.sort(Comparator.comparing(ShopCommissionDetail::getTime).reversed());
+        if (pageNum != null && pageSize != null) {
+            int fromIndex = (pageNum - 1) * pageSize;
+            int toIndex = Math.min(fromIndex + pageSize, list.size());
+            list = list.subList(fromIndex, toIndex);
+        }
+
+        ShopBalanceStatementDetailPage page = new ShopBalanceStatementDetailPage();
+        page.setRecords(list);
+        page.setTotal(total);
+        page.setPageSize(pageSize);
+        page.setPageNum(pageNum);
+        return R.ok(page);
+    }
+
+
 }
 
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
index 54cf198..ac1f16a 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -817,6 +817,21 @@
         return R.ok();
     }
 
+    @PostMapping("/saveWithdrawalAppletAccount")
+    @ApiOperation(value = "保存提现账户", tags = {"小程序-个人中心-门店管理-门店钱包"})
+    public R saveWithdrawalAppletAccount(@RequestBody SaveWithdrawalAccount saveWithdrawalAccount){
+
+        Shop shop = shopService.getById(saveWithdrawalAccount.getShopId());
+        if(null != shop){
+            shop.setReceiverAccountNoEnc(saveWithdrawalAccount.getReceiverAccountNoEnc());
+            shop.setReceiverNameEnc(saveWithdrawalAccount.getReceiverNameEnc());
+            shop.setReceiverAccountType(saveWithdrawalAccount.getReceiverAccountType());
+            shop.setReceiverBankChannelNo(saveWithdrawalAccount.getReceiverBankChannelNo());
+            shopService.updateById(shop);
+        }
+        return R.ok();
+    }
+
 
     /**
      * 获取所有门店
@@ -840,6 +855,21 @@
         }
         return R.fail("请先配置收款账户");
     }
+
+
+    @ResponseBody
+    @GetMapping("/verifyAppletConfiguration")
+    @ApiOperation(value = "判断是否有提现账户", tags = {"门店后台-财务管理-提现明细","小程序-个人中心-门店管理-门店钱包"})
+    public R verifyAppletConfiguration(Integer shopId){
+        Shop shop = shopService.getById(shopId);
+        if(StringUtils.hasLength(shop.getReceiverAccountNoEnc())){
+            return R.ok(true);
+        }
+        return R.ok(false);
+    }
+
+
+
 
 
 
@@ -874,7 +904,6 @@
 
     /**
      * 获取指定用户的服务商
-     * @param userId
      * @return
      */
     @GetMapping("/getServiceProvider")
@@ -909,13 +938,15 @@
         }
         return getSuperiorStore(appUser1, list, hierarchy, num, pid);
     }
-    
-    
-    
-    
-    
-    
-    
+
+
+
+
+
+
+
+
+
 
     /**
      * 获取指定用户的高级服务商
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopWithdrawController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopWithdrawController.java
index 9b46fcf..873101a 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopWithdrawController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopWithdrawController.java
@@ -7,16 +7,13 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.account.api.feignClient.AppUserClient;
-import com.ruoyi.account.api.model.AppUser;
-import com.ruoyi.account.api.model.BalanceChangeRecord;
-import com.ruoyi.account.api.model.WithdrawalRequests;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.domain.Shop;
 import com.ruoyi.other.api.domain.ShopBalanceStatement;
 import com.ruoyi.other.api.domain.ShopWithdraw;
-import com.ruoyi.other.dto.ShopBalanceDto;
 import com.ruoyi.other.service.ShopBalanceStatementService;
 import com.ruoyi.other.service.ShopService;
 import com.ruoyi.other.service.ShopWithdrawService;
@@ -148,21 +145,37 @@
     @GetMapping("/shop/with")
     @ApiOperation(value = "提现申请", notes = "提现申请列表", tags = {"门店后台"})
     public R shopwith(@RequestParam BigDecimal money){
-        Long userid = tokenService.getLoginUser().getUserid();
-        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
-        Integer objectId = sysUser.getObjectId();
-        Shop shop = shopService.getById(objectId);
+        LoginUser loginUser = tokenService.getLoginUser();
+        SysUser sysUser = sysUserClient.getSysUser(loginUser.getUserid()).getData();
+        baseWithdrawalApplication(money, sysUser.getUserId(), sysUser.getObjectId());
+        return R.ok();
+    }
+
+    /**
+     * 小程序端提现申请
+     */
+    @ApiOperation(value = "提现申请", notes = "提现申请", tags = {"小程序-个人中心-门店管理-门店钱包"})
+    @GetMapping("/withdrawalApplication")
+    @ResponseBody
+    public R withdrawalApplication(@RequestParam BigDecimal money, @RequestParam Integer shopId) {
+        LoginUser loginUser = tokenService.getLoginUserApplet();
+        baseWithdrawalApplication(money, loginUser.getUserid(), shopId);
+        return R.ok();
+    }
+
+    private void baseWithdrawalApplication(BigDecimal money, Long userId, Integer shopId) {
+        Shop shop = shopService.getById(shopId);
         if (money.compareTo(BigDecimal.ZERO)==0){
-            return R.fail("提现金额必须大于零");
+            throw new ServiceException("提现金额必须大于零");
         }
         if (money.compareTo(shop.getCanWithdrawMoney())>0){
-            return R.fail("提现金额不能大于可提现金额");
+            throw new ServiceException("提现金额不能大于可提现金额");
         }
         if(StringUtils.isEmpty(shop.getReceiverAccountNoEnc())){
-            return R.fail("请完善账户信息后再申请提现!");
+            throw new ServiceException("请完善账户信息后再申请提现!");
         }
         ShopWithdraw shopWithdraw = new ShopWithdraw();
-        shopWithdraw.setShopId(objectId);
+        shopWithdraw.setShopId(shopId);
         shopWithdraw.setMoney(money);
         shopWithdraw.setAuditStatus(0);
         shopWithdraw.setStatus(1);
@@ -183,14 +196,14 @@
         shopBalanceStatement.setHistoricalBalance(balance);
         shopBalanceStatement.setVariableAmount(money);
         shopBalanceStatement.setBalance(shop.getBalance());
-        shopBalanceStatement.setCreateUserId(sysUser.getUserId());
+        shopBalanceStatement.setCreateUserId(userId);
         shopBalanceStatement.setCreateTime(LocalDateTime.now());
         shopBalanceStatement.setObjectId(shopWithdraw.getId());
         shopBalanceStatementService.save(shopBalanceStatement);
-        return R.ok();
     }
 
 
+
     /**
      * 审核
      */
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/SaveWithdrawalAccount.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/SaveWithdrawalAccount.java
index a91eb6a..ac64691 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/SaveWithdrawalAccount.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/SaveWithdrawalAccount.java
@@ -9,6 +9,7 @@
  */
 @Data
 public class SaveWithdrawalAccount {
+	private Integer shopId;
 	
 	@ApiModelProperty("收款银行卡号")
 	private String receiverAccountNoEnc;
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopBalanceStatementDetailPage.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopBalanceStatementDetailPage.java
new file mode 100644
index 0000000..5b42ba8
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopBalanceStatementDetailPage.java
@@ -0,0 +1,13 @@
+package com.ruoyi.other.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class ShopBalanceStatementDetailPage {
+    private List<ShopCommissionDetail> records;
+    private Integer total;
+    private Integer pageSize;
+    private Integer pageNum;
+}
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommission.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommission.java
new file mode 100644
index 0000000..4251dab
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommission.java
@@ -0,0 +1,42 @@
+package com.ruoyi.other.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@Data
+@ApiModel(value = "门店分佣统计")
+public class ShopCommission {
+    /**
+     * 总金额
+     */
+    @ApiModelProperty(value = "总金额")
+    private BigDecimal totalAmount;
+
+    /**
+     * 可提现金额
+     */
+    @ApiModelProperty(value = "可提现金额")
+    private BigDecimal canWithdrawCommission;
+
+    /**
+     *  分佣金额
+     */
+    @ApiModelProperty(value = "分佣金额")
+    private BigDecimal commissionAmount;
+
+    /**
+     * 已提现金额
+     */
+    @ApiModelProperty(value = "已提现金额")
+    private BigDecimal withdrawnCommission;
+
+    /**
+     * 提现审核中金额
+     */
+    @ApiModelProperty(value = "提现审核中金额")
+    private BigDecimal waitingAuditCommission;
+}
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommissionDetail.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommissionDetail.java
new file mode 100644
index 0000000..de046dc
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/ShopCommissionDetail.java
@@ -0,0 +1,33 @@
+package com.ruoyi.other.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+@Data
+public class ShopCommissionDetail {
+    /**
+     * 明细名称
+     */
+    private String item;
+
+    /**
+     * 时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime time;
+
+    /**
+     * 变动金额
+     */
+    private BigDecimal amount;
+
+    /**
+     * 加或减标记: 1 加 2 减
+     */
+    private Integer type;
+
+}

--
Gitblit v1.7.1