|
|
@@ -2,15 +2,24 @@ package org.springblade.gateway.goods_gateway.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import io.jsonwebtoken.lang.Assert;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springblade.common.utils.BeanPropertyUtil;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.gateway.active_gateway.exception.AppActiveProductException;
|
|
|
import org.springblade.gateway.goods_gateway.exception.HelpGoodsException;
|
|
|
import org.springblade.gateway.goods_gateway.service.AppHelpGoodsService;
|
|
|
+import org.springblade.gateway.point_gateway.enums.CmccPayStatus;
|
|
|
import org.springblade.gateway.point_gateway.enums.PointTypeEnum;
|
|
|
+import org.springblade.payment.cmcc.exception.CmccRequestException;
|
|
|
+import org.springblade.payment.cmcc.request.CmccDectOrderRequest;
|
|
|
+import org.springblade.payment.cmcc.request.CmccPlaceOrderRequest;
|
|
|
+import org.springblade.payment.cmcc.util.CmccUtil;
|
|
|
import org.springblade.sing.goods.entity.HelpGoods;
|
|
|
import org.springblade.sing.goods.service.IHelpGoodsService;
|
|
|
+import org.springblade.sing.point.entity.CmccPointRecord;
|
|
|
import org.springblade.sing.point.entity.PointRecord;
|
|
|
+import org.springblade.sing.point.service.ICmccPointRecordService;
|
|
|
import org.springblade.sing.point.service.IPointRecordService;
|
|
|
import org.springblade.sing.user.entity.LoginUser;
|
|
|
import org.springblade.sing.user.service.ILoginUserService;
|
|
|
@@ -27,6 +36,7 @@ import java.math.BigDecimal;
|
|
|
* @Modified By:
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
|
|
|
@Autowired
|
|
|
private ILoginUserService loginUserService;
|
|
|
@@ -34,20 +44,22 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
|
|
|
private IPointRecordService pointRecordService;
|
|
|
@Autowired
|
|
|
private IHelpGoodsService helpGoodsService;
|
|
|
+ @Autowired
|
|
|
+ private ICmccPointRecordService cmccPointRecordService;
|
|
|
|
|
|
/**
|
|
|
* 移动积分兑换道具
|
|
|
- * @param pointRecord
|
|
|
+ * @param cmccPointRecord
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void exchangeProps(PointRecord pointRecord) {
|
|
|
+ public void exchangeProps(CmccPointRecord cmccPointRecord,CmccDectOrderRequest cmccDectOrderRequest) {
|
|
|
//获取道具商品
|
|
|
- HelpGoods helpGoods = helpGoodsService.getById(pointRecord.getHelpGoodsId());
|
|
|
+ HelpGoods helpGoods = helpGoodsService.getById(cmccPointRecord.getHelpGoodsId());
|
|
|
Assert.notNull(helpGoods,"没有找到该道具");
|
|
|
//获取用户信息
|
|
|
- LoginUser loginUser = loginUserService.getById(pointRecord.getUserId());
|
|
|
+ LoginUser loginUser = loginUserService.getById(cmccPointRecord.getUserId());
|
|
|
Assert.notNull(loginUser,"没有找到该用户");
|
|
|
|
|
|
//判断用户今天购买该商品次数是否超过限制(-1标识不限制次数)
|
|
|
@@ -60,14 +72,14 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
|
|
|
.append(",\"%Y-%m-%d\")=\"")
|
|
|
.append(DateUtil.format(DateUtil.now(),"yyyy-MM-dd").trim()).append("\"").toString()));
|
|
|
//购买次数>=允许购买的次数
|
|
|
- if(count>=helpGoods.getTotal()){
|
|
|
- throw new HelpGoodsException("您今日购买次数达到上限");
|
|
|
+ if((cmccPointRecord.getNum().longValue()+count)>helpGoods.getTotal()){
|
|
|
+ throw new HelpGoodsException("您购买次数超过上限");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//判断是否赠送积分
|
|
|
if(ObjectUtils.isNotEmpty(helpGoods.getPufaPointRate()) && helpGoods.getPufaPointRate().intValue()>0){
|
|
|
- loginUser.setPufaPoint(loginUser.getPufaPoint().add(helpGoods.getPufaPointRate()));
|
|
|
+ loginUser.setPufaPoint(loginUser.getPufaPoint().add(helpGoods.getPufaPointRate().multiply(cmccPointRecord.getNum())));
|
|
|
|
|
|
//添加普法积分增加
|
|
|
PointRecord pufaPointRecord = new PointRecord();
|
|
|
@@ -80,7 +92,7 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
|
|
|
|
|
|
//判断是否赠送票数
|
|
|
if(ObjectUtils.isNotEmpty(helpGoods.getVotePointRate()) && helpGoods.getVotePointRate().intValue()>0){
|
|
|
- loginUser.setVoteCount(BigDecimal.valueOf(loginUser.getVoteCount()).add(helpGoods.getVotePointRate()).longValue());
|
|
|
+ loginUser.setVoteCount(BigDecimal.valueOf(loginUser.getVoteCount()).add(helpGoods.getVotePointRate().multiply(cmccPointRecord.getNum())).longValue());
|
|
|
}
|
|
|
|
|
|
//修改用户信息
|
|
|
@@ -88,13 +100,46 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
|
|
|
|
|
|
//TODO 对接移动积分接口
|
|
|
if(ObjectUtils.isNotEmpty(helpGoods.getPoint()) && helpGoods.getPoint().longValue()>0L){
|
|
|
+ //查询移动订单记录
|
|
|
+ CmccPointRecord oldCmccPointRecord = cmccPointRecordService.getOne(Wrappers.<CmccPointRecord>lambdaQuery().eq(CmccPointRecord::getOutOrderId, cmccPointRecord.getOutOrderId()));
|
|
|
+ Assert.notNull(oldCmccPointRecord,"没有找到移动支付订单");
|
|
|
+
|
|
|
//添加移动积分兑换记录
|
|
|
- PointRecord cmccPointRecord = new PointRecord();
|
|
|
- cmccPointRecord.setPoint(helpGoods.getPoint());
|
|
|
- cmccPointRecord.setHelpGoodsId(helpGoods.getId());
|
|
|
- cmccPointRecord.setPointType(PointTypeEnum.CMCC_POINT_EXCHANGE);
|
|
|
- cmccPointRecord.setUserId(loginUser.getId());
|
|
|
- Assert.isTrue(pointRecordService.save(cmccPointRecord),"兑换失败");
|
|
|
+ PointRecord pointRecord = new PointRecord();
|
|
|
+ pointRecord.setPoint(helpGoods.getPoint());
|
|
|
+ pointRecord.setHelpGoodsId(helpGoods.getId());
|
|
|
+ pointRecord.setUserId(loginUser.getId());
|
|
|
+ Assert.isTrue(pointRecordService.save(pointRecord),"兑换失败");
|
|
|
+
|
|
|
+ //设置状态为支付成功
|
|
|
+ oldCmccPointRecord.setPayStatus(CmccPayStatus.SUCCESS);
|
|
|
+
|
|
|
+ //更新支付状态
|
|
|
+ Assert.isTrue(cmccPointRecordService.updateById(oldCmccPointRecord));
|
|
|
+
|
|
|
+ // TODO 移动支付逻辑
|
|
|
+ cmccDectOrderRequest.setOutOrderId(cmccPointRecord.getOutOrderId());
|
|
|
+ try {
|
|
|
+ CmccUtil.dectOrder(cmccDectOrderRequest);
|
|
|
+ } catch (CmccRequestException e) {
|
|
|
+ throw new AppActiveProductException(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建道具订单
|
|
|
+ * @param cmccPointRecord
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createPropsOrder(CmccPointRecord cmccPointRecord, CmccPlaceOrderRequest cmccPlaceOrderRequest) {
|
|
|
+ //获取道具id
|
|
|
+ HelpGoods helpGoods = helpGoodsService.getById(cmccPointRecord.getHelpGoodsId());
|
|
|
+ Assert.notNull(helpGoods,"没有找到该道具");
|
|
|
+
|
|
|
+ //设置状态为待支付
|
|
|
+ cmccPointRecord.setPayStatus(CmccPayStatus.WAIT);
|
|
|
+
|
|
|
+ }
|
|
|
}
|