Blame view

service-acct/src/main/java/com/java110/acct/integral/impl/ComputeGiftIntegralImpl.java 4.33 KB
88e030b7   王彪总   init project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  package com.java110.acct.integral.impl;
  
  import com.alibaba.fastjson.JSONObject;
  import com.java110.acct.integral.IComputeGiftIntegral;
  import com.java110.dto.integral.GiftIntegralDto;
  import com.java110.dto.integral.IntegralRuleConfigDto;
  import com.java110.dto.integral.IntegralRuleFeeDto;
  import com.java110.dto.mall.MallConfigDto;
  import com.java110.intf.acct.IIntegralRuleConfigV1InnerServiceSMO;
  import com.java110.intf.acct.IIntegralRuleFeeV1InnerServiceSMO;
  import com.java110.intf.job.IMallInnerServiceSMO;
  import com.java110.utils.cache.MappingCache;
  import com.java110.utils.util.DateUtil;
  import com.java110.utils.util.ListUtil;
  import com.java110.vo.ResultVo;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import java.math.BigDecimal;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * 计算赠送积分
   */
  @Service
  public class ComputeGiftIntegralImpl implements IComputeGiftIntegral {
      private static final String MALL_DOMAIN = "MALL";
  
      @Autowired
      private IMallInnerServiceSMO mallInnerServiceSMOImpl;
  
      @Autowired
      private IIntegralRuleFeeV1InnerServiceSMO integralRuleFeeV1InnerServiceSMOImpl;
  
  
      @Autowired
      private IIntegralRuleConfigV1InnerServiceSMO integralRuleConfigV1InnerServiceSMOImpl;
  
  
      @Override
      public GiftIntegralDto gift(double payMoney, int month, String communityId) {
  
          String mallSwitch = MappingCache.getValue(MALL_DOMAIN, "MALL_SWITCH");
  
          if (!"ON".equals(mallSwitch)) {
              return new GiftIntegralDto(0, 0, communityId);
          }
  
          IntegralRuleFeeDto integralRuleFeeDto = new IntegralRuleFeeDto();
          integralRuleFeeDto.setCurTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
          integralRuleFeeDto.setCommunityId(communityId);
          List<IntegralRuleFeeDto> integralRuleFeeDtos = integralRuleFeeV1InnerServiceSMOImpl.queryIntegralRuleFees(integralRuleFeeDto);
  
          if (ListUtil.isNull(integralRuleFeeDtos)) {
              return new GiftIntegralDto(0, 0, communityId);
          }
  
          List<String> ruleIds = new ArrayList<>();
          for (IntegralRuleFeeDto tmpCouponRuleFeeDto : integralRuleFeeDtos) {
              ruleIds.add(tmpCouponRuleFeeDto.getRuleId());
          }
  
          IntegralRuleConfigDto integralRuleConfigDto = new IntegralRuleConfigDto();
          integralRuleConfigDto.setRuleIds(ruleIds.toArray(new String[ruleIds.size()]));
          List<IntegralRuleConfigDto> integralRuleConfigDtos = integralRuleConfigV1InnerServiceSMOImpl.queryIntegralRuleConfigs(integralRuleConfigDto);
  
          if (ListUtil.isNull(integralRuleConfigDtos)) {
              return new GiftIntegralDto(0, 0, communityId);
          }
  
          int quantity = computeOneIntegralQuantity(integralRuleConfigDtos.get(0), payMoney, month);
  
          if (quantity <= 0) {
              return new GiftIntegralDto(0, 0, communityId);
          }
  
          double money = mallInnerServiceSMOImpl.computeIntegralMoney(quantity);
  
          MallConfigDto mallConfigDto = new MallConfigDto();
          mallConfigDto = mallInnerServiceSMOImpl.getMallConfig(mallConfigDto);
  
  
  
          return new GiftIntegralDto(quantity, money, communityId,
                  integralRuleFeeDtos.get(0).getRuleId(),
                  integralRuleConfigDtos.get(0).getRuleName(),
                  integralRuleConfigDtos.get(0).getConfigId(),
                  integralRuleConfigDtos.get(0).getConfigName(),
                  mallConfigDto.getPlatformMchId(),
                  mallConfigDto.getPlatformMchName()
                  );
      }
  
      public int computeOneIntegralQuantity(IntegralRuleConfigDto integralRuleConfigDto, double payMoney, int month) {
          String computingFormula = integralRuleConfigDto.getComputingFormula();
          int amount = 0;
          if (IntegralRuleConfigDto.COMPUTING_FORMULA_MONEY.equals(computingFormula)) { // 满金额送积分
              if (payMoney >= Double.parseDouble(integralRuleConfigDto.getSquarePrice())) {
                  amount = Integer.parseInt(integralRuleConfigDto.getAdditionalAmount());
              }
          } else if (IntegralRuleConfigDto.COMPUTING_FORMULA_MONTH.equals(computingFormula)) { // 满月送积分
              if (month >= Double.parseDouble(integralRuleConfigDto.getSquarePrice())) {
                  amount = Integer.parseInt(integralRuleConfigDto.getAdditionalAmount());
              }
          }
          return amount;
      }
  }