|
|
@@ -14,7 +14,7 @@ import org.springblade.core.log.logger.BladeLogger;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.gateway.goods_gateway.exception.HelpGoodsException;
|
|
|
import org.springblade.gateway.point_gateway.enums.PointTypeEnum;
|
|
|
-import org.springblade.gateway.point_gateway.excetion.PointException;
|
|
|
+import org.springblade.gateway.point_gateway.exception.PointExchangeException;
|
|
|
import org.springblade.gateway.point_gateway.service.PointExchangeService;
|
|
|
import org.springblade.sing.goods.entity.GoodsOrder;
|
|
|
import org.springblade.sing.goods.entity.PointGoods;
|
|
|
@@ -25,7 +25,6 @@ import org.springblade.sing.point.entity.PointRecord;
|
|
|
import org.springblade.sing.point.entity.UserPufaPoint;
|
|
|
import org.springblade.sing.point.service.IPointRecordService;
|
|
|
import org.springblade.sing.point.service.IUserPufaPointService;
|
|
|
-import org.springblade.sing.user.entity.LoginUser;
|
|
|
import org.springblade.sing.user.entity.UserAddress;
|
|
|
import org.springblade.sing.user.service.ILoginUserService;
|
|
|
import org.springblade.sing.user.service.IUserAddressService;
|
|
|
@@ -81,7 +80,7 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void pointExchange(YeepayOrder yeepayOrder) {
|
|
|
- UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
+/* UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
Assert.notNull(user, "用户不存在");
|
|
|
PointGoods goods = pointGoodsService.getById(yeepayOrder.getPointGoodsId());
|
|
|
Assert.notNull(goods, "商品不存在");
|
|
|
@@ -95,14 +94,14 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
.eq(GoodsOrder::getPhone, yeepayOrder.getPhone()).eq(GoodsOrder::getPointGoodsId, yeepayOrder.getPointGoodsId())).size();
|
|
|
System.out.println(size);
|
|
|
if ((yeepayOrder.getNum() + size) > goods.getLimitBuy()) {
|
|
|
- throw new PointException("超过限购数量");
|
|
|
+ throw new PointExchangeException("超过限购数量");
|
|
|
}
|
|
|
}
|
|
|
if (goods.getRemain() < yeepayOrder.getNum()) {
|
|
|
- throw new PointException("库存不足");
|
|
|
+ throw new PointExchangeException("库存不足");
|
|
|
}
|
|
|
if (user.getPufaPoint().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- throw new PointException("积分不足");
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
}
|
|
|
//商品所需积分
|
|
|
BigDecimal exchangeNum = BigDecimal.valueOf(yeepayOrder.getNum());
|
|
|
@@ -111,7 +110,7 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
BigDecimal userPoint = user.getPufaPoint().subtract(exchangePoint);
|
|
|
|
|
|
if (userPoint.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw new PointException("积分不足");
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
}
|
|
|
|
|
|
user.setPufaPoint(userPoint);
|
|
|
@@ -129,15 +128,14 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
pointRecord.setPointType(PointTypeEnum.PUFA_POINT_EXCHANGE);
|
|
|
pointRecord.setPhone(yeepayOrder.getPhone());
|
|
|
pointRecord.setActiveId(yeepayOrder.getActiveId());
|
|
|
- Assert.isTrue(pointRecordService.save(pointRecord), "兑换失败");
|
|
|
+ Assert.isTrue(pointRecordService.save(pointRecord), "兑换失败");*/
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HashMap<String, Object> cashExchange(YeepayOrder yeepayOrder) throws Exception {
|
|
|
- LoginUser loginUser = loginUserService.getOne(new LambdaQueryWrapper<LoginUser>().eq(LoginUser::getPhone, yeepayOrder.getPhone()));
|
|
|
- UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
+/* UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
Assert.notNull(user, "用户不存在");
|
|
|
PointGoods goods = pointGoodsService.getById(yeepayOrder.getPointGoodsId());
|
|
|
Assert.notNull(goods, "商品不存在");
|
|
|
@@ -150,11 +148,11 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
int size = goodsOrderService.list(new LambdaQueryWrapper<GoodsOrder>().eq(GoodsOrder::getPhone, yeepayOrder.getPhone())
|
|
|
.eq(GoodsOrder::getPointGoodsId, yeepayOrder.getPointGoodsId())).size();
|
|
|
if ((yeepayOrder.getNum() + size) > goods.getLimitBuy()) {
|
|
|
- throw new PointException("超过限购数量");
|
|
|
+ throw new PointExchangeException("超过限购数量");
|
|
|
}
|
|
|
}
|
|
|
if (goods.getRemain() < yeepayOrder.getNum()) {
|
|
|
- throw new PointException("库存不足");
|
|
|
+ throw new PointExchangeException("库存不足");
|
|
|
}
|
|
|
//商品所需积分
|
|
|
BigDecimal exchangeNum = BigDecimal.valueOf(yeepayOrder.getNum());
|
|
|
@@ -231,7 +229,8 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
return map;
|
|
|
} catch (Exception e) {
|
|
|
throw new Exception(e.getMessage());
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -312,9 +311,9 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HashMap<String, Object> hybridExchange(YeepayOrder yeepayOrder, BigDecimal point) throws Exception {
|
|
|
+ public HashMap<String, Object> hybridExchange(YeepayOrder yeepayOrder) throws Exception {
|
|
|
|
|
|
- UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
+/* UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
Assert.notNull(user, "用户不存在");
|
|
|
PointGoods goods = pointGoodsService.getById(yeepayOrder.getPointGoodsId());
|
|
|
Assert.notNull(goods, "商品不存在");
|
|
|
@@ -326,14 +325,14 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
if (isLimit) {
|
|
|
int size = goodsOrderService.list(new LambdaQueryWrapper<GoodsOrder>().eq(GoodsOrder::getPhone, yeepayOrder.getPhone()).eq(GoodsOrder::getPointGoodsId, yeepayOrder.getPointGoodsId())).size();
|
|
|
if ((yeepayOrder.getNum() + size) > goods.getLimitBuy()) {
|
|
|
- throw new PointException("超过限购数量");
|
|
|
+ throw new PointExchangeException("超过限购数量");
|
|
|
}
|
|
|
}
|
|
|
if (goods.getRemain() < yeepayOrder.getNum()) {
|
|
|
- throw new PointException("库存不足");
|
|
|
+ throw new PointExchangeException("库存不足");
|
|
|
}
|
|
|
- if (user.getPufaPoint().compareTo(point) <= 0) {
|
|
|
- throw new PointException("积分不足");
|
|
|
+ if (user.getPufaPoint().compareTo(yeepayOrder.getUsePoint()) <= 0) {
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
}
|
|
|
//商品所需积分
|
|
|
BigDecimal exchangeNum = BigDecimal.valueOf(yeepayOrder.getNum());
|
|
|
@@ -346,7 +345,7 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
}
|
|
|
|
|
|
//需要的现金
|
|
|
- BigDecimal usePoint = exchangePoint.subtract(point);
|
|
|
+ BigDecimal usePoint = exchangePoint.subtract(yeepayOrder.getUsePoint());
|
|
|
BigDecimal useCash = usePoint.divide(BigDecimal.valueOf(100));
|
|
|
|
|
|
//判断兑换数量(判断兑换次数大于零)
|
|
|
@@ -361,7 +360,6 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
yeepayOrder.setHelpGoodsName(goods.getName());
|
|
|
yeepayOrder.setCallbackUrl(callbackUrl);
|
|
|
yeepayOrder.setCreateTime(new Date());
|
|
|
- yeepayOrder.setUsePoint(point);
|
|
|
yeepayOrder.setPointGoodsName(goods.getName());
|
|
|
yeepayOrder.setUserId(user.getUserId());
|
|
|
|
|
|
@@ -416,7 +414,159 @@ public class PointExchangeServiceImpl implements PointExchangeService {
|
|
|
return map;
|
|
|
} catch (Exception e) {
|
|
|
throw new Exception(e.getMessage());
|
|
|
+ }*/
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HashMap<String, Object> merge(YeepayOrder yeepayOrder, int type) throws Exception {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ if (yeepayOrder.getUsePoint() != null && (yeepayOrder.getUsePoint().compareTo(BigDecimal.ZERO) <= 0)) {
|
|
|
+ throw new PointExchangeException("请输入有效积分值");
|
|
|
}
|
|
|
+ UserPufaPoint user = userPufaPointService.getOne(new LambdaQueryWrapper<UserPufaPoint>().eq(UserPufaPoint::getPhone, yeepayOrder.getPhone()));
|
|
|
+ Assert.notNull(user, "用户不存在");
|
|
|
+ PointGoods goods = pointGoodsService.getById(yeepayOrder.getPointGoodsId());
|
|
|
+ Assert.notNull(goods, "商品不存在");
|
|
|
+ UserAddress address = userAddressService.getById(yeepayOrder.getAddressId());
|
|
|
+ Assert.notNull(address, "请添加收货地址");
|
|
|
+ Assert.notNull(yeepayOrder.getActiveId(), "兑换失败");
|
|
|
|
|
|
+ Boolean isLimit = Optional.ofNullable(goods.getIsLimit()).orElse(false);
|
|
|
+ if (isLimit) {
|
|
|
+ int size = goodsOrderService.list(new LambdaQueryWrapper<GoodsOrder>()
|
|
|
+ .eq(GoodsOrder::getPhone, yeepayOrder.getPhone()).eq(GoodsOrder::getPointGoodsId, yeepayOrder.getPointGoodsId())).size();
|
|
|
+ System.out.println(size);
|
|
|
+ if ((yeepayOrder.getNum() + size) > goods.getLimitBuy()) {
|
|
|
+ throw new PointExchangeException("超过限购数量");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (goods.getRemain() < yeepayOrder.getNum()) {
|
|
|
+ throw new PointExchangeException("库存不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ //商品所需积分
|
|
|
+ BigDecimal exchangeNum = BigDecimal.valueOf(yeepayOrder.getNum());
|
|
|
+ BigDecimal exchangePoint = goods.getPoint().multiply(exchangeNum);
|
|
|
+
|
|
|
+ if (type == 1){
|
|
|
+ if (user.getPufaPoint().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal userPoint = user.getPufaPoint().subtract(exchangePoint);
|
|
|
+
|
|
|
+ if (userPoint.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
+ }
|
|
|
+ user.setPufaPoint(userPoint);
|
|
|
+ Assert.isTrue(userPufaPointService.saveOrUpdate(user), "兑换失败");
|
|
|
+ yeepayOrder.setUserId(user.getUserId());
|
|
|
+ yeepayOrder.setUsePoint(exchangePoint);
|
|
|
+ //下单
|
|
|
+ createOrder(yeepayOrder);
|
|
|
+ //添加积分消费
|
|
|
+ PointRecord pointRecord = new PointRecord();
|
|
|
+ pointRecord.setPoint(goods.getPoint());
|
|
|
+ pointRecord.setUserId(user.getUserId());
|
|
|
+ pointRecord.setPointGoodsId(yeepayOrder.getPointGoodsId());
|
|
|
+ pointRecord.setPointType(PointTypeEnum.PUFA_POINT_EXCHANGE);
|
|
|
+ pointRecord.setPhone(yeepayOrder.getPhone());
|
|
|
+ pointRecord.setActiveId(yeepayOrder.getActiveId());
|
|
|
+ Assert.isTrue(pointRecordService.save(pointRecord), "兑换失败");
|
|
|
+ //map.put("msg","兑换成功");
|
|
|
+ //return map;
|
|
|
+ }
|
|
|
+ if (type == 2 || type == 0){
|
|
|
+ BigDecimal amount;
|
|
|
+ if (type == 2){
|
|
|
+ if (user.getPufaPoint().compareTo(yeepayOrder.getUsePoint()) < 0) {
|
|
|
+ throw new PointExchangeException("积分不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果用户输入的积分足够,则使用积分支付
|
|
|
+ if (user.getPufaPoint().compareTo(exchangePoint) > 0) {
|
|
|
+ type = 1;
|
|
|
+ return this.merge(yeepayOrder,type);
|
|
|
+ }
|
|
|
+ //需要的现金
|
|
|
+ BigDecimal usePoint = exchangePoint.subtract(yeepayOrder.getUsePoint());
|
|
|
+ amount = usePoint.divide(BigDecimal.valueOf(100));
|
|
|
+ }else {
|
|
|
+ amount = exchangePoint.divide(BigDecimal.valueOf(100));
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断兑换数量(判断兑换次数大于零)
|
|
|
+ Assert.isTrue(Integer.valueOf(-1).equals(BigDecimal.ZERO.compareTo(BigDecimal.valueOf(yeepayOrder.getNum()))), "兑换数量必须大于零");
|
|
|
+
|
|
|
+ //回调地址
|
|
|
+ String callbackUrl = new StringBuilder(yeePayConst.getServiceUrl())
|
|
|
+ .append("/app/point/callbackUrl").toString();
|
|
|
+ yeepayOrder.setId(new SnowflakeGenerator().next());
|
|
|
+ yeepayOrder.setPayStatus(YeepayOrderPayStatus.待付款);
|
|
|
+ yeepayOrder.setAmount(amount);
|
|
|
+ yeepayOrder.setHelpGoodsName(goods.getName());
|
|
|
+ yeepayOrder.setCallbackUrl(callbackUrl);
|
|
|
+ yeepayOrder.setCreateTime(new Date());
|
|
|
+ yeepayOrder.setUserId(user.getUserId());
|
|
|
+ yeepayOrder.setUsePoint(BigDecimal.ZERO);
|
|
|
+ yeepayOrder.setPointGoodsName(goods.getName());
|
|
|
+ yeepayOrder.setIp(IPUtils.getRealIp(request));
|
|
|
+
|
|
|
+ // 请求易宝
|
|
|
+ try {
|
|
|
+ InitOrderDto initOrderDto = InitOrderDto
|
|
|
+ .builder()
|
|
|
+ .orderId(yeepayOrder.getId().toString())
|
|
|
+ .orderAmount(amount.doubleValue())
|
|
|
+ .goodsName(goods.getName())
|
|
|
+ .scene("OFFLINE")
|
|
|
+ .payWay("WECHAT_OFFIACCOUNT")
|
|
|
+ .userIp(yeepayOrder.getIp())
|
|
|
+ .channel("WECHAT")
|
|
|
+ .userId(yeepayOrder.getOpenId())
|
|
|
+ .appId(configForOfficial.getAppId())
|
|
|
+ //支付订单有效期为一天
|
|
|
+ .expiredTime(DateUtil.format(cn.hutool.core.date.DateUtil.offsetDay(DateUtil.now(), 1), DateUtil.PATTERN_DATETIME))
|
|
|
+ .notifyUrl(callbackUrl)
|
|
|
+ .build();
|
|
|
+ //设置易宝配置内容
|
|
|
+ initOrderDto.setParentMerchantNo(yeePayConst.getPlatformServiceNo());
|
|
|
+ initOrderDto.setMerchantNo(yeePayConst.getMerchantNo());
|
|
|
+ YopResponse yopResponse = yeepaySaasService.aggPrepay(initOrderDto);
|
|
|
+
|
|
|
+ //返回数据
|
|
|
+ String stringResult = yopResponse.getStringResult();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(stringResult);
|
|
|
+ //返回给前端
|
|
|
+ String prePayTn = jsonObject.getString("prePayTn");
|
|
|
+
|
|
|
+ if (!StringUtils.equals(jsonObject.getString("code"), "00000")) {
|
|
|
+ bladeLogger.error("创建道具订单错误", jsonObject.getString("message"));
|
|
|
+ log.error("创建道具订单错误:{}", jsonObject.getString("message"));
|
|
|
+ throw new HelpGoodsException("创建订单失败");
|
|
|
+ }
|
|
|
+ yeepayOrder.setUniqueOrderNo(jsonObject.getString(BeanPropertyUtil.getFieldName(YeepayOrder::getUniqueOrderNo)));
|
|
|
+ yeepayOrder.setQrCodeUrl(jsonObject.getString(BeanPropertyUtil.getFieldName(YeepayOrder::getQrCodeUrl)));
|
|
|
+ yeepayOrder.setBankOrderId(jsonObject.get("bankOrderId").toString());
|
|
|
+ yeepayOrder.setPrePayTn(prePayTn);
|
|
|
+ //保存订单
|
|
|
+ Assert.isTrue(yeepayOrderService.save(yeepayOrder), "创建订单失败");
|
|
|
+
|
|
|
+ JSONObject prePayTnJson = JSONObject.parseObject(prePayTn);
|
|
|
+
|
|
|
+ map.put("appId", prePayTnJson.get("appId"));
|
|
|
+ map.put("timeStamp", prePayTnJson.get("timeStamp"));
|
|
|
+ map.put("nonceStr", prePayTnJson.get("nonceStr"));
|
|
|
+ map.put("package", prePayTnJson.get("package"));
|
|
|
+ map.put("signType", prePayTnJson.get("signType"));
|
|
|
+ map.put("paySign", prePayTnJson.get("paySign"));
|
|
|
+ return map;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
}
|
|
|
}
|