| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.account.api.feignClient.*; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserGiveawayTemporaryClient; |
| | | import com.ruoyi.account.api.feignClient.BalanceChangeRecordClient; |
| | | import com.ruoyi.account.api.feignClient.UserPointClient; |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import com.ruoyi.order.service.CommissionService; |
| | | import com.ruoyi.order.service.OrderGoodService; |
| | | import com.ruoyi.order.service.OrderService; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getIsCommission, 2).isNotNull(Order::getAfterSaleTime) |
| | | .eq(Order::getDelFlag, 0).ne(Order::getPayMethod, 3).last(" and after_sale_time <= now()")); |
| | | List<Long> collect = list.stream().map(Order::getId).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | if(collect.isEmpty()){ |
| | | return; |
| | | } |
| | | |
| | |
| | | changeRecord.setId(null); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(changeRecord); |
| | | } |
| | | if(data2.size() > 0){ |
| | | List<Long> ids = data2.stream().map(BalanceChangeRecordCopy::getId).collect(Collectors.toList()); |
| | | balanceChangeRecordClient.deleteBalanceChangeRecordCopyByIds(ids); |
| | | } |
| | | } |
| | | balanceChangeRecordClient.deleteBalanceChangeRecordCopy(order.getId(), Arrays.asList(4)); |
| | | |
| | | List<UserPointCopy> data3 = userPointClient.getUserPointCopy(order.getId(), Arrays.asList(2,8,9,10,14)).getData(); |
| | | if(null != data3){ |
| | |
| | | userPoint.setId(null); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | if(data3.size() > 0){ |
| | | List<Long> ids = data3.stream().map(UserPointCopy::getId).collect(Collectors.toList()); |
| | | userPointClient.deleteUserPointCopyByIds(ids); |
| | | } |
| | | } |
| | | userPointClient.deleteUserPointCopy(order.getId(), Arrays.asList(2,8,9,10,14)); |
| | | |
| | | |
| | | List<ShopBalanceStatementCopy> data4 = shopBalanceStatementClient.getShopBalanceStatementCopy(order.getId(), Arrays.asList(1,2,3)).getData(); |
| | |
| | | shopBalanceStatement.setId(null); |
| | | shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement); |
| | | } |
| | | if(data4.size() > 0){ |
| | | List<Long> ids = data4.stream().map(ShopBalanceStatementCopy::getId).collect(Collectors.toList()); |
| | | shopBalanceStatementClient.deleteShopBalanceStatementCopyByIds(ids); |
| | | } |
| | | } |
| | | shopBalanceStatementClient.deleteShopBalanceStatementCopy(order.getId(), Arrays.asList(1,2,3)); |
| | | |
| | | List<ShopPointCopy> data5 = shopPointClient.getShopPointCopy(order.getId(), Arrays.asList(1,2,3)).getData(); |
| | | if(null != data5){ |
| | |
| | | shopPoint.setId(null); |
| | | shopPointClient.saveShopPoint(shopPoint); |
| | | } |
| | | if(data5.size() > 0){ |
| | | List<Long> ids = data5.stream().map(ShopPointCopy::getId).collect(Collectors.toList()); |
| | | shopPointClient.deleteShopPointCopyByIds(ids); |
| | | } |
| | | } |
| | | shopPointClient.deleteShopPointCopy(order.getId(), Arrays.asList(1,2,3)); |
| | | order.setIsCommission(3); |
| | | orderService.updateById(order); |
| | | |
| | |
| | | balanceChangeRecordCopy.setVipId(superiorLeader.getVipId()); |
| | | balanceChangeRecordCopy.setOrderId(order.getId()); |
| | | balanceChangeRecordCopy.setChangeType(4); |
| | | balanceChangeRecordCopy.setBeforeAmount(balance); |
| | | balanceChangeRecordCopy.setChangeAmount(zdls_price); |
| | | balanceChangeRecordCopy.setAfterAmount(superiorLeader.getBalance()); |
| | | balanceChangeRecordCopy.setDelFlag(0); |
| | | balanceChangeRecordCopy.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordCopy.setChangeDirection(1); |
| | | balanceChangeRecordClient.saveBalanceChangeRecordCopy(balanceChangeRecordCopy); |
| | | } |
| | | //添加积分明细 |
| | | if(zdls_point > 0){ |
| | | UserPointCopy userPointCopy = new UserPointCopy(); |
| | | userPointCopy.setType(2); |
| | | userPointCopy.setHistoricalPoint(lavePoint); |
| | | userPointCopy.setVariablePoint(zdls_point); |
| | | userPointCopy.setBalance(superiorLeader.getLavePoint()); |
| | | userPointCopy.setCreateTime(LocalDateTime.now()); |
| | | userPointCopy.setAppUserId(superiorLeader.getId()); |
| | | userPointCopy.setObjectId(order.getId()); |
| | | userPointCopy.setExtention(order.getOrderNumber()); |
| | | userPointCopy.setChangeDirection(1); |
| | | userPointClient.saveUserPointCopy(userPointCopy); |
| | | //变更等级 |
| | | // appUserClient.vipUpgrade(superiorLeader.getId()); |
| | |
| | | ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); |
| | | shopBalanceStatementCopy.setShopId(shop1.getId()); |
| | | shopBalanceStatementCopy.setType(1); |
| | | shopBalanceStatementCopy.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatementCopy.setVariableAmount(fws_price); |
| | | shopBalanceStatementCopy.setBalance(shop1.getBalance()); |
| | | shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatementCopy.setObjectId(order.getId()); |
| | | shopBalanceStatementCopy.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementCopy.setChangeDirection(1); |
| | | shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); |
| | | } |
| | | //添加积分明细 |
| | | if(fws_point > 0){ |
| | | UserPointCopy userPointCopy = new UserPointCopy(); |
| | | userPointCopy.setType(9); |
| | | userPointCopy.setHistoricalPoint(lavePoint); |
| | | userPointCopy.setVariablePoint(fws_point); |
| | | userPointCopy.setBalance(bdShopAppUser.getLavePoint()); |
| | | userPointCopy.setCreateTime(LocalDateTime.now()); |
| | | userPointCopy.setAppUserId(bdShopAppUser.getId()); |
| | | userPointCopy.setObjectId(order.getId()); |
| | | userPointCopy.setExtention(order.getOrderNumber()); |
| | | userPointCopy.setChangeDirection(1); |
| | | userPointClient.saveUserPointCopy(userPointCopy); |
| | | //变更等级 |
| | | // appUserClient.vipUpgrade(bdShopAppUser.getId()); |
| | | } |
| | | |
| | | if(shopLavePoint > 0){ |
| | | if(fws_point > 0){ |
| | | ShopPointCopy shopPointCopy = new ShopPointCopy(); |
| | | shopPointCopy.setShopId(shop1.getId()); |
| | | shopPointCopy.setType(2); |
| | | shopPointCopy.setHistoricalPoint(shopLavePoint); |
| | | shopPointCopy.setVariablePoint(fws_point); |
| | | shopPointCopy.setBalance(shop1.getLavePoint()); |
| | | shopPointCopy.setCreateTime(LocalDateTime.now()); |
| | | shopPointCopy.setCreateUserId(order.getAppUserId()); |
| | | shopPointCopy.setObjectId(order.getId()); |
| | | shopPointCopy.setOrderNum(order.getOrderNumber()); |
| | | shopPointCopy.setChangeDirection(1); |
| | | shopPointClient.saveShopPointCopy(shopPointCopy); |
| | | } |
| | | } |
| | |
| | | ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); |
| | | shopBalanceStatementCopy.setShopId(shop2.getId()); |
| | | shopBalanceStatementCopy.setType(2); |
| | | shopBalanceStatementCopy.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatementCopy.setVariableAmount(gjfws_price); |
| | | shopBalanceStatementCopy.setBalance(shop2.getBalance()); |
| | | shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatementCopy.setObjectId(order.getId()); |
| | | shopBalanceStatementCopy.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementCopy.setChangeDirection(1); |
| | | shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); |
| | | } |
| | | //添加积分明细 |
| | | if(gjfws_point > 0){ |
| | | UserPointCopy userPointCopy = new UserPointCopy(); |
| | | userPointCopy.setType(14); |
| | | userPointCopy.setHistoricalPoint(lavePoint); |
| | | userPointCopy.setVariablePoint(gjfws_point); |
| | | userPointCopy.setBalance(sjShopAppUser.getLavePoint()); |
| | | userPointCopy.setCreateTime(LocalDateTime.now()); |
| | | userPointCopy.setAppUserId(sjShopAppUser.getId()); |
| | | userPointCopy.setObjectId(order.getId()); |
| | | userPointCopy.setExtention(order.getOrderNumber()); |
| | | userPointCopy.setChangeDirection(1); |
| | | userPointClient.saveUserPointCopy(userPointCopy); |
| | | //变更等级 |
| | | // appUserClient.vipUpgrade(sjShopAppUser.getId()); |
| | |
| | | ShopPointCopy shopPointCopy = new ShopPointCopy(); |
| | | shopPointCopy.setShopId(shop2.getId()); |
| | | shopPointCopy.setType(3); |
| | | shopPointCopy.setHistoricalPoint(shopLavePoint); |
| | | shopPointCopy.setVariablePoint(gjfws_point); |
| | | shopPointCopy.setBalance(shop2.getLavePoint()); |
| | | shopPointCopy.setCreateTime(LocalDateTime.now()); |
| | | shopPointCopy.setCreateUserId(order.getAppUserId()); |
| | | shopPointCopy.setObjectId(order.getId()); |
| | | shopPointCopy.setOrderNum(order.getOrderNumber()); |
| | | shopPointCopy.setChangeDirection(1); |
| | | shopPointClient.saveShopPointCopy(shopPointCopy); |
| | | } |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void calculationCommissionShop(Long orderId) { |
| | | Order order = orderService.getById(orderId); |
| | | //快递单品不进行分佣 |
| | | if(order.getOrderType() == 2 && order.getDistributionMode() == 2){ |
| | | return; |
| | | } |
| | | List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() |
| | | .eq(OrderGood::getOrderId, order.getId())); |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | |
| | | ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); |
| | | shopBalanceStatementCopy.setShopId(shop.getId()); |
| | | shopBalanceStatementCopy.setType(3); |
| | | shopBalanceStatementCopy.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatementCopy.setVariableAmount(hxmd_price); |
| | | shopBalanceStatementCopy.setBalance(shop.getBalance()); |
| | | shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatementCopy.setObjectId(order.getId()); |
| | | shopBalanceStatementCopy.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementCopy.setChangeDirection(1); |
| | | shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); |
| | | } |
| | | //添加积分明细 |
| | | if(hxmd_point > 0){ |
| | | UserPointCopy userPointCopy = new UserPointCopy(); |
| | | userPointCopy.setType(8); |
| | | userPointCopy.setHistoricalPoint(lavePoint); |
| | | userPointCopy.setVariablePoint(hxmd_point); |
| | | userPointCopy.setBalance(shopAppUser.getLavePoint()); |
| | | userPointCopy.setCreateTime(LocalDateTime.now()); |
| | | userPointCopy.setAppUserId(shopAppUser.getId()); |
| | | userPointCopy.setObjectId(order.getId()); |
| | | userPointCopy.setExtention(order.getOrderNumber()); |
| | | userPointCopy.setChangeDirection(1); |
| | | userPointClient.saveUserPointCopy(userPointCopy); |
| | | //变更等级 |
| | | // appUserClient.vipUpgrade(shopAppUser.getId()); |
| | |
| | | ShopPointCopy shopPointCopy = new ShopPointCopy(); |
| | | shopPointCopy.setShopId(shop.getId()); |
| | | shopPointCopy.setType(1); |
| | | shopPointCopy.setHistoricalPoint(shopLavePoint); |
| | | shopPointCopy.setVariablePoint(hxmd_point); |
| | | shopPointCopy.setBalance(shop.getLavePoint()); |
| | | shopPointCopy.setCreateTime(LocalDateTime.now()); |
| | | shopPointCopy.setCreateUserId(order.getAppUserId()); |
| | | shopPointCopy.setObjectId(order.getId()); |
| | | shopPointCopy.setOrderNum(order.getOrderNumber()); |
| | | shopPointCopy.setChangeDirection(1); |
| | | shopPointClient.saveShopPointCopy(shopPointCopy); |
| | | } |
| | | } |
| | |
| | | if(js_point > 0){ |
| | | UserPointCopy userPointCopy = new UserPointCopy(); |
| | | userPointCopy.setType(10); |
| | | userPointCopy.setHistoricalPoint(lavePoint); |
| | | userPointCopy.setVariablePoint(js_point); |
| | | userPointCopy.setBalance(technicianAppUser.getLavePoint()); |
| | | userPointCopy.setCreateTime(LocalDateTime.now()); |
| | | userPointCopy.setAppUserId(technicianAppUser.getId()); |
| | | userPointCopy.setObjectId(order.getId()); |
| | | userPointCopy.setExtention(order.getOrderNumber()); |
| | | userPointCopy.setChangeDirection(1); |
| | | userPointClient.saveUserPointCopy(userPointCopy); |
| | | //变更等级 |
| | | // appUserClient.vipUpgrade(technicianAppUser.getId()); |