|
|
@@ -13,6 +13,8 @@ import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserPlatDistributeRateMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
|
+import com.cyksj.mapper.shop.YhShopMapper;
|
|
|
+import com.cyksj.mapper.shop.YhShopUserPlatDistributeRateMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.UserDistributeReq;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -56,6 +58,10 @@ public class DistributeServiceImpl implements DistributeService {
|
|
|
|
|
|
private final CouponDistributePopularizeMapper couponDistributePopularizeMapper;
|
|
|
|
|
|
+ private final YhShopUserPlatDistributeRateMapper yhShopUserPlatDistributeRateMapper;
|
|
|
+
|
|
|
+ private final YhShopMapper yhShopMapper;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public void insertDistribute(UserDistributeReq userDistributeReq) {
|
|
|
@@ -99,7 +105,11 @@ public class DistributeServiceImpl implements DistributeService {
|
|
|
if (userDistributeReq.getId() == null || userDistributeReq.getId() < 1) {
|
|
|
throw BusinessRuntimeException.getInstance("id错误");
|
|
|
}
|
|
|
- UserDistribute userDistribute = new UserDistribute();
|
|
|
+ Long id = userDistributeReq.getId();
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectById(id);
|
|
|
+ if (userDistribute == null || !userDistribute.getDeleted()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
userDistribute.setId(userDistributeReq.getId());
|
|
|
userDistribute.setRemark(userDistributeReq.getRemark());
|
|
|
Long businessId = userDistributeReq.getBusinessId();
|
|
|
@@ -112,6 +122,9 @@ public class DistributeServiceImpl implements DistributeService {
|
|
|
userDistribute.setBusinessId(businessId);
|
|
|
}
|
|
|
userDistributeMapper.updateById(userDistribute);
|
|
|
+ YhShop yhShop = yhShopMapper.selectOne(Wrappers.lambdaQuery(YhShop.class)
|
|
|
+ .eq(YhShop::getUserId, userDistribute.getUserId())
|
|
|
+ .eq(YhShop::getVerifyStatus, YhShop.Status.success).last("limit 1"));
|
|
|
for (UserPlatDistributeRate rate : userDistributeReq.getRates()) {
|
|
|
if (rate.getRate() < 0 || rate.getRate() > 100) {
|
|
|
throw new BusinessRuntimeException("比例错误");
|
|
|
@@ -133,10 +146,35 @@ public class DistributeServiceImpl implements DistributeService {
|
|
|
try {
|
|
|
userPlatDistributeRateMapper.insert(rate);
|
|
|
} catch (DuplicateKeyException e) {
|
|
|
-
|
|
|
+ userPlatDistributeRateMapper.update(null, Wrappers.lambdaUpdate(UserPlatDistributeRate.class)
|
|
|
+ .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
+ .eq(UserPlatDistributeRate::getGoodsId, rate.getGoodsId())
|
|
|
+ .set(UserPlatDistributeRate::getRate, rate.getRate()));
|
|
|
+ }
|
|
|
+ if (yhShop != null) {
|
|
|
+ try {
|
|
|
+ YhShopUserPlatDistributeRate yhShopUserPlatDistributeRate = new YhShopUserPlatDistributeRate();
|
|
|
+ yhShopUserPlatDistributeRate.setRate(rate.getRate());
|
|
|
+ yhShopUserPlatDistributeRate.setGoodsId(rate.getGoodsId());
|
|
|
+ yhShopUserPlatDistributeRate.setUserId(userDistribute.getUserId());
|
|
|
+ yhShopUserPlatDistributeRateMapper.insert(yhShopUserPlatDistributeRate);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ //同步店铺分销比例
|
|
|
+ yhShopUserPlatDistributeRateMapper.update(null, Wrappers.lambdaUpdate(YhShopUserPlatDistributeRate.class)
|
|
|
+ .eq(YhShopUserPlatDistributeRate::getUserId, userDistribute.getUserId())
|
|
|
+ .eq(YhShopUserPlatDistributeRate::getGoodsId, rate.getGoodsId())
|
|
|
+ .set(YhShopUserPlatDistributeRate::getRate, rate.getRate()));
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
userPlatDistributeRateMapper.updateById(rate);
|
|
|
+ if (yhShop != null) {
|
|
|
+ //同步店铺分销比例
|
|
|
+ yhShopUserPlatDistributeRateMapper.update(null, Wrappers.lambdaUpdate(YhShopUserPlatDistributeRate.class)
|
|
|
+ .eq(YhShopUserPlatDistributeRate::getUserId, userDistribute.getUserId())
|
|
|
+ .eq(YhShopUserPlatDistributeRate::getGoodsId, rate.getGoodsId())
|
|
|
+ .set(YhShopUserPlatDistributeRate::getRate, rate.getRate()));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|