New file |
| | |
| | | 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.DateUtil; |
| | | 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,Integer language) throws Exception { |
| | | pageNum = (pageNum - 1) * size; |
| | | List<Map<String, Object>> list = integralOrderMapper.queryConvertHistory(pageNum, size, uid); |
| | | for (Map<String, Object> map : list) { |
| | | if(null != map.get("integral") && !"".equals(map.get("integral"))){ |
| | | String integral = String.valueOf(map.get("integral")); |
| | | if(language == 1){ |
| | | integral = integral + "积分"; |
| | | }else{ |
| | | // 积分的英语与法语翻译一致 |
| | | integral = integral + " points"; |
| | | } |
| | | map.put("integral",integral); |
| | | } |
| | | |
| | | if(null != map.get("time")){ |
| | | String time = map.get("time").toString(); |
| | | map.put("time", DateUtil.conversionFormat(language, time)); |
| | | } |
| | | |
| | | } |
| | | return list; |
| | | } |
| | | } |