phpcjl
2024-12-05 6d1cd76c47e92f6fbb33a1274cfec4c88e09938f
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
package com.ruoyi.account.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.UserPoint;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.UserPointService;
import com.ruoyi.account.vo.UserPointDetailVO;
import com.ruoyi.account.vo.UserPointVO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.util.List;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/user-point")
@Api(tags = "个人积分")
public class UserPointController extends BaseController {
    @Resource
    private UserPointService userPointService;
    @Resource
    private AppUserService appUserService;
 
 
    /**
     * 获取个人积分
     */
    @GetMapping("/getUserPoint")
    @ApiOperation("获取个人积分")
    public R<UserPointVO> getUserPoint() {
        return R.ok(userPointService.getUserPoint(SecurityUtils.getUserId()));
    }
 
    /**
     * 获取变更明细
     */
    @GetMapping("/getUserPointDetail")
    @ApiOperation("获取变更明细")
    public TableDataInfo<UserPointDetailVO> getUserPointDetail(@ApiParam("指定日期") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date,
                                                               @ApiParam("变动类型(1=消费积分,2=返佣积分,3=拉新人积分,4=兑换商品 " +
                                                                       "5 = 门店业绩积分 6 =门店返佣积分7=技师业绩积分8 =转赠积分 9 =做工积分 " +
                                                                       "10 =注册积分)") Integer type) {
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        if (date != null) {
            // 将 createTime 设置为当天的开始时间 (00:00)
            startTime = date.atStartOfDay();
 
            // 使用 YearMonth 来获取该月的最后一天
            YearMonth yearMonth = YearMonth.from(date);
            LocalDate lastDayOfMonth = yearMonth.atEndOfMonth();
 
            // 将最后一天转换为 LocalDateTime,并设置为当天的最后一秒 (23:59:59.999)
            endTime = lastDayOfMonth.atTime(LocalTime.MAX);
        }
 
        startPage();
        List<UserPointDetailVO> list = userPointService.getUserPointDetail(SecurityUtils.getUserId(), startTime, endTime, type);
        return getDataTable(list);
    }
 
    /**
     * 转赠积分
     */
    @PostMapping("/transferPoint")
    @ApiOperation("转赠积分")
    public R<Void> transferPoint(@ApiParam("积分") BigDecimal point, @ApiParam("手机号") Long phone) {
        AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>()
                .eq(AppUser::getPhone, phone));
 
 
 
        if (null == appUser) {
            return R.fail("用户不存在");
        }
        return R.ok();
    }
 
 
    /**
     * 保存积分流水记录
     *
     * @param userPoint
     * @return
     */
    @PostMapping("/saveUserPoint")
    public R saveUserPoint(@RequestBody UserPoint userPoint) {
        userPointService.save(userPoint);
        return R.ok();
    }
}