gongzuming
2024-09-19 a768dc3daa04d35fedfbe75c0a59b9b2545b85c4
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
package com.mzl.flower.web.point;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.dto.request.point.ChangePointDTO;
import com.mzl.flower.dto.request.point.QueryCustomerPointDTO;
import com.mzl.flower.dto.request.point.QueryPointDetailDTO;
import com.mzl.flower.dto.request.supplier.UpdateSupplierDTO;
import com.mzl.flower.dto.response.content.AdvertisementDTO;
import com.mzl.flower.dto.response.point.CustomerPointDTO;
import com.mzl.flower.dto.response.point.CustomerPointDetailDTO;
import com.mzl.flower.service.point.CustomerPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.ValidationException;
import javax.validation.constraints.NotNull;
import java.util.List;
 
@RestController
@RequestMapping("/api/customer/point")
@Api(value = "会员积分", tags = "会员积分")
@Validated
@Slf4j
public class CustomerPointController extends BaseController {
 
 
    private final CustomerPointService customerPointService;
 
    public CustomerPointController(CustomerPointService customerPointService) {
        this.customerPointService = customerPointService;
    }
 
 
    @GetMapping("/page/list")
    @ApiOperation(value = "管理端-积分详细记录列表", notes = "管理端-商户积分详细记录列表")
    public ResponseEntity<ReturnDataDTO<Page<CustomerPointDetailDTO>>> queryCustomerDetails(QueryPointDetailDTO dto, Page page) {
        if(dto.getCustomerId() == null || dto.getCustomerId() == 0){
            throw new ValidationException("商户ID不能为空");
        }
        return returnData(R.SUCCESS.getCode(),customerPointService.queryCustomerDetails(dto, page));
    }
 
 
    @GetMapping("/page")
    @ApiOperation(value = "管理端-积分查询", notes = "用户端-积分查询")
    public ResponseEntity<ReturnDataDTO<Page<CustomerPointDTO>>> queryPage(QueryCustomerPointDTO dto, Page page)  {
        return returnData(R.SUCCESS.getCode(), customerPointService.queryPage(dto, page));
    }
 
    @PostMapping("/giveaway")
    @ApiOperation(value = "管理端-积分赠送", notes = "管理端-积分赠送")
    public ResponseEntity<ReturnDataDTO> giveawayPoint(@Validated @RequestBody ChangePointDTO dto) {
        if(dto.getPoint()<=0){
            throw new ValidationException("赠送积分必须大于0");
        }
        customerPointService.giveawayPoint(dto);
        return returnData(R.SUCCESS.getCode(),null);
    }
 
    @PostMapping("/deduction")
    @ApiOperation(value = "管理端-积分扣除", notes = "管理端-积分扣除")
    public ResponseEntity<ReturnDataDTO> deductionPoint(@Validated @RequestBody ChangePointDTO dto) {
        if(dto.getPoint()<=0){
            throw new ValidationException("扣除积分必须大于0");
        }
        customerPointService.deductionPoint(dto);
        return returnData(R.SUCCESS.getCode(),null);
    }
 
 
 
    @GetMapping("/list")
    @ApiOperation(value = "用户端-积分列表(花店积分列表)", notes = "管理端-积分列表(花店积分列表)")
    public ResponseEntity<ReturnDataDTO<Page<CustomerPointDetailDTO>>> myPointDetails(QueryPointDetailDTO dto, Page page) {
        dto.setUserId(SecurityUtils.getUserId());
        return returnData(R.SUCCESS.getCode(),customerPointService.queryCustomerDetails(dto, page));
    }
 
}