完成新增会员接口开发
This commit is contained in:
parent
537b9b408b
commit
d2982d3528
|
|
@ -0,0 +1,33 @@
|
|||
package cn.ysk.cashier.controller.member;
|
||||
|
||||
import cn.ysk.cashier.mybatis.service.MemberService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tankaikai
|
||||
* @since 2024-10-24 16:13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/member")
|
||||
@Api(tags="会员管理")
|
||||
public class MemberController {
|
||||
|
||||
@Resource
|
||||
private MemberService memberService;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("保存")
|
||||
public ResponseEntity save(@RequestBody Map<String, Object> map) {
|
||||
memberService.createMember(map);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
* @author tankaikai
|
||||
* @since 2024-10-24 16:15
|
||||
*/
|
||||
public interface MemberService {
|
||||
|
||||
void createMember(Map<String, Object> map);
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpUserInfoMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.ShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.service.MemberService;
|
||||
import cn.ysk.cashier.pojo.TbUserInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2024-10-24 16:16
|
||||
*/
|
||||
@Service
|
||||
public class MemberServiceImpl implements MemberService {
|
||||
|
||||
@Resource
|
||||
private ShopUserMapper shopUserMapper;
|
||||
@Resource
|
||||
private MpUserInfoMapper mpUserInfoMapper;
|
||||
|
||||
@Override
|
||||
public void createMember(Map<String, Object> map) {
|
||||
if (ObjectUtil.isEmpty(map) || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))
|
||||
|| !map.containsKey("phone") || ObjectUtil.isEmpty(map.get("phone"))
|
||||
|| !map.containsKey("nickName") || ObjectUtil.isEmpty(map.get("nickName"))
|
||||
|| !map.containsKey("sex") || ObjectUtil.isEmpty(map.get("sex"))
|
||||
|| !map.containsKey("level") || ObjectUtil.isEmpty(map.get("level")) ||
|
||||
!map.containsKey("birthDay") || ObjectUtil.isEmpty(map.get("birthDay"))
|
||||
) {
|
||||
throw new BadRequestException("请求参数不允许为空");
|
||||
}
|
||||
String phone = String.valueOf(map.get("phone"));
|
||||
|
||||
String shopId = String.valueOf(map.get("shopId"));
|
||||
|
||||
List<TbShopUser> tbShopUsers = shopUserMapper.selectList(Wrappers.<TbShopUser>lambdaQuery().eq(TbShopUser::getShopId, shopId).eq(TbShopUser::getTelephone, phone));
|
||||
|
||||
if (ObjectUtil.isNotEmpty(tbShopUsers) && tbShopUsers.stream().filter(it -> "1".equals(it.getIsVip().toString())).count() > 0) {
|
||||
throw new BadRequestException("会员已存在");
|
||||
}
|
||||
|
||||
Long count = mpUserInfoMapper.selectCount(Wrappers.<TbUserInfo>lambdaQuery().eq(TbUserInfo::getTelephone, phone));
|
||||
if (count > 1) {
|
||||
throw new BadRequestException("相同的手机号已存在多个记录");
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(tbShopUsers) && ObjectUtil.isNotEmpty(tbShopUsers)) {
|
||||
TbShopUser tbShopUser = tbShopUsers.get(0);
|
||||
tbShopUser.setTelephone(phone);
|
||||
tbShopUser.setBirthDay(String.valueOf(map.get("birthDay")));
|
||||
tbShopUser.setName(String.valueOf(map.get("nickName")));
|
||||
tbShopUser.setSex(Convert.toInt(map.get("sex")));
|
||||
tbShopUser.setLevel(Convert.toInt(map.get("level")));
|
||||
tbShopUser.setIsVip(1);
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUser.setJoinTime(new Timestamp(System.currentTimeMillis()));
|
||||
shopUserMapper.updateById(tbShopUser);
|
||||
return;
|
||||
}
|
||||
|
||||
TbShopUser tbShopUser = new TbShopUser();
|
||||
TbUserInfo tbUserInfo = mpUserInfoMapper.selectOne(Wrappers.<TbUserInfo>lambdaQuery().eq(TbUserInfo::getTelephone, phone));
|
||||
if (tbUserInfo != null) {
|
||||
tbShopUser.setUserId(tbUserInfo.getId().toString());
|
||||
}
|
||||
tbShopUser.setAmount(BigDecimal.ZERO);
|
||||
tbShopUser.setCreditAmount(BigDecimal.ZERO);
|
||||
tbShopUser.setConsumeAmount(BigDecimal.ZERO);
|
||||
tbShopUser.setConsumeNumber(0);
|
||||
tbShopUser.setLevelConsume(BigDecimal.ZERO);
|
||||
tbShopUser.setStatus(1);
|
||||
tbShopUser.setShopId(shopId);
|
||||
tbShopUser.setTelephone(phone);
|
||||
tbShopUser.setBirthDay(String.valueOf(map.get("birthDay")));
|
||||
tbShopUser.setName(String.valueOf(map.get("nickName")));
|
||||
tbShopUser.setSex(Convert.toInt((map.get("sex"))));
|
||||
tbShopUser.setLevel(Convert.toInt(map.get("level")));
|
||||
String code = RandomUtil.randomNumbers(8);
|
||||
tbShopUser.setCode(code);
|
||||
tbShopUser.setIsVip(1);
|
||||
tbShopUser.setCreatedAt(System.currentTimeMillis());
|
||||
tbShopUser.setJoinTime(new Timestamp(System.currentTimeMillis()));
|
||||
shopUserMapper.insert(tbShopUser);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue