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();
|
}
|
}
|