ソースを参照

游戏费率递减修改

dos 3 ヶ月 前
コミット
1ae9f1de32

+ 34 - 2
game-business/src/main/java/com/game/business/controller/AppGameCommissionController.java

@@ -3,11 +3,13 @@ package com.game.business.controller;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.game.business.domain.AppUserAgent;
 import com.game.business.service.IAppUserAgentService;
 import com.game.common.core.domain.R;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -122,6 +124,7 @@ public class AppGameCommissionController extends BaseController
     @Log(title = "更新用户游戏佣金待遇", businessType = BusinessType.UPDATE)
     @PostMapping(value = "/updateSetting")
     @ApiOperation(value = "更新用户游戏佣金待遇", notes = "更新用户游戏佣金待遇")
+    @Transactional(rollbackFor = Exception.class)
     public R<String> updateSetting(@RequestBody AppGameCommission appGameCommission){
         AppGameCommission gameCommission = appGameCommissionService.selectAppGameCommissionById(appGameCommission.getId());
         AppUserAgent appUserAgent = appUserAgentService.selectInfo(appGameCommission.getUserId());
@@ -131,6 +134,12 @@ public class AppGameCommissionController extends BaseController
         if(appUserAgent.getPid().doubleValue() == 0){
             return R.fail("顶级账号禁止修改");
         }
+        if(null == appGameCommission.getGameRate()){
+            return R.fail("费率不能为空");
+        }
+        if(appGameCommission.getGameRate() < 0){
+            return R.fail("费率不能为负数");
+        }
         //查询上级
         AppGameCommission superQuery = new AppGameCommission();
         superQuery.setUserId(appUserAgent.getPid());
@@ -143,7 +152,7 @@ public class AppGameCommissionController extends BaseController
             }
         }
         //查询下级
-        AppGameCommission downQuery = new AppGameCommission();
+        /*AppGameCommission downQuery = new AppGameCommission();
         downQuery.setPid(appGameCommission.getUserId());
         downQuery.setGameId(appGameCommission.getGameId());
         List<AppGameCommission> downGameCommissions = appGameCommissionService.selectAppGameCommissionList(downQuery);
@@ -152,7 +161,7 @@ public class AppGameCommissionController extends BaseController
             if(appGameCommission.getGameRate() < rate){
                 return R.fail("修改失败,超过最小可修改值:" + rate);
             }
-        }
+        }*/
         AppGameCommission updateCommission = new AppGameCommission();
         if(null != gameCommission){
             updateCommission.setId(appGameCommission.getId());
@@ -167,6 +176,29 @@ public class AppGameCommissionController extends BaseController
             updateCommission.setPid(appUserAgent.getPid());
             appGameCommissionService.insertAppGameCommission(updateCommission);
         }
+        upRate(appUserAgent.getUserId(),appGameCommission.getGameRate(),appGameCommission.getGameId());
         return R.ok("修改成功");
     }
+
+    private void upRate(Long userId,Double rate,Long gameId){
+        double newRate = rate - 0.1;
+        if(newRate < 0){
+            newRate = 0.0;
+        }
+        //查询下级大于等于当前分红比例的用户
+        LambdaQueryWrapper<AppGameCommission> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(AppGameCommission::getPid,userId);
+        queryWrapper.eq(AppGameCommission::getGameId,gameId);
+        queryWrapper.gt(AppGameCommission::getGameRate,newRate);//查询费率大于当前值的用户
+        List<AppGameCommission> downAgents = appGameCommissionService.list(queryWrapper);
+        if(null != downAgents && downAgents.size() > 0){
+            for(AppGameCommission downAgent : downAgents){
+                AppGameCommission updateAgent = new AppGameCommission();
+                updateAgent.setId(downAgent.getId());
+                updateAgent.setGameRate(newRate);
+                appGameCommissionService.updateAppGameCommission(updateAgent);
+                upRate(downAgent.getUserId(),newRate,gameId);
+            }
+        }
+    }
 }

+ 3 - 0
game-business/src/main/java/com/game/business/controller/AppUserAgentController.java

@@ -599,6 +599,9 @@ public class AppUserAgentController extends BaseController
 
     private void upRate(Long userId,Double rate,Integer upType){
         double newRate = rate - 0.1;
+        if(newRate < 0){
+            newRate = 0.0;
+        }
         //查询下级大于等于当前分红比例的用户
         List<AppUserAgent> downAgents = appUserAgentService.selectDownByRate(userId,rate,upType);
         if(null != downAgents && downAgents.size() > 0){

+ 1 - 1
game-ui/src/views/business/user/index.vue

@@ -1882,7 +1882,7 @@ export default {
         spinner: 'el-icon-loading',
         background: 'rgba(0, 0, 0, 0.7)'
       });
-      setTimeout(function (){loading.close();},1000);
+      // setTimeout(function (){loading.close();},1000);
       updateGameCommissionAgent(this.appGameCommissionForm).then(response => {
         that.getList();
         that.$modal.msgSuccess("修改成功");