|
@@ -0,0 +1,154 @@
|
|
|
+package com.zswl.cloud.springBtach.server.core.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.lang.Snowflake;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.eeext.openapi.entity.NotifyOrderReq;
|
|
|
+import com.eeext.openapi.entity.ProductItemResp;
|
|
|
+import com.eeext.openapi.entity.RechargeOrderReq;
|
|
|
+import com.eeext.openapi.entity.RechargeProductResp;
|
|
|
+import com.github.microservice.auth.client.content.ResultContent;
|
|
|
+import com.github.microservice.auth.client.content.ResultState;
|
|
|
+import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
+import com.zhongshu.payment.client.model.order.v2.*;
|
|
|
+import com.zhongshu.payment.client.service.v2.OrderService2;
|
|
|
+import com.zhongshu.payment.client.service.v2.PaymentService2;
|
|
|
+import com.zhongshu.payment.client.type.*;
|
|
|
+import com.zswl.cloud.shop.client.service.ShopService;
|
|
|
+import com.zswl.cloud.shop.client.vo.life.AccountDetailVo;
|
|
|
+import com.zswl.cloud.shop.client.vo.life.SharePlatformVo;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.video2.Video2Api;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class Video2ServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Video2Api video2Api;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ShopService shopService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ Snowflake snowflake;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AuthHelper authHelper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrderService2 orderService2;
|
|
|
+ @Autowired
|
|
|
+ private PaymentService2 paymentService2;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<RechargeProductResp> rechargeProduct() {
|
|
|
+
|
|
|
+ return ResultContent.buildContent(video2Api.rechargeProduct());
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<CreatOrderResultModel> creatOrder(RechargeOrderReq rechargeOrderReq) {
|
|
|
+
|
|
|
+ RechargeProductResp rechargeProductResp = video2Api.rechargeProduct();
|
|
|
+ List<ProductItemResp> collect = rechargeProductResp.getProducts().stream().filter(productItemResp -> productItemResp.getProductId().equals(rechargeOrderReq.getProductId())).collect(Collectors.toList());
|
|
|
+ ProductItemResp productItemResp = collect.get(0);
|
|
|
+ String channelPrice = productItemResp.getChannelPrice();
|
|
|
+ BigDecimal totalPrice = new BigDecimal(channelPrice);
|
|
|
+ com.zswl.cloud.shop.client.ret.ResultContent<AccountDetailVo> shopSetting = shopService.shopSetting("视频会员");
|
|
|
+ if (!shopSetting.getState().equals(com.zswl.cloud.shop.client.ret.ResultState.Success)) {
|
|
|
+ return ResultContent.build(ResultState.Fail, "视频会员信息未配置");
|
|
|
+ }
|
|
|
+ AccountDetailVo accountDetailVo = shopSetting.getContent();
|
|
|
+
|
|
|
+
|
|
|
+ String orderNo = snowflake.nextIdStr();
|
|
|
+
|
|
|
+
|
|
|
+// 平台订单
|
|
|
+
|
|
|
+ String shopId = accountDetailVo.getAccountId();
|
|
|
+ String authAccount = accountDetailVo.getAuthAccount();
|
|
|
+ SharePlatformVo sharePlatformVo = accountDetailVo.getSharePlatformVo();
|
|
|
+
|
|
|
+ // 平台订单
|
|
|
+ CreateOrder2Model createOrder2Model = new CreateOrder2Model();
|
|
|
+ createOrder2Model.setOrderNo(orderNo);
|
|
|
+ createOrder2Model.setUserId(authHelper.getCurrentUser().getUserId());
|
|
|
+ createOrder2Model.setShopId(shopId);
|
|
|
+ JSONObject shopInfo = JSONUtil.parseObj(shopSetting);
|
|
|
+// shopInfo.set("hotelIdPic", addOrderRequest.getHotelIdPic());
|
|
|
+// shopInfo.set("shopName", shopSetting.getContent().getContactName());
|
|
|
+ createOrder2Model.setShopInfo(shopInfo);
|
|
|
+ createOrder2Model.setTotalAmount(totalPrice);
|
|
|
+ createOrder2Model.setDiscountAmount(BigDecimal.ZERO);
|
|
|
+ createOrder2Model.setPayAmount(totalPrice);
|
|
|
+ createOrder2Model.setAccesserUserId(authAccount);
|
|
|
+ createOrder2Model.setChannel(Channel.ZhongShu);
|
|
|
+ JSONObject goodsInfo = JSONUtil.parseObj(rechargeOrderReq);
|
|
|
+ goodsInfo.set("goodsName", productItemResp.getItemName());
|
|
|
+// goodsInfo.set("goodsPath", addOrderRequest.getRoomPic());
|
|
|
+
|
|
|
+ CreateOrder2Model.Goods goods = new CreateOrder2Model.Goods();
|
|
|
+ goods.setGoodsId(productItemResp.getProductId().toString());
|
|
|
+ goods.setJobFlowMap(JobFlowMap.video2);
|
|
|
+ goods.setGoodsInfo(goodsInfo);
|
|
|
+ goods.setPayAmount(totalPrice);
|
|
|
+ goods.setValidDay(90);
|
|
|
+ goods.setTransferType(sharePlatformVo.getShareType().equals(1) ? TransferType.RATIO : TransferType.FIXED);
|
|
|
+
|
|
|
+ List<CreateOrder2Model.Owner> ownerList = new ArrayList<>();
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner platfor = new CreateOrder2Model.Owner();
|
|
|
+ platfor.setOwner(TransferOwner.PLATFORM);
|
|
|
+ platfor.setValue(sharePlatformVo.getPlatformRate());
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner buy = new CreateOrder2Model.Owner();
|
|
|
+ buy.setOwner(TransferOwner.BUY_SHOP);
|
|
|
+ buy.setValue(sharePlatformVo.getBuyShopRate());
|
|
|
+ buy.setShopId(shopId);
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner use = new CreateOrder2Model.Owner();
|
|
|
+ use.setOwner(TransferOwner.USE_SHOP);
|
|
|
+ use.setValue(sharePlatformVo.getCheckShopRate());
|
|
|
+
|
|
|
+ ownerList.add(platfor);
|
|
|
+ ownerList.add(buy);
|
|
|
+ ownerList.add(use);
|
|
|
+ goods.setTransferRrule(ownerList);
|
|
|
+ createOrder2Model.setGoodsList(List.of(goods));
|
|
|
+ return orderService2.creat(createOrder2Model);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void notifyOrder(NotifyOrderReq notifyOrderReq) {
|
|
|
+ ResultContent<List<GoodsResultModel>> listResultContent = orderService2.goodsDetail(notifyOrderReq.getOutTradeNo());
|
|
|
+ GoodsResultModel goodsResultModel = listResultContent.getContent().get(0);
|
|
|
+ UpdateGoodsModel updateGoodsModel = new UpdateGoodsModel();
|
|
|
+ updateGoodsModel.setId(goodsResultModel.getId());
|
|
|
+ if (notifyOrderReq.getStatus().equals("1")) {
|
|
|
+ updateGoodsModel.setGoodsState(OrderType.USED);
|
|
|
+ } else if (notifyOrderReq.getStatus().equals("3")) {
|
|
|
+ ApplicantRefundParam2Model applicantRefundParam2Model = new ApplicantRefundParam2Model();
|
|
|
+ applicantRefundParam2Model.setId(goodsResultModel.getId());
|
|
|
+ applicantRefundParam2Model.setRemark("充值失败退款");
|
|
|
+ applicantRefundParam2Model.setUserId(goodsResultModel.getUserId());
|
|
|
+ paymentService2.refund(applicantRefundParam2Model);
|
|
|
+
|
|
|
+ }
|
|
|
+ updateGoodsModel.setExtend(JSONUtil.parseObj(notifyOrderReq));
|
|
|
+ orderService2.updateGoods(updateGoodsModel);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|