店铺会员新增

This commit is contained in:
张松
2025-02-15 11:28:08 +08:00
parent ec0809a783
commit 95c56e1b03
4 changed files with 90 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
package com.czg.controller.admin;
import com.czg.account.dto.shopuser.ShopUserAddDTO;
import com.czg.account.dto.shopuser.ShopUserEditDTO;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
@@ -47,6 +48,16 @@ public class ShopUserController {
return CzgResult.success(shopUserService.getPage(key, isVip));
}
/**
* 店铺用户信息添加
* @return 是否成功
*/
@SaAdminCheckPermission("shopUser:add")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) {
return CzgResult.success(shopUserService.add(StpKit.USER.getShopId(), shopUserAddDTO));
}
/**
* 店铺用户信息修改
* @return 是否成功

View File

@@ -2,21 +2,62 @@ package com.czg.account.dto.shopuser;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
public record ShopUserAddDTO(@NotEmpty(message = "店铺名称不为空") String shopName,
@NotEmpty(message = "logo不为空") String logo,
@NotEmpty String profiles,
@NotNull(message = "店铺类型不为空") Integer shopType,
@NotEmpty(message = "经营模式不为空") String registerType,
@NotEmpty(message = "账号不为空") String loginName,
@NotEmpty(message = "密码不为空") String loginPwd,
@NotEmpty(message = "经度不为空") String lat,
@NotEmpty(message = "维度不为空") String lng,
@NotEmpty(message = "详细地址不为空") String address,
@NotNull(message = "店铺状态不为空") Integer status,
String detail,
String phone,
String activateCode,
String coverImg,
String chainName) {
import java.math.BigDecimal;
/**
* @author Administrator
*/
@Data
public class ShopUserAddDTO {
/**
* 用户头像
*/
private String headImg;
/**
* 用户昵称
*/
@NotEmpty(message = "用户昵称不为空")
private String nickName;
/**
* 电话号码
*/
@NotEmpty(message = "手机号不为空")
private String phone;
/**
* 会员生日
*/
private String birthDay;
/**
* 0-女 1男
*/
private Integer sex;
/**
* 用户Id
*/
@NotNull(message = "用户id不为空")
private Long userId;
/**
* 账户积分
*/
private Integer accountPoints;
/**
* 钱包余额
*/
private BigDecimal amount;
/**
* 是否会员,
*/
private Integer isVip;
}

View File

@@ -1,5 +1,6 @@
package com.czg.account.service;
import com.czg.account.dto.shopuser.ShopUserAddDTO;
import com.czg.account.dto.shopuser.ShopUserEditDTO;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
@@ -24,4 +25,7 @@ public interface ShopUserService extends IService<ShopUser> {
ShopUserSummaryDTO getSummary(Long shopId, Integer isVip);
ShopUser getShopUserInfo(Long shopId, long userId);
Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO);
}

View File

@@ -2,6 +2,7 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.czg.account.dto.shopuser.ShopUserAddDTO;
import com.czg.account.dto.shopuser.ShopUserEditDTO;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
@@ -102,4 +103,21 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser>
}
return shopUser;
}
@Override
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
long userCount = userInfoService.queryChain().eq(UserInfo::getId, shopUserAddDTO.getUserId()).count();
if (userCount == 0) {
throw new ApiNotPrintException("用户信息不存在");
}
long count = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, shopUserAddDTO.getUserId()).count();
if (count > 0) {
throw new ApiNotPrintException("此用户已存在");
}
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
shopUser.setShopId(shopId);
shopUser.setJoinTime(shopUser.getIsVip() != null &&shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
return save(shopUser);
}
}