| | |
| | | package com.yeshi.fanli.service.impl.redpack;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dao.mybatis.redpack.RedPackGiveRecordMapper;
|
| | | import com.yeshi.fanli.dto.msg.MsgRedPackGiveContentDTO;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
|
| | | import com.yeshi.fanli.entity.redpack.RedPackDetail;
|
| | | import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum;
|
| | | import com.yeshi.fanli.entity.redpack.RedPackGiveRecord;
|
| | | import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException;
|
| | | import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.TokenRecordService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TokenUtil;
|
| | | import com.yeshi.fanli.util.factory.RedPackDetailFactory;
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private TokenRecordService tokenRecordService;
|
| | | |
| | | @Resource
|
| | | private RedPackDetailService redPackDetailService;
|
| | | |
| | | @Resource
|
| | | private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
|
| | | |
| | | |
| | | @Override
|
| | | public RedPackGiveRecord selectByPrimaryKey(Long id) {
|
| | | return redPackGiveRecordMapper.selectByPrimaryKey(id);
|
| | | }
|
| | | |
| | | @Override
|
| | | public void updateByPrimaryKeySelective(RedPackGiveRecord record) {
|
| | | redPackGiveRecordMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<RedPackGiveRecord> overdueList(int count) {
|
| | | return redPackGiveRecordMapper.overdueList(count);
|
| | | }
|
| | | |
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void overdue(List<RedPackGiveRecord> list) throws Exception {
|
| | | if (list == null || list.size() == 0)
|
| | | return;
|
| | | |
| | | SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
| | | RedPackGiveRecord updateRecord = null;
|
| | | for (RedPackGiveRecord giveRecord: list) {
|
| | | updateRecord = new RedPackGiveRecord();
|
| | | updateRecord.setId(giveRecord.getId());
|
| | | updateRecord.setState(1);
|
| | | redPackGiveRecordMapper.updateByPrimaryKeySelective(updateRecord);
|
| | | |
| | | // 退回红包
|
| | | redPackBalanceService.addRedPack(giveRecord.getGiveUid(), giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersFail(giveRecord));
|
| | | |
| | | // 退回消息
|
| | | MsgRedPackGiveContentDTO givedto = new MsgRedPackGiveContentDTO();
|
| | | givedto.setTitle("你赠送的红包未被成功领取");
|
| | | givedto.setMoney("¥" + giveRecord.getAmount().setScale(2));
|
| | | givedto.setTime(sd.format(new Date()));
|
| | | givedto.setGiveTime(sd.format(giveRecord.getGiveTime()));
|
| | | userMoneyMsgNotificationService.redPackMsg(giveRecord.getGiveUid(), MsgTypeMoneyTypeEnum.redPackGiveBack, new Gson().toJson(givedto), "请到我的-红包查看");
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | |
| | | tips = tips.replace("{APP名称}", projectChineseName);
|
| | | }
|
| | | tips = tips.replace("{口令}", token).replace("{下载链接}", redPackConfigService.getValueByKey("app_down_link")).replace("{面额}",
|
| | | amount.setScale(0).toString());
|
| | | amount.setScale(2).toString());
|
| | |
|
| | | // 减少红包
|
| | | try {
|
| | | redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createGiveOthers(giveRecord, null, RedPackDetailTypeEnum.giveOthers));
|
| | | redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createGiveOthers(giveRecord));
|
| | | } catch (Exception e) {
|
| | | throw new RedPackGiveRecordException(1, "红包创建失败");
|
| | | }
|
| | | return tips;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public RedPackGiveRecord receiveFriendsGive(Long uid, Long id) throws RedPackGiveRecordException{
|
| | | RedPackGiveRecord giveRecord = redPackGiveRecordMapper.selectByPrimaryKey(id);
|
| | | if (giveRecord == null || giveRecord.getState() != RedPackGiveRecord.STATE_INIT)
|
| | | throw new RedPackGiveRecordException(1, "赠送记录失效或已被领取");
|
| | | |
| | | Date now = new Date();
|
| | | Date endTime = giveRecord.getEndTime();
|
| | | if (endTime != null && endTime.getTime() < now.getTime())
|
| | | throw new RedPackGiveRecordException(1, "红包已失效了");
|
| | | |
| | | giveRecord.setReceiveUid(uid);
|
| | | giveRecord.setReceiveTime(now);
|
| | | giveRecord.setState(RedPackGiveRecord.STATE_RECEIVE);
|
| | | // 领取人增加红包
|
| | | try {
|
| | | redPackBalanceService.addRedPack(uid, giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersReceive(giveRecord));
|
| | | } catch (Exception e) {
|
| | | throw new RedPackGiveRecordException(1, "红包领取失败");
|
| | | } |
| | | |
| | | // 更新赠送记录
|
| | | redPackGiveRecordMapper.updateByPrimaryKey(giveRecord);
|
| | | |
| | | try {
|
| | | String identifyCode = StringUtil.Md5(RedPackDetailTypeEnum.giveOthers.name() + ":" + giveRecord.getId());
|
| | | RedPackDetail redPackDetail = redPackDetailService.getByIdentifyCode(identifyCode);
|
| | | |
| | | RedPackDetail updateDetail = RedPackDetailFactory.createGiveOthersSucceed(redPackDetail.getId(), giveRecord);
|
| | | redPackDetailService.updateByPrimaryKeySelective(updateDetail);
|
| | | } catch (Exception e) {
|
| | | throw new RedPackGiveRecordException(1,"更新提现明细出错");
|
| | | }
|
| | | return giveRecord;
|
| | | }
|
| | |
|
| | | |
| | | }
|