Przeglądaj źródła

完成道具和移动积分对接

silent 4 lat temu
rodzic
commit
26cb906146

+ 2 - 0
src/main/java/org/springblade/gateway/goods_gateway/controller/AppHelpGoodsController.java

@@ -42,11 +42,13 @@ public class AppHelpGoodsController {
 	@ApiOperation(value = "兑换道具", notes = "传入pointRecord")
 	public R exchangeProps(@RequestParam Long helpGoodsId,
 						   @RequestParam Long userId,
+						   @RequestParam BigDecimal num,
 						   CmccDectOrderRequest cmccDectOrderRequest){
 		try {
 			CmccPointRecord cmccPointRecord = new CmccPointRecord();
 			cmccPointRecord.setHelpGoodsId(helpGoodsId);
 			cmccPointRecord.setUserId(userId);
+			cmccPointRecord.setNum(num);
 			appHelpGoodsService.exchangeProps(cmccPointRecord,cmccDectOrderRequest);
 			return R.success("兑换成功");
 		} catch (Exception e) {

+ 12 - 7
src/main/java/org/springblade/gateway/goods_gateway/service/impl/AppHelpGoodsServiceImpl.java

@@ -65,7 +65,7 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 		Assert.notNull(loginUser,"没有找到该用户");
 
 		//判断用户今天购买该商品次数是否超过限制(-1标识不限制次数)
-		if(!helpGoods.getTotal().equals(-1)){
+		if(!helpGoods.getTotal().equals(-1L)){
 			int count = pointRecordService.count(Wrappers.<PointRecord>lambdaQuery()
 				.eq(PointRecord::getUserId,loginUser.getId())
 				.eq(PointRecord::getHelpGoodsId,helpGoods.getId())
@@ -104,8 +104,10 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 
 		//TODO 对接移动积分接口
 		if(ObjectUtils.isNotEmpty(helpGoods.getPoint()) && helpGoods.getPoint().longValue()>0L){
+			Assert.notNull(cmccDectOrderRequest.getOutOrderId(),"订单号不能为空");
+
 			//查询移动订单记录
-			CmccPointRecord oldCmccPointRecord = cmccPointRecordService.getOne(Wrappers.<CmccPointRecord>lambdaQuery().eq(CmccPointRecord::getOutOrderId, cmccPointRecord.getOutOrderId()));
+			CmccPointRecord oldCmccPointRecord = cmccPointRecordService.getOne(Wrappers.<CmccPointRecord>lambdaQuery().eq(CmccPointRecord::getOutOrderId, cmccDectOrderRequest.getOutOrderId()));
 			Assert.notNull(oldCmccPointRecord,"没有找到移动支付订单");
 
 			//判断是否是同一个道具
@@ -123,6 +125,7 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 			pointRecord.setPoint(oldCmccPointRecord.getPoint());
 			pointRecord.setHelpGoodsId(helpGoods.getId());
 			pointRecord.setUserId(loginUser.getId());
+			pointRecord.setPointType(PointTypeEnum.CMCC_POINT_EXCHANGE);
 			Assert.isTrue(pointRecordService.save(pointRecord),"兑换失败");
 
 			//设置状态为支付成功
@@ -132,7 +135,7 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 			Assert.isTrue(cmccPointRecordService.updateById(oldCmccPointRecord));
 
 			// TODO 移动支付逻辑
-			cmccDectOrderRequest.setOutOrderId(cmccPointRecord.getOutOrderId());
+			cmccDectOrderRequest.setMobile(oldCmccPointRecord.getPhone());
 			try {
 				CmccUtil.dectOrder(cmccDectOrderRequest);
 			} catch (CmccRequestException e) {
@@ -162,9 +165,8 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 		cmccPointRecord.setPayStatus(CmccPayStatus.WAIT);
 		//生成随机订单号
 		cmccPointRecord.setOutOrderId(IdUtil.randomUUID());
-
-		//设置请求属性
-		cmccPlaceOrderRequest.setOutOrderId(cmccPointRecord.getOutOrderId());
+		//设置积分
+		cmccPointRecord.setPoint(cmccPointRecord.getNum().multiply(helpGoods.getPoint()));
 
 		//设置商品属性
 		CmccPlaceOrderRequest.ProductItem productItem = new CmccPlaceOrderRequest.ProductItem();
@@ -173,11 +175,14 @@ public class AppHelpGoodsServiceImpl implements AppHelpGoodsService {
 
 		cmccPlaceOrderRequest.setProductItemList(JSONObject.toJSONString(Arrays.asList(productItem)));
 		cmccPlaceOrderRequest.setMobile(cmccPointRecord.getPhone());
-		cmccPlaceOrderRequest.setPoints(cmccPointRecord.getNum().multiply(helpGoods.getPoint()).toString());
+//		cmccPlaceOrderRequest.setPoints(cmccPointRecord.getNum().multiply(helpGoods.getPoint()).toString());
+		cmccPlaceOrderRequest.setPoints("240");
 
 		Assert.isTrue(cmccPointRecordService.save(cmccPointRecord),"创建订单失败");
 
 		// TODO 移动订单创建逻辑
+		//设置请求属性
+		cmccPlaceOrderRequest.setOutOrderId(cmccPointRecord.getOutOrderId());
 		try {
 			CmccUtil.placeOrder(cmccPlaceOrderRequest);
 		} catch (CmccRequestException e) {