消费金额
This commit is contained in:
parent
f078333d37
commit
ab97f4aa3e
|
|
@ -29,5 +29,7 @@ public interface MkDistributionUserMapper extends BaseMapper<MkDistributionUser>
|
|||
/**
|
||||
* 统计消费金额
|
||||
*/
|
||||
BigDecimal getOrderConsumeAmountByList(Long shopId, List<Long> userIds,Long userId);
|
||||
BigDecimal getOrderConsumeAmountByList(Long shopId, Long inviterId);
|
||||
|
||||
BigDecimal getOrderConsumeAmountById(Long shopId, Long userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,11 +338,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
if (mkDistributionConfig == null || !"cost".equals(mkDistributionConfig.getUpgradeType())) {
|
||||
return;
|
||||
}
|
||||
List<Long> userIds = shopUserService.listAs(QueryWrapper.create()
|
||||
.select(ShopUser::getUserId)
|
||||
.eq(ShopUser::getDistributionUserId, shopUserId), Long.class);
|
||||
userIds.add(distributionUser.getUserId());
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountByList(shopId, userIds, null);
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountByList(shopId, distributionUser.getId());
|
||||
BigDecimal ownTotalAmount = mapper.getOrderConsumeAmountById(shopId, distributionUser.getUserId());
|
||||
totalAmount = totalAmount.add(ownTotalAmount);
|
||||
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||
.eq(MkDistributionLevelConfig::getShopId, distributionUser.getShopId())
|
||||
.le(MkDistributionLevelConfig::getCostAmount, totalAmount)
|
||||
|
|
@ -431,7 +429,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
param.setId(param.getId());
|
||||
param.setUserId(shopUser.getUserId());
|
||||
param.setInviteCode(CzgRandomUtils.randomString(10));
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountByList(param.getShopId(), null, param.getUserId());
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountById(param.getShopId(), param.getUserId());
|
||||
param.setConsumeAmount(totalAmount);
|
||||
save(param);
|
||||
ShopUser shopUser2 = new ShopUser();
|
||||
|
|
@ -470,11 +468,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
.le(MkDistributionLevelConfig::getInviteCount, distributionUser.getInviteCount())
|
||||
.orderBy(MkDistributionLevelConfig::getInviteCount).asc().limit(1));
|
||||
} else if ("cost".equals(detail.getUpgradeType())) {
|
||||
List<Long> userIds = shopUserService.listAs(QueryWrapper.create()
|
||||
.select(ShopUser::getUserId)
|
||||
.eq(ShopUser::getDistributionUserId, distributionUser.getId()), Long.class);
|
||||
userIds.add(distributionUser.getUserId());
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountByList(param.getShopId(), userIds, null);
|
||||
BigDecimal totalAmount = mapper.getOrderConsumeAmountByList(param.getShopId(), distributionUser.getId());
|
||||
BigDecimal ownTotalAmount = mapper.getOrderConsumeAmountById(param.getShopId(), distributionUser.getUserId());
|
||||
totalAmount = totalAmount.add(ownTotalAmount);
|
||||
levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||
.eq(MkDistributionLevelConfig::getShopId, distributionUser.getShopId())
|
||||
.le(MkDistributionLevelConfig::getCostAmount, totalAmount)
|
||||
|
|
|
|||
|
|
@ -54,20 +54,25 @@
|
|||
</select>
|
||||
|
||||
<select id="getOrderConsumeAmountByList" resultType="java.math.BigDecimal">
|
||||
SELECT
|
||||
IFNULL( SUM( ord.pay_amount ), 0 ) AS totalAmount
|
||||
FROM
|
||||
tb_shop_user su
|
||||
INNER JOIN tb_order_info ord ON su.user_id = ord.user_id
|
||||
AND ord.shop_id = #{shopId}
|
||||
AND ord.STATUS = 'done'
|
||||
AND ord.pay_type NOT IN ( 'vip_pay', 'credit_pay' )
|
||||
AND ord.paid_time >= su.invite_time
|
||||
WHERE
|
||||
su.distribution_user_id = #{inviterId}
|
||||
</select>
|
||||
|
||||
<select id="getOrderConsumeAmountById" resultType="java.math.BigDecimal">
|
||||
select sum(pay_amount)
|
||||
from tb_order_info
|
||||
where shop_id = #{shopId}
|
||||
AND pay_type NOT IN ('vip_pay', 'credit_pay')
|
||||
and status = 'done'
|
||||
<choose>
|
||||
<when test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</when>
|
||||
<otherwise>
|
||||
and user_id in
|
||||
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue