Pu Zhibing
2024-12-24 af243c209737fbae0671638f0e73a9e670f3d6fa
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.ruoyi.other.controller;
import java.time.LocalDateTime;
 
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.account.api.feignClient.AppUserCarClient;
import com.ruoyi.account.api.feignClient.AppUserClient;
import com.ruoyi.account.api.model.TAppUser;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.THtml;
import com.ruoyi.other.api.domain.TIntegralRule;
import com.ruoyi.other.api.domain.TVip;
import com.ruoyi.other.api.dto.SaveHtml;
import com.ruoyi.other.service.THtmlService;
import com.ruoyi.other.service.TIntegralRuleService;
import com.ruoyi.other.service.TVipService;
import com.ruoyi.system.api.model.LoginUserApplet;
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.web.bind.annotation.*;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-08-06
 */
@RestController
@RequestMapping("/integral")
public class TIntegralRuleController {
    @Autowired
    private THtmlService htmlService;
    @Autowired
    private TIntegralRuleService integralRuleService;
    @Autowired
    private AppUserClient appUserClient;
 
 
    /**
     * 远程调用 获取首次添加车辆可获得积分
     * @return
     */
    @PostMapping("/getAddCarIntegral")
    public R<Integer> getAddCarIntegral() {
        TIntegralRule one = integralRuleService.getOne(null);
        String addVehiclesEarnsPoints = one.getAddVehiclesEarnsPoints();
        JSONObject jsonObject = JSON.parseObject(addVehiclesEarnsPoints);
        Integer point = 0;
        //增加车牌50分,必填
        point += jsonObject.getInteger("num1");
        point += jsonObject.getInteger("num2");
        point += jsonObject.getInteger("num3");
        point += jsonObject.getInteger("num4");
        return R.ok(point);
    }
    @Autowired
    private TokenService tokenService;
    @Autowired
    private TVipService vipService;
    
    
    @RequiresPermissions(value = {"/IntegralSetting"}, logical = Logical.OR)
    @GetMapping("/getSet")
    @ApiOperation(tags = {"管理后台-积分管理"},value = "获取积分设置")
    public R<TIntegralRule> getSet() {
        TIntegralRule res = integralRuleService.getOne(new QueryWrapper<>());
        return R.ok(res);
    }
    
    
    
    @GetMapping("/getSet1")
    @ApiOperation(tags = {"小程序-个人中心-签到"},value = "获取积分设置")
    public R<TIntegralRule> getSet1() {
        TIntegralRule res = integralRuleService.getOne(new QueryWrapper<>());
        LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet();
        res.setIsDouble(0);
        if (loginUserApplet!=null){
            TAppUser data = appUserClient.getUserById(loginUserApplet.getUserId()).getData();
            if (data.getVipEndTime()!=null && data.getVipEndTime().isAfter(LocalDateTime.now())){
                TVip byId = vipService.getById(data.getVipId());
                Integer doubleIntegration = byId.getDoubleIntegration();
                if (doubleIntegration!=null&&doubleIntegration==1){
                    res.setIsDouble(1);
                }
            }
        }
        return R.ok(res);
    }
    
    
    @RequiresPermissions(value = {"/IntegralSetting"}, logical = Logical.OR)
    @PostMapping("/saveSet")
    @ApiOperation(tags = {"管理后台-积分管理"},value = "保存积分设置")
    @Log(title = "【积分管理】保存积分设置", businessType = BusinessType.INSERT)
    public R saveSet(@RequestBody TIntegralRule dto) {
        TIntegralRule one = integralRuleService.getOne(null);
        if (one!=null){
            dto.setId(one.getId());
            integralRuleService.saveOrUpdate(dto);
        }else{
            integralRuleService.saveOrUpdate(dto);
        }
        return R.ok();
    }
    
    
    
    @RequiresPermissions(value = {"/vipSetting/html"}, logical = Logical.OR)
    @GetMapping("/getInfo")
    @ApiOperation(tags = {"管理后台-积分管理"},value = "type 1=积分规则说明," +
            "2=会员折扣说明," +
            "3=优惠券说明," +
            "4=双倍积分说明," +
            "5=商城专享价说明," +
            "6=会员协议," +
            "7=用户协议," +
            "8=隐私协议," +
            "9=邀请好友说明," +
            "10=资质证明," +
            "11=开票说明")
    public R<String> getInfo(Integer type) {
        THtml g = htmlService.getOne(new QueryWrapper<THtml>().eq("type",type));
        if (g == null){
            return R.ok("");
        }
        return R.ok(g.getContent());
    }
    
    
    
    @RequiresPermissions(value = {"/vipSetting/html"}, logical = Logical.OR)
    @PostMapping("/saveInfo")
    @ApiOperation(tags = {"管理后台-积分管理"},value = "保存积分说明")
    @Log(title = "【积分管理】保存积分说明", businessType = BusinessType.INSERT)
    public R saveInfo(@RequestBody SaveHtml dto) {
        THtml g = htmlService.getOne(new QueryWrapper<THtml>().eq("type",dto.getType()));
        if (g == null){
            THtml tHtml = new THtml();
            tHtml.setType(dto.getType());
            tHtml.setContent(dto.getInfo());
            htmlService.save(tHtml);
        }else{
            g.setContent(dto.getInfo());
            htmlService.updateById(g);
        }
        return R.ok();
    }
    
    
    @GetMapping("/getIntegralRule")
    @ApiOperation(tags = {"小程序-充电记录"},value = "获取积分规则设置")
    public AjaxResult<String> getIntegralRule(){
        TIntegralRule one = integralRuleService.getOne(null);
        return AjaxResult.success(one);
    }
}