|
@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.beust.jcommander.internal.Lists;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.*;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMapper;
|
|
@@ -88,6 +90,13 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
|
|
|
@Autowired
|
|
|
private UserTenantAlbumRecordService userTenantAlbumRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantGroupAlbumService tenantGroupAlbumService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserOrderDao userOrderDao;
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
*
|
|
@@ -202,9 +211,9 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
log.error("订单创建前检测,专辑不存在,bizId={}", orderGoodsInfo.getBizId());
|
|
|
throw new BizException("订单商品信息为空");
|
|
|
}
|
|
|
- tenantAlbumContent.setBuyCycle(tenantAlbum.getPurchaseCycle());
|
|
|
- tenantAlbumContent.setSalePrice(tenantAlbum.getSalePrice());
|
|
|
- tenantAlbumContent.setOriginalPrice(tenantAlbum.getOriginalPrice());
|
|
|
+// tenantAlbumContent.setBuyCycle(tenantAlbum.getPurchaseCycle());
|
|
|
+// tenantAlbumContent.setSalePrice(tenantAlbum.getSalePrice());
|
|
|
+// tenantAlbumContent.setOriginalPrice(tenantAlbum.getOriginalPrice());
|
|
|
|
|
|
// 查询专辑所在机构
|
|
|
List<TenantAlbumRef> refList =
|
|
@@ -223,7 +232,8 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
|
|
|
// 设置金额入账去向
|
|
|
UserPaymentOrderWrapper.AccountTenantTo accountTenantTo = teacherService.teacherSettlementFrom(null, orderGoodsInfo.getRecomUserId());
|
|
|
- BigDecimal price = BigDecimal.ZERO;
|
|
|
+ BigDecimal originalPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal actualPrice = BigDecimal.ZERO;
|
|
|
// 学生购买机构专辑
|
|
|
switch (orderGoodsInfo.getPaymentClient()) {
|
|
|
case STUDENT: {
|
|
@@ -238,10 +248,36 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
log.error("订单创建前检测,学生不在当前机构下,userId={},tenantId={}", orderGoodsInfo.getUserId(), student.getTenantId());
|
|
|
throw new BizException("用户不在当前机构");
|
|
|
}
|
|
|
- price = tenantAlbum.getSalePrice();
|
|
|
+ if (orderGoodsInfo.getTenantGroupAlbumId() == null) {
|
|
|
+ log.error("订单创建前检测,学生购买机构专辑,机构小组专辑ID为空,userId={}", orderGoodsInfo.getUserId());
|
|
|
+ throw new BizException("机构小组专辑ID为空");
|
|
|
+ }
|
|
|
+ // 判断机构小组专辑ID是否能购买,专辑ID和当前机构专辑ID是否对应
|
|
|
+ TenantGroupAlbum tenantGroupAlbum = tenantGroupAlbumService.getById(orderGoodsInfo.getTenantGroupAlbumId());
|
|
|
+ if (tenantGroupAlbum == null) {
|
|
|
+ log.error("订单创建前检测,学生购买机构专辑,机构小组专辑不存在,userId={},tenantGroupAlbumId={}", orderGoodsInfo.getUserId(), orderGoodsInfo.getTenantGroupAlbumId());
|
|
|
+ throw new BizException("小组专辑不存在");
|
|
|
+ }
|
|
|
+ if (!tenantGroupAlbum.getTenantAlbumId().equals(orderGoodsInfo.getBizId())) {
|
|
|
+ log.error("订单创建前检测,学生购买机构专辑,机构小组专辑ID和当前机构专辑ID不对应,userId={},tenantGroupAlbumId={},bizId={}", orderGoodsInfo.getUserId(), orderGoodsInfo.getTenantGroupAlbumId(), orderGoodsInfo.getBizId());
|
|
|
+ throw new BizException("小组专辑和当前购买专辑不对应");
|
|
|
+ }
|
|
|
+ // 判断购买次数
|
|
|
+ if (tenantGroupAlbum.getBuyTimesFlag()) {
|
|
|
+ List<Long> studentTenantAlbumNum = userOrderDao.getStudentTenantAlbumNum(student.getUserId(), Lists.newArrayList(tenantGroupAlbum.getId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(studentTenantAlbumNum) && studentTenantAlbumNum.size() >tenantGroupAlbum.getBuyTimes()) {
|
|
|
+ log.error("订单创建前检测,学生购买机构专辑,机构小组专辑购买次数超过限制,userId={},tenantGroupAlbumId={},buyTimes={}", orderGoodsInfo.getUserId(), orderGoodsInfo.getTenantGroupAlbumId(), tenantGroupAlbum.getBuyTimes());
|
|
|
+ throw new BizException("购买次数超过限制");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ originalPrice = tenantGroupAlbum.getOriginalPrice();
|
|
|
+ actualPrice = tenantGroupAlbum.getActualPrice();
|
|
|
userOrderDetail.setMerchId(tenantInfo.getId());
|
|
|
+ userOrderDetail.setTenantGroupAlbumId(tenantGroupAlbum.getId());
|
|
|
tenantAlbumContent.setBuyNumber(1);
|
|
|
- tenantAlbumContent.setBuyCycle(tenantAlbumContent.getBuyCycle()*tenantAlbumContent.getBuyMultiple());
|
|
|
+ tenantAlbumContent.setBuyCycle(tenantGroupAlbum.getPurchaseNum());
|
|
|
+ tenantAlbumContent.setPurchaseType(tenantGroupAlbum.getPurchasePeriod());
|
|
|
tenantAlbumContent.setTenantId(tenantInfo.getId());
|
|
|
accountTenantTo.setIncomeTenant(tenantInfo.getId());
|
|
|
break;
|
|
@@ -258,7 +294,34 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
log.error("订单创建前检测,专辑不在机构下,userId={},tenantId={}", orderGoodsInfo.getUserId(), tenantStaff.getTenantId());
|
|
|
throw new BizException("用户不在当前机构");
|
|
|
}
|
|
|
- price = tenantAlbum.getOriginalPrice();
|
|
|
+ // 根据周期判断能不能购买当前周期的专辑
|
|
|
+ if (StringUtil.isEmpty(tenantAlbum.getPurchaseTypes())) {
|
|
|
+ log.error("订单创建前检测,机构购买机构专辑,专辑周期为空,userId={},bizId={}", orderGoodsInfo.getUserId(), orderGoodsInfo.getBizId());
|
|
|
+ throw new BizException("专辑不支持当前周期");
|
|
|
+ }
|
|
|
+ List<String> purchaseTypes = Arrays.asList(tenantAlbum.getPurchaseTypes().split(","));
|
|
|
+ if (!purchaseTypes.contains(tenantAlbumContent.getPurchaseType())) {
|
|
|
+ log.error("订单创建前检测,机构购买机构专辑,专辑周期不支持,userId={},bizId={},purchaseType={}", orderGoodsInfo.getUserId(),
|
|
|
+ orderGoodsInfo.getBizId(), tenantAlbumContent.getPurchaseType());
|
|
|
+ throw new BizException("专辑不支持当前周期");
|
|
|
+ }
|
|
|
+ List<TenantAlbumWrapper.TenantAlbumPurchaseJson> tenantAlbumPurchaseJsons = JSON
|
|
|
+ .parseArray(tenantAlbum.getPurchaseJson(), TenantAlbumWrapper.TenantAlbumPurchaseJson.class);
|
|
|
+ if (CollectionUtils.isEmpty(tenantAlbumPurchaseJsons)) {
|
|
|
+ log.error("订单创建前检测,机构购买机构专辑,专辑周期不支持,userId={},bizId={},purchaseType={}", orderGoodsInfo.getUserId(),
|
|
|
+ orderGoodsInfo.getBizId(), tenantAlbumContent.getPurchaseType());
|
|
|
+ throw new BizException("专辑不支持当前周期");
|
|
|
+ }
|
|
|
+ Optional<TenantAlbumWrapper.TenantAlbumPurchaseJson> first = tenantAlbumPurchaseJsons.stream().filter(o -> o.getPurchaseType().equals(tenantAlbumContent.getPurchaseType())).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ log.error("订单创建前检测,机构购买机构专辑,专辑周期不支持,userId={},bizId={},purchaseType={}", orderGoodsInfo.getUserId(),
|
|
|
+ orderGoodsInfo.getBizId(), tenantAlbumContent.getPurchaseType());
|
|
|
+ throw new BizException("专辑不支持当前周期");
|
|
|
+ }
|
|
|
+ TenantAlbumWrapper.TenantAlbumPurchaseJson tenantAlbumPurchaseJson = first.get();
|
|
|
+
|
|
|
+ originalPrice = tenantAlbumPurchaseJson.getPrice();
|
|
|
+ actualPrice = tenantAlbumPurchaseJson.getPrice();
|
|
|
userOrderDetail.setMerchId(0L);
|
|
|
tenantAlbumContent.setTenantId(tenantStaff.getTenantId());
|
|
|
tenantAlbumContent.setBuyCycle(tenantAlbumContent.getBuyCycle()*tenantAlbumContent.getBuyMultiple());
|
|
@@ -272,10 +335,11 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
userOrderDetail.setBizId(tenantAlbum.getId());
|
|
|
userOrderDetail.setBizContent(JSON.toJSONString(tenantAlbumContent));
|
|
|
userOrderDetail.setGoodNum(orderGoodsInfo.getGoodNum());
|
|
|
- userOrderDetail.setOriginalPrice(price.multiply(new BigDecimal(orderGoodsInfo.getGoodNum()))
|
|
|
+ userOrderDetail.setOriginalPrice(originalPrice.multiply(new BigDecimal(orderGoodsInfo.getGoodNum()))
|
|
|
.multiply(new BigDecimal(tenantAlbumContent.getBuyMultiple())));
|
|
|
userOrderDetail.setCouponAmount(BigDecimal.ZERO);
|
|
|
- userOrderDetail.setExpectPrice(userOrderDetail.getOriginalPrice());
|
|
|
+ userOrderDetail.setExpectPrice(actualPrice.multiply(new BigDecimal(orderGoodsInfo.getGoodNum()))
|
|
|
+ .multiply(new BigDecimal(tenantAlbumContent.getBuyMultiple())));
|
|
|
userOrderDetail.setActualPrice(userOrderDetail.getExpectPrice());
|
|
|
userOrderDetail.setAccountConfig(accountTenantTo.jsonString());
|
|
|
|
|
@@ -515,6 +579,7 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
tenantAlbumPurchase.setPurchaseCycle(tenantAlbumContent.getBuyCycle());
|
|
|
tenantAlbumPurchase.setActiveQuantity(0);
|
|
|
tenantAlbumPurchase.setOrderNo(orderGoodsInfo.getOrderNo());
|
|
|
+ tenantAlbumPurchase.setPurchaseType(tenantAlbumContent.getPurchaseType());
|
|
|
tenantAlbumPurchase.setPurchasePrice(orderGoodsInfo.getUserOrderDetail().getActualPrice());
|
|
|
tenantAlbumPurchase.setPurchaseStatus(OrderStatusEnum.WAIT_PAY.getCode());
|
|
|
tenantAlbumPurchaseService.save(tenantAlbumPurchase);
|