发放传参

This commit is contained in:
2025-12-05 14:09:33 +08:00
parent e345c409dd
commit 0879143285
6 changed files with 36 additions and 15 deletions

View File

@@ -24,7 +24,7 @@ public class UChatCouponController {
*/
@PostMapping("/grant")
public CzgResult<Boolean> grantChatCoupon(@RequestBody ChatCouponGrantDTO chatCouponGrant) {
chatCouponService.grantChatCoupon(chatCouponGrant.getId(), chatCouponGrant.getShopUserId(), chatCouponGrant.getUserId());
chatCouponService.grantChatCoupon(chatCouponGrant.getId(), chatCouponGrant.getShopId(), chatCouponGrant.getUserId());
return CzgResult.success(true);
}
}

View File

@@ -31,6 +31,11 @@ public interface ShopUserService extends IService<ShopUser> {
*/
Page<InviteUserVO> getInviteUser(Long getDistributionUserId, Long shopId, Long shopUserId, Long distributionLevelId, Integer page, Integer size);
/**
* 会自动获取到用户的主店铺id 然后获取用户信息
* 获取用户信息
*/
ShopUser getUserInfo(Long shopId, Long userId);
boolean updateInfo(ShopUser shopUser);

View File

@@ -17,6 +17,10 @@ public class ChatCouponGrantDTO {
* 店铺用户ID
*/
private Long shopUserId;
/**
* 店铺ID
*/
private Long shopId;
/**
* 用户ID
*/

View File

@@ -33,7 +33,7 @@ public interface ChatCouponService extends IService<ChatCoupon> {
/**
* 发放优惠券
*/
void grantChatCoupon(Long id, Long shopUserId, Long userId);
void grantChatCoupon(Long id, Long shopId, Long userId);
/**
* 分页查询优惠券发放记录

View File

@@ -63,6 +63,12 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
return shopUser;
}
@Override
public ShopUser getUserInfo(Long shopId, Long userId) {
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
return getOne(QueryWrapper.create().eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, mainShopId));
}
@Override
public boolean updateInfo(ShopUser shopUser) {
return super.updateById(shopUser);
@@ -71,13 +77,9 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public ShopUser getShopUserInfo(Long shopId, long userId) {
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
ShopUser shopUser = queryChain().eq(ShopUser::getUserId, userId).and(q -> {
q.eq(ShopUser::getMainShopId, mainShopId).or(q1 -> {
q1.eq(ShopUser::getSourceShopId, shopId);
});
}).one();
ShopUser shopUser = getUserInfo(shopId, userId);
if (shopUser == null) {
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
shopUser = new ShopUser();
UserInfo userInfo = userInfoService.getById(userId);
BeanUtil.copyProperties(userInfo, shopUser);

View File

@@ -1,6 +1,8 @@
package com.czg.service.market.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.exception.CzgException;
import com.czg.market.dto.ChatCouponDTO;
import com.czg.market.dto.MkShopCouponGiftDTO;
@@ -17,6 +19,7 @@ import com.czg.market.service.ChatCouponService;
import com.czg.service.market.mapper.ChatCouponMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -33,6 +36,9 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
private ShopCouponService couponService;
@Resource
private MkShopCouponRecordService recordService;
@DubboReference
private ShopUserService shopUserService;
@Override
@Transactional
@@ -94,7 +100,7 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
@Override
@Transactional
public void grantChatCoupon(Long id, Long shopUserId, Long userId) {
public void grantChatCoupon(Long id, Long shopId, Long userId) {
ChatCoupon coupon = getById(id);
if (coupon == null) {
throw new CzgException("活动不存在");
@@ -105,7 +111,7 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
boolean exists = recordService.exists(QueryWrapper.create()
.eq(MkShopCouponRecord::getSource, "群聊发放")
.eq(MkShopCouponRecord::getSourceId, coupon.getId())
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
.eq(MkShopCouponRecord::getShopId, shopId)
.eq(MkShopCouponRecord::getUserId, userId)
);
if (exists) {
@@ -122,16 +128,20 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
coupon.setStatus(3);
}
updateById(coupon);
ShopUser shopUser = shopUserService.getUserInfo(shopId, userId);
MkShopCouponRecord record = JSONObject.parseObject(coupon.getCouponJson(), MkShopCouponRecord.class);
record.setShopUserId(shopUserId);
record.setUserId(userId);
// MkShopCouponRecord record = JSONObject.parseObject(coupon.getCouponJson(), MkShopCouponRecord.class);
// record.setShopUserId(shopUserId);
// record.setUserId(userId);
// recordService.grantChatCoupon(record, coupon.getGetLimit());
if (shopUser == null) {
throw new CzgException("用户不存在");
}
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO()
.setCouponId(coupon.getCouponId())
.setShopId(coupon.getShopId())
.setShopId(shopId)
.setSourceId(coupon.getId())
.setShopUserId(shopUserId)
.setShopUserId(shopUser.getId())
.setSource("群聊发放");
recordService.receiveCoupon(giftDTO, coupon.getGetLimit(), false);
}