zhibing.pu
2024-08-27 8f39e870ca9519d8a8190c038d15a030149de98e
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
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.model.UserInfo;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.service.IUserCouponRecordService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.DateUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
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;
 
    @Autowired
    private IUserInfoService userInfoService;
    
    @Resource
    private ISystemNoticeService systemNoticeService;
    
    
    
 
 
    /**
     * 获取可用优惠券数量
     * @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 language, Integer uid, Integer companyId, Integer state, Integer couponUseType, Double money, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        List<Map<String, Object>> list = userCouponRecordMapper.queryCoupon(uid, companyId, state, couponUseType, money, pageNum, size);
        for (Map<String, Object> map : list) {
            if(null != map.get("time")){
                String time = map.get("time").toString();
                map.put("time", DateUtil.conversionFormat(language, time));
            }
        }
        return list;
    }
 
 
    /**
     * 获取优惠券列表
     * @param state
     * @param pageNum
     * @param size
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyCoupons(Integer language, Integer state, Integer pageNum, Integer size, Integer uid) throws Exception {
        pageNum = (pageNum - 1) * size;
        List<Map<String, Object>> list = userCouponRecordMapper.queryMyCoupons(state, pageNum, size, uid);
        for (Map<String, Object> map : list) {
            if(null != map.get("time")){
                String time = map.get("time").toString();
                map.put("time", DateUtil.conversionFormat(language, time));
            }
        }
        return list;
    }
 
    /**
     * 删除优惠券
     * @param id
     * @param uid
     * @throws Exception
     */
    @Override
    public ResultUtil delMyCoupon(Integer id, Integer uid, Integer language) throws Exception {
        UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(id);
        if(userCouponRecord.getUserId().compareTo(uid) != 0){
            language = userInfoService.queryLanguage(uid, language);
            return ResultUtil.error(language == 1 ? "您不能删除此优惠券" : language == 2 ? "You cannot cancel the coupon." : "Vous ne pouvez pas annuler le coupon.");
        }
        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, Integer language) throws Exception {
        UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(id);
        language = userInfoService.queryLanguage(uid, language);
        UserInfo userInfo1 = userInfoService.selectById(uid);
        String nickName = userInfo1.getNickName();
        String phone = userInfo1.getPhone();
        if(userCouponRecord.getUserId().compareTo(uid) != 0){
            return ResultUtil.error(language == 1 ? "您不能赠送此优惠券" : language == 2 ? "You cannot gift the coupon." : "Vous ne pouvez pas offrir le coupon.");
        }
        if(userCouponRecord.getState() != 1){
            return ResultUtil.error(language == 1 ? "优惠券已无法使用" : language == 2 ? "The coupon is no more available." : "Le coupon n’est plus disponible.");
        }
        userCouponRecord.setUserId(userId);
        userCouponRecordMapper.updateById(userCouponRecord);
        UserInfo userInfo = userInfoService.selectById(userId);
        Integer language1 = userInfo.getLanguage();
        systemNoticeService.addSystemNotice(1, language1 == 1 ? nickName + "(" + phone + ")刚赠送您了一张GHS 5.00的优惠券,请查看账户。" : language1 == 2
                ? nickName + "(" + phone + ")just gifted a GHS 5.00 coupon to you, please check your account."
                : nickName + "(" + phone + ")vient de vous offrir un coupon de GHS 5.00, veuillez vérifier votre compte.", userId, 1);
        return ResultUtil.success();
    }
 
 
    /**
     * 修改过期优惠券状态
     * @throws Exception
     */
    @Override
    public void updateTimeOut() throws Exception {
        userCouponRecordMapper.updateTimeOut();
    }
}