店铺会员mq新增--购买时新增

This commit is contained in:
liyj 2026-01-13 18:34:37 +08:00
parent 44d0e633bc
commit 0cf037e6f2
3 changed files with 78 additions and 3 deletions

View File

@ -1,10 +1,20 @@
package com.suisung.mall.account.listener;
import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.client.Channel;
import com.suisung.mall.account.service.AccountUserBindConnectService;
import com.suisung.mall.account.service.AccountUserInfoService;
import com.suisung.mall.common.api.BindCode;
import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.constant.MqConstant;
import com.suisung.mall.common.feignService.ShopService;
import com.suisung.mall.common.modules.account.AccountUserBindConnect;
import com.suisung.mall.common.modules.account.AccountUserInfo;
import com.suisung.mall.common.modules.store.ShopStoreBase;
import com.suisung.mall.common.modules.store.ShopStoreMember;
import com.suisung.mall.common.modules.store.ShopStoreMemberLevel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
@ -14,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Service
@Slf4j
@ -22,6 +33,11 @@ public class DealUserInfoListener {
@Autowired
private AccountUserInfoService accountUserInfoService;
@Autowired
private ShopService shopService;
@Autowired
private AccountUserBindConnectService accountUserBindConnectService;
@RabbitHandler
public void listener(byte[] data, Channel channel, Message message) throws IOException, InterruptedException {
@ -39,6 +55,7 @@ public class DealUserInfoListener {
boolean flag = accountUserInfoService.saveOrUpdate(accountUserInfo);
if (flag) {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
dealStoreMember(accountUserInfo);
} else {
log.error("消息消费失败执行dealUserInfo异常当前用户编号{}", accountUserInfo.getUser_id());
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
@ -50,4 +67,56 @@ public class DealUserInfoListener {
Thread.sleep(1000);
}
}
private void dealStoreMember(AccountUserInfo accountUserInfo){
if(null!=accountUserInfo.getStore_id()){
Integer store_id = accountUserInfo.getStore_id();
Integer user_id = accountUserInfo.getUser_id();
ShopStoreMember params=new ShopStoreMember();
params.setUserId(user_id);
params.setStoreId(store_id);
List<ShopStoreMember> shopStoreMembers= shopService.findShopStoreMemberList(params);
ShopStoreBase shopStoreBase= shopService.getShopStoreBase(store_id);
if(shopStoreMembers.isEmpty()&&shopStoreBase!=null){
QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bind_id", "+86"+accountUserInfo.getUser_mobile())//+86的
.eq("bind_type", BindCode.MOBILE)
.eq("user_type", 0)
.eq("user_id", user_id)
.eq("bind_active", CommonConstant.Enable)
.orderByAsc("bind_time");
List<AccountUserBindConnect> accountUserBindConnectList = accountUserBindConnectService.list(queryWrapper);
if (!accountUserBindConnectList.isEmpty()){
AccountUserBindConnect accountUserBindConnect= accountUserBindConnectList.get(0);
ShopStoreMember shopStoreMember = new ShopStoreMember();
shopStoreMember.setStoreName(shopStoreBase.getStore_name());
shopStoreMember.setStoreId(shopStoreBase.getStore_id());
shopStoreMember.setUserId(user_id);
shopStoreMember.setBind_openid(accountUserBindConnect.getBind_openid());
shopStoreMember.setUserNickname(accountUserBindConnect.getBind_nickname());
shopStoreMember.setUserAccount(accountUserBindConnect.getBind_id());
ShopStoreMember saveShopStoreMember= shopService.saveShopStoreMember(shopStoreMember);
ShopStoreMemberLevel shopStoreMemberLevel = getShopStoreMemberLevel(shopStoreBase, saveShopStoreMember);
shopStoreMemberLevel.setUserId(user_id);
shopService.saveShopStoreMemberLevel(shopStoreMemberLevel);
}
}
}
}
/**
* 店铺会员初始化信息
* @param shopStoreBase
* @param shopStoreMember
* @return
*/
private ShopStoreMemberLevel getShopStoreMemberLevel(ShopStoreBase shopStoreBase, ShopStoreMember shopStoreMember) {
ShopStoreMemberLevel shopStoreMemberLevel=new ShopStoreMemberLevel();
shopStoreMemberLevel.setStoreId(shopStoreBase.getStore_id());
shopStoreMemberLevel.setStoreMemberId(shopStoreMember.getStore_member_id());
shopStoreMemberLevel.setUserLevelName("v1");
shopStoreMemberLevel.setUserLevelId(1001);
shopStoreMemberLevel.setMemberLevelId(1001);
shopStoreMemberLevel.setMemberLevelName("v1");
return shopStoreMemberLevel;
}
}

View File

@ -179,7 +179,7 @@ public class AccountUserInfoServiceImpl extends BaseServiceImpl<AccountUserInfoM
// 需要设置经验值设置为0否则忽略不计
QueryWrapper<AccountBaseUserLevel> levelQueryWrapper = new QueryWrapper<>();
levelQueryWrapper.le("user_level_spend", user_spend_total)
.gt("user_level_spend", 0).orderByDesc("user_level_spend");
.gt("user_level_spend", BigDecimal.ZERO).orderByDesc("user_level_spend");
level_row = accountBaseUserLevelService.findOne(levelQueryWrapper);
}
@ -225,7 +225,7 @@ public class AccountUserInfoServiceImpl extends BaseServiceImpl<AccountUserInfoM
BigDecimal storeSpend=NumberUtil.add(updateShopStoreMemberLevel.getUserLevelSpend(),user_store_spend_total);//店铺会员总消费
QueryWrapper<AccountBaseUserLevel> levelQueryWrapper = new QueryWrapper<>();
levelQueryWrapper.le("user_level_spend", storeSpend)
.gt("user_level_spend", 0).orderByDesc("user_level_spend");
.gt("user_level_spend", BigDecimal.ZERO).orderByDesc("user_level_spend");
level_row = accountBaseUserLevelService.findOne(levelQueryWrapper);
updateShopStoreMemberLevel.setUserLevelSpend(storeSpend);
if(level_row != null && CheckUtil.isNotEmpty(level_row.getUser_level_id())){

View File

@ -1,6 +1,7 @@
package com.suisung.mall.common.modules.account;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.suisung.mall.common.annotation.OssMedia;
@ -119,5 +120,10 @@ public class AccountUserInfo implements Serializable {
@ApiModelProperty(value = "渠道编码")
private Integer ucc_id;
/**
* 同步会员到店铺会员与消息队列UserLevelTO关联
*/
@ApiModelProperty(value = "店铺id")
@TableField(exist = false)
private Integer store_id;
}