| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoManageMapper;
|
| | | import com.yeshi.fanli.dto.order.OrderHongBaoRateParams;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoManage;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.exception.order.HongBaoException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | |
|
| | |
| | | HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKey(key);
|
| | | if (hongBaoManage != null)
|
| | | hongBaoManage.getValue();
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据键值与时间查询比例
|
| | | * |
| | | * @param key
|
| | | * @param time
|
| | | * @return
|
| | | */
|
| | | public BigDecimal getByKeyAndMaxTime(String key, Long time) {
|
| | | if (time == null)
|
| | | time = System.currentTimeMillis();
|
| | | HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
|
| | | if (hongBaoManage == null)
|
| | | hongBaoManage = hongBaoManageMapper.selectByKey(key);
|
| | | if (hongBaoManage != null)
|
| | | return new BigDecimal(hongBaoManage.getValue());
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | return new BigDecimal(0);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getVIPFanLiRate(long time) {
|
| | | String key = "hongbao_goods_proportion_vip";
|
| | | HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
|
| | | if (hongBaoManage == null)
|
| | | hongBaoManage = hongBaoManageMapper.selectByKey(key);
|
| | | if (hongBaoManage != null)
|
| | | return new BigDecimal(hongBaoManage.getValue());
|
| | | LogHelper.error("获取返利分成比例出错");
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getVIPShareRate(long time) {
|
| | | String key = "share_proportion_vip";
|
| | | HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
|
| | | if (hongBaoManage == null)
|
| | | hongBaoManage = hongBaoManageMapper.selectByKey(key);
|
| | | if (hongBaoManage != null)
|
| | | return new BigDecimal(hongBaoManage.getValue());
|
| | | LogHelper.error("获取返利分成比例出错");
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getVIPFanLiRate() {
|
| | | return getVIPFanLiRate(System.currentTimeMillis());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getVIPShareRate() {
|
| | | return getVIPShareRate(System.currentTimeMillis());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取比例
|
| | | * |
| | | * @param level
|
| | | * 0-本级 1-下级 2-下下级
|
| | | * @param orderType
|
| | | * @param isVip本级是否为VIP
|
| | | * @param isWorkerVip下级是否为VIP
|
| | | * @return
|
| | | */
|
| | | public BigDecimal getRate(OrderHongBaoRateParams params) throws HongBaoException {
|
| | | if (params == null)
|
| | | throw new HongBaoException(1, "比例参数错误");
|
| | |
|
| | | long time = params.getOrderCreateTime().getTime();
|
| | |
|
| | | if (params.getLevel() == 0) {// 本级
|
| | |
|
| | | if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {
|
| | | if (params.isVip())
|
| | | return getVIPFanLiRate(time);
|
| | | else
|
| | | return getFanLiRate(time);
|
| | | } else {
|
| | | if (params.isVip())
|
| | | return getVIPShareRate(time);
|
| | | else
|
| | | return getShareRate(time);
|
| | | }
|
| | |
|
| | | } else if (params.getLevel() == 1) {// 上级
|
| | | if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {// 自购
|
| | | if (params.isSubsidy()) {// 补贴比例
|
| | | if (params.isVip()) {// 下级为会员不补贴
|
| | | return new BigDecimal("0");
|
| | | } else {
|
| | | return getInviteFirstLevelSubsidyRate(time);
|
| | | }
|
| | | } else {// 奖金比例
|
| | | if (params.isVip()) {
|
| | | return getByKeyAndMaxTime("new_invite_vip_6", time);
|
| | | } else {
|
| | | return getByKeyAndMaxTime("new_invite_6", time);
|
| | | }
|
| | | }
|
| | | } else {// 分享
|
| | | if (params.isVip()) {
|
| | | return getByKeyAndMaxTime("new_share_vip_21", time);
|
| | | } else {
|
| | | return getByKeyAndMaxTime("new_share_21", time);
|
| | | }
|
| | | }
|
| | | } else if (params.getLevel() == 2) {// 上上级
|
| | | if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {// 自购
|
| | | if (params.isSubsidy()) {// 补贴比例
|
| | | if (params.isVip()) {// 下下级为会员不补贴
|
| | | return new BigDecimal("0");
|
| | | } else {
|
| | | return getInviteSecondLevelSubsidyRate(time);
|
| | | }
|
| | | } else {// 奖金比例
|
| | | if (params.isVip())
|
| | | return new BigDecimal("0");
|
| | | else
|
| | | return getByKeyAndMaxTime("new_invite_7", time);
|
| | | }
|
| | | } else {// 分享
|
| | | if (params.isVip())
|
| | | return new BigDecimal("0");
|
| | | else
|
| | | return getByKeyAndMaxTime("new_share_22", time);
|
| | | }
|
| | | }
|
| | | throw new HongBaoException(2, "未匹配到比例参数");
|
| | | }
|
| | |
|
| | | }
|