|
|
@@ -3,6 +3,7 @@ package com.ylx.giftCard.service.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
@@ -10,6 +11,10 @@ import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.DateUtils;
|
|
|
import com.ylx.giftCard.domain.GiftCard;
|
|
|
import com.ylx.giftCard.domain.GiftCardOrder;
|
|
|
+import com.ylx.giftCard.domain.dto.UserShoppingFundsDetailQueryDTO;
|
|
|
+import com.ylx.giftCard.domain.vo.UserShoppingFundsDetailItemVO;
|
|
|
+import com.ylx.giftCard.domain.vo.UserShoppingFundsDetailVO;
|
|
|
+import com.ylx.giftCard.domain.vo.UserShoppingFundsSummaryVO;
|
|
|
import com.ylx.giftCard.enums.GiftCardOrderStatusEnum;
|
|
|
import com.ylx.giftCard.mapper.GiftCardOrderMapper;
|
|
|
import com.ylx.giftCard.service.IGiftCardOrderService;
|
|
|
@@ -19,8 +24,10 @@ import com.ylx.massage.service.TJsService;
|
|
|
import com.ylx.massage.service.TWxUserService;
|
|
|
import com.ylx.shopingfundsdetail.domain.vo.ShoppingFundsDetailAddDto;
|
|
|
import com.ylx.shopingfundsdetail.enums.ShoppingFundsExpenseTypeEnum;
|
|
|
+import com.ylx.shopingfundsdetail.mapper.ShoppingFundsDetailMapper;
|
|
|
import com.ylx.shopingfundsdetail.service.ShoppingFundsDetailService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -38,6 +45,11 @@ public class GiftCardOrderServiceImpl extends ServiceImpl<GiftCardOrderMapper, G
|
|
|
private TWxUserService wxUserService;
|
|
|
@Resource
|
|
|
private ShoppingFundsDetailService shoppingFundsDetailService;
|
|
|
+ @Resource
|
|
|
+ private ShoppingFundsDetailMapper shoppingFundsDetailMapper;
|
|
|
+
|
|
|
+ private static final int DETAIL_TYPE_PURCHASE = 0;
|
|
|
+ private static final int DETAIL_TYPE_EXPENSE = 1;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -139,6 +151,61 @@ public class GiftCardOrderServiceImpl extends ServiceImpl<GiftCardOrderMapper, G
|
|
|
shoppingFundsDetailService.addShoppingFundsDetail(dto);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public UserShoppingFundsDetailVO getPcUserShoppingFundsDetail(Page<UserShoppingFundsDetailItemVO> page, UserShoppingFundsDetailQueryDTO dto) {
|
|
|
+ validateShoppingFundsDetailQuery(dto);
|
|
|
+ normalizeTimeRange(dto);
|
|
|
+
|
|
|
+ TWxUser user = wxUserService.getById(dto.getUserId());
|
|
|
+ if (ObjectUtil.isNull(user)) {
|
|
|
+ throw new IllegalArgumentException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserShoppingFundsSummaryVO summary;
|
|
|
+ Page<UserShoppingFundsDetailItemVO> detailPage;
|
|
|
+ // 支出
|
|
|
+ if (DETAIL_TYPE_EXPENSE == dto.getDetailType()) {
|
|
|
+ summary = shoppingFundsDetailMapper.selectPcExpenseShoppingFundsSummary(dto);
|
|
|
+ detailPage = shoppingFundsDetailMapper.selectPcExpenseShoppingFundsDetail(page, dto);
|
|
|
+ } else {
|
|
|
+ // 购买
|
|
|
+ summary = baseMapper.selectPcPurchaseShoppingFundsSummary(dto);
|
|
|
+ detailPage = baseMapper.selectPcPurchaseShoppingFundsDetail(page, dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ UserShoppingFundsDetailVO vo = new UserShoppingFundsDetailVO();
|
|
|
+ vo.setShoppingFundsBalance(defaultAmount(user.getdBalance()));
|
|
|
+ vo.setTotalAmount(defaultAmount(summary == null ? null : summary.getTotalAmount()));
|
|
|
+ vo.setTotalCount(summary == null || summary.getTotalCount() == null ? 0L : summary.getTotalCount());
|
|
|
+ vo.setPage(detailPage);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateShoppingFundsDetailQuery(UserShoppingFundsDetailQueryDTO dto) {
|
|
|
+ if (dto == null || StringUtils.isBlank(dto.getUserId())) {
|
|
|
+ throw new IllegalArgumentException("userId不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getDetailType() == null) {
|
|
|
+ dto.setDetailType(DETAIL_TYPE_PURCHASE);
|
|
|
+ }
|
|
|
+ if (dto.getDetailType() != DETAIL_TYPE_PURCHASE && dto.getDetailType() != DETAIL_TYPE_EXPENSE) {
|
|
|
+ throw new IllegalArgumentException("明细类型不正确");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void normalizeTimeRange(UserShoppingFundsDetailQueryDTO dto) {
|
|
|
+ if (StringUtils.isNotBlank(dto.getStartTime()) && dto.getStartTime().trim().length() == 10) {
|
|
|
+ dto.setStartTime(dto.getStartTime().trim() + " 00:00:00");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getEndTime()) && dto.getEndTime().trim().length() == 10) {
|
|
|
+ dto.setEndTime(dto.getEndTime().trim() + " 23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal defaultAmount(BigDecimal amount) {
|
|
|
+ return amount == null ? BigDecimal.ZERO : amount;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成唯一订单号
|
|
|
*/
|
|
|
@@ -205,4 +272,4 @@ public class GiftCardOrderServiceImpl extends ServiceImpl<GiftCardOrderMapper, G
|
|
|
|
|
|
order.setCommissionAmount(commissionAmount);
|
|
|
}
|
|
|
-}
|
|
|
+}
|