| | |
| | | package com.mzl.flower.service; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.mzl.flower.base.cache.MarkupCacheClient; |
| | | import com.mzl.flower.base.cache.StringCacheClient; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | | import com.mzl.flower.constant.Constants; |
| | |
| | | import com.mzl.flower.dto.response.payment.OrderSalesItemChargeDTO; |
| | | import com.mzl.flower.entity.customer.Customer; |
| | | import com.mzl.flower.entity.flower.*; |
| | | import com.mzl.flower.entity.menber.Member; |
| | | import com.mzl.flower.entity.partner.Partner; |
| | | import com.mzl.flower.entity.payment.FeeService; |
| | | import com.mzl.flower.entity.payment.OrderItemSales; |
| | |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.mapper.customer.CustomerMapper; |
| | | import com.mzl.flower.mapper.flower.FlowerCategoryMapper; |
| | | import com.mzl.flower.mapper.member.MemberMapper; |
| | | import com.mzl.flower.mapper.partner.PartnerMapper; |
| | | import com.mzl.flower.mapper.supplier.SupplierMapper; |
| | | import com.mzl.flower.mapper.system.UserMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.oauth2.common.OAuth2AccessToken; |
| | | import org.springframework.security.oauth2.common.OAuth2RefreshToken; |
| | | import org.springframework.security.oauth2.provider.token.TokenStore; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import static java.time.format.DateTimeFormatter.BASIC_ISO_DATE; |
| | | |
| | | @Service |
| | | public class BaseService { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | private FlowerCategoryMapper flowerCategoryMapper; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | protected Member getMember(Long levelId){ |
| | | return memberMapper.selectById(levelId); |
| | | } |
| | | |
| | | @Autowired |
| | | private StringCacheClient stringCacheClient; |
| | | |
| | | @Autowired |
| | | private TokenStore tokenStore; |
| | | |
| | | public static final String TOKEN_KEY = "TOKEN-KEY"; |
| | | |
| | | public static final String SEPARATOR = ":"; |
| | | |
| | | protected double getServiceFeeRate(List<FeeService> fees, Integer saleCount){ |
| | | int sc = saleCount == null ? 0 : saleCount; |
| | |
| | | break; |
| | | } |
| | | } |
| | | fp = fp.add(b); |
| | | fp = fp.add(getAmount(b)); |
| | | dto.setFirstFee(b); |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | fp = fp.add(b); |
| | | fp = fp.add(getAmount(b)); |
| | | dto.setSecondFee(b); |
| | | |
| | | FlowerMarkupSpCg fmpsc = null; |
| | |
| | | break; |
| | | } |
| | | } |
| | | fp = fp.add(b); |
| | | fp = fp.add(getAmount(b)); |
| | | dto.setPartnerFee(b); |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | fp = fp.add(b); |
| | | fp = fp.add(getAmount(b)); |
| | | } |
| | | |
| | | //二次加价 |
| | |
| | | break; |
| | | } |
| | | } |
| | | fp = fp.add(b); |
| | | fp = fp.add(getAmount(b)); |
| | | |
| | | return fp; |
| | | } |
| | |
| | | } |
| | | |
| | | return p; |
| | | } |
| | | |
| | | /** |
| | | * 计算会员单价 |
| | | * |
| | | * @param price |
| | | * @param member |
| | | * @return |
| | | */ |
| | | protected BigDecimal calculateMemberPrice(BigDecimal price, Member member){ |
| | | if(price == null || member == null){ |
| | | return price; |
| | | } |
| | | BigDecimal r = price; |
| | | |
| | | String discountType = member.getDiscountType(); |
| | | if(Constants.DISCOUNT_TYPE.ratio.name().equals(discountType)){ |
| | | BigDecimal discountRatio = getAmount(member.getDiscountRatio()); |
| | | r = price.multiply(discountRatio).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); |
| | | } else if (Constants.DISCOUNT_TYPE.amount.name().equals(discountType)){ |
| | | BigDecimal discountAmount = getAmount(member.getDiscountAmount()); |
| | | r = price.subtract(discountAmount); |
| | | } |
| | | |
| | | if(r.doubleValue() < 0){ |
| | | r = new BigDecimal(0); |
| | | } |
| | | |
| | | return r; |
| | | } |
| | | |
| | | protected Customer getCustomerByUserId(String userId){ |
| | |
| | | return null; |
| | | } |
| | | |
| | | public void removeToken(String userId) { |
| | | String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + userId); |
| | | if (StringUtils.isNotBlank(tokenCache)) { |
| | | //强制删除token,下线 |
| | | if (StringUtils.isNotBlank(tokenCache) && StringUtils.isNotBlank(userId)) { |
| | | stringCacheClient.delete(TOKEN_KEY + SEPARATOR + userId); |
| | | String tokenValue = tokenCache.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim(); |
| | | OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); |
| | | if (accessToken != null && StringUtils.isNotBlank(accessToken.getValue())) { |
| | | tokenStore.removeAccessToken(accessToken); |
| | | OAuth2RefreshToken refreshToken = accessToken.getRefreshToken(); |
| | | tokenStore.removeRefreshToken(refreshToken); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |