2.5
luo
2024-02-05 2f3d5e904ec44b807b35d4c1a9ceeeac590d8e90
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.IntegralOrderMapper;
import com.stylefeng.guns.modular.system.model.IntegralGoods;
import com.stylefeng.guns.modular.system.model.IntegralOrder;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IIntegralGoodsService;
import com.stylefeng.guns.modular.system.service.IIntegralOrderService;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
 
@Service
public class IntegralOrderServiceImpl extends ServiceImpl<IntegralOrderMapper, IntegralOrder> implements IIntegralOrderService {
 
    @Resource
    private IntegralOrderMapper integralOrderMapper;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private IIntegralGoodsService integralGoodsService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
 
    /**
     * 保存订单
     * @param integralOrder
     * @throws Exception
     */
    @Override
    public ResultUtil addIntegralOrder(IntegralOrder integralOrder,Integer language, Integer uid) throws Exception {
        IntegralGoods integralGoods = integralGoodsService.selectById(integralOrder.getGoodsId());
        UserInfo userInfo = userInfoService.selectById(uid);
        if(integralGoods.getIntegral().compareTo(userInfo.getIntegral()) > 0){
            return ResultUtil.error(language == 1 ? "兑换失败,积分不足!":(language == 2 ? "Redemption failed, insufficient points!":"Échange échoué, points insuffisants!"));
        }
        integralOrder.setInsertTime(new Date());
        integralOrder.setIntegral(integralGoods.getIntegral());
        integralOrder.setNum(1);
        integralOrder.setState(1);
        integralOrder.setUserId(uid);
        this.insert(integralOrder);
 
        userInfo.setIntegral(userInfo.getIntegral() - integralGoods.getIntegral());
        userInfoService.updateById(userInfo);
 
        //添加消息
        if(language == 1){
            systemNoticeService.addSystemNotice(1, "您使用" + integralGoods.getIntegral() + "积分成功兑换" + integralGoods.getName(), uid, 1);
        }else if (language == 2){
            systemNoticeService.addSystemNotice(1, "You redeemed " + integralGoods.getIntegral() + " points for the " + integralGoods.getName() + " successfully", uid, 1);
        }else {
            systemNoticeService.addSystemNotice(1, "Vous avez échangé " + integralGoods.getIntegral() + " points avec succès contre le " + integralGoods.getName(), uid, 1);
        }
        //添加交易明细
        transactionDetailsService.saveData(uid, "积分兑换", integralGoods.getIntegral().doubleValue(), 2, 2, 1, 7, integralOrder.getId());
        return ResultUtil.success();
    }
 
    /**
     * 获取历史记录
     * @param pageNum
     * @param size
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryConvertHistory(Integer pageNum, Integer size, Integer uid) throws Exception {
        pageNum = (pageNum - 1) * size;
        return integralOrderMapper.queryConvertHistory(pageNum, size, uid);
    }
}