puzhibing
2022-08-22 1421f8e9c308c4741cb396309035009393b5b036
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.UserCouponRecordMapper;
import com.stylefeng.guns.modular.system.model.UserCouponRecord;
import com.stylefeng.guns.modular.system.service.IUserCouponRecordService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
 
@Service
public class UserCouponRecordServiceImpl extends ServiceImpl<UserCouponRecordMapper, UserCouponRecord> implements IUserCouponRecordService {
 
    @Resource
    private UserCouponRecordMapper userCouponRecordMapper;
 
 
    /**
     * 获取可用优惠券数量
     * @param uid
     * @param companyId
     * @param state
     * @param couponUseType
     * @return
     * @throws Exception
     */
    @Override
    public int queryAvailable(Integer uid, Integer companyId, Integer state, Integer couponUseType, Double money) throws Exception {
        return userCouponRecordMapper.queryAvailable(uid, companyId, state, couponUseType, money);
    }
 
 
    /**
     * 获取优惠券列表
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryCoupon(Integer uid, Integer companyId, Integer state, Integer couponUseType, Double money, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        return userCouponRecordMapper.queryCoupon(uid, companyId, state, couponUseType, money, pageNum, size);
    }
 
 
    /**
     * 获取优惠券列表
     * @param state
     * @param pageNum
     * @param size
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyCoupons(Integer state, Integer pageNum, Integer size, Integer uid) throws Exception {
        pageNum = (pageNum - 1) * size;
        return userCouponRecordMapper.queryMyCoupons(state, pageNum, size, uid);
    }
 
    /**
     * 删除优惠券
     * @param id
     * @param uid
     * @throws Exception
     */
    @Override
    public ResultUtil delMyCoupon(Integer id, Integer uid) throws Exception {
        UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(id);
        if(userCouponRecord.getUserId() != uid){
            return ResultUtil.error("您不能删除此优惠券");
        }
        userCouponRecordMapper.deleteById(id);
        return ResultUtil.success();
    }
 
 
    /**
     * 赠送优惠券
     * @param id
     * @param uid
     * @param userId
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil handselCoupon(Integer id, Integer uid, Integer userId) throws Exception {
        UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(id);
        if(userCouponRecord.getUserId() != uid){
            return ResultUtil.error("您不能赠送此优惠券");
        }
        if(userCouponRecord.getState() != 1){
            return ResultUtil.error("优惠券已无法使用");
        }
        userCouponRecord.setUserId(userId);
        userCouponRecordMapper.updateById(userCouponRecord);
        return ResultUtil.success();
    }
 
 
    /**
     * 修改过期优惠券状态
     * @throws Exception
     */
    @Override
    public void updateTimeOut() throws Exception {
        userCouponRecordMapper.updateTimeOut();
    }
}