luodangjia
2025-01-14 cb4e092579de93dae99b39bd104410b7e58040d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.ruoyi.account.controller;
import java.time.LocalDateTime;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.account.api.model.AgentApplication;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.UserChangeLog;
import com.ruoyi.account.dto.AgentQuery;
import com.ruoyi.account.api.model.VipSettingDto;
import com.ruoyi.account.service.AgentApplicationService;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.UserChangeLogService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.other.api.domain.BaseSetting;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.feignClient.BaseSettingClient;
import com.ruoyi.other.api.feignClient.VipSettingClient;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/agent-application")
public class AgentApplicationController extends BaseController {
    @Resource
    private AgentApplicationService agentApplicationService;
    @Resource
    private AppUserService appUserService;
    @Resource
    private BaseSettingClient baseSettingClient;
 
    @PostMapping("/apply")
    @ApiOperation(value = "会员申请", tags = {"会员中心-小程序"})
    public R<Void> apply(@RequestBody AgentApplication agentApplication) {
        agentApplicationService.apply(agentApplication);
        return R.ok();
    }
 
    @PostMapping("/page")
    @ApiOperation(value = "会员申请列表", tags = {"后台"})
    public R<IPage<AgentApplication>> page(@RequestBody AgentQuery agentQuery) {
        IPage<AgentApplication> agentApplicationIPage = agentApplicationService.pageList(agentQuery);
        for (AgentApplication record : agentApplicationIPage.getRecords()) {
            AppUser byId = appUserService.getById(record.getAppUserId());
            if (byId!=null){
                record.setVipId(byId.getVipId());
            }
        }
        return R.ok(agentApplicationIPage);
    }
    @Resource
    private VipSettingClient vipSettingClient;
    @GetMapping("/detail")
    @ApiOperation(value = "会员申请详情", tags = {"会员中心-小程序"})
    public R<AgentApplication> detail(@RequestParam Long id) {
        AgentApplication agentApplication = agentApplicationService.getById(id);
        R<VipSetting> vipSetting = vipSettingClient.getVipSetting(agentApplication.getApplicationVipId());
        VipSettingDto vipSettingDto = new VipSettingDto();
        BeanUtils.copyProperties(vipSetting.getData(),vipSettingDto);
        agentApplication.setVipSettingDto(vipSettingDto);
        return R.ok(agentApplication);
    }
    @Resource
    private UserChangeLogService userChangeLogService;
 
    @GetMapping("/auth")
    @ApiOperation(value = "会员申请审核", tags = {"会员中心-小程序"})
    public R<AgentApplication> auth(@RequestParam Long id, @ApiParam("2'已处理-同意',3'已处理-拒绝")Integer status,@ApiParam("处理意见") String remark) {
        AgentApplication byId = agentApplicationService.getById(id);
        byId.setStatus(status);
        byId.setRemark(remark);
        agentApplicationService.updateById(byId);
        AppUser byId1 = appUserService.getById(byId.getAppUserId());
        //插入等级变化数据
        UserChangeLog userChangeLog = new UserChangeLog();
        userChangeLog.setCreateTime(LocalDateTime.now());
        userChangeLog.setAppUserId(byId.getAppUserId());
        userChangeLog.setBeforeVipId(byId1.getVipId());
        userChangeLog.setAfterVipId(byId.getApplicationVipId());
        if (userChangeLog.getBeforeVipId()>userChangeLog.getAfterVipId()) {
            userChangeLog.setChangeType(0);
        }else {
            userChangeLog.setChangeType(1);
        }
        userChangeLogService.save(userChangeLog);
        //变更会员等级
        byId1.setVipId(byId.getApplicationVipId());
        appUserService.updateById(byId1);
 
        // 当用户为合伙人时,计算合伙人积分和培育积分
        Integer vipId = byId1.getVipId();
        if (vipId == 7){
            // 当前用户计算合伙人积分
            R<VipSetting> vipSetting = vipSettingClient.getVipSetting(vipId);
            setPoint(vipSetting, byId1, byId1.getShopPoint(), byId1.getSharePoint());
            // 上级计算培育积分
            Long inviteUserId = byId1.getInviteUserId();
            AppUser byId2 = appUserService.getById(inviteUserId);
            if (byId2 != null){
                setPoint(vipSetting, byId2, byId1.getShopPoint(), byId1.getSharePoint());
            }
        }
        return R.ok(byId);
    }
 
    private void setPoint(R<VipSetting> vipSetting, AppUser appUser, Integer shopPoint, Integer sharePoint) {
        VipSetting vipSettingData = vipSetting.getData();
        Integer vipLevelUpShopRole = vipSettingData.getVipLevelUpShopRole();
        if (vipLevelUpShopRole == 1){
            Integer vipLevelUpShop = vipSettingData.getVipLevelUpShop();
            Integer vipLevelUpShare = vipSettingData.getVipLevelUpShare();
            if (shopPoint >=vipLevelUpShop && sharePoint >= vipLevelUpShare) {
                R<BaseSetting> baseSetting = baseSettingClient.getBaseSetting(1);
                BaseSetting data = baseSetting.getData();
                if (data != null){
                    appUser.setPartPoint(Integer.parseInt(data.getContent()));
                    appUserService.updateById(appUser);
                }
            }
        }
    }
 
 
}