Merge remote-tracking branch 'origin/dev' into test

This commit is contained in:
Tankaikai
2024-10-24 16:41:46 +08:00
12 changed files with 220 additions and 7 deletions

View File

@@ -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();
}
}

View File

@@ -100,4 +100,5 @@ public class TbShopInfoController {
tbShopInfoService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}
}

View File

@@ -17,10 +17,7 @@ package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.annotation.AnonymousAccess;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shoptable.AddCartDTO;
import cn.ysk.cashier.dto.shoptable.ClearCartDTO;
import cn.ysk.cashier.dto.shoptable.RemoveCartDTO;
import cn.ysk.cashier.dto.shoptable.TableGenerateDTO;
import cn.ysk.cashier.dto.shoptable.*;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.service.shop.TbShopTableService;
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
@@ -106,4 +103,12 @@ public class TbShopTableController {
return new ResponseEntity<>(tbShopTableService.getShopState(shopId, tableId),HttpStatus.OK);
}
/**
* 桌码绑定
*/
@PostMapping("/bind")
public ResponseEntity<Object> bindQrcode(@Validated @RequestBody BindTableQrCodeDTO bindTableQrCodeDTO) {
return new ResponseEntity<>(tbShopTableService.bindQrcode(bindTableQrCodeDTO),HttpStatus.OK);
}
}

View File

@@ -0,0 +1,16 @@
package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class BindTableQrCodeDTO {
@NotNull
private Integer shopId;
@NotNull
private Integer id;
@NotEmpty
private String code;
}

View File

@@ -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);
}

View File

@@ -28,4 +28,12 @@ public interface MpShopTableService extends IService<TbShopTable> {
* @return 台桌信息
*/
TbShopTable selectByTableId(String tableId, Integer shopId);
/**
* 根据主键查询台桌
* @param id 主键
* @param shopId 店铺id
* @return 台桌信息
*/
TbShopTable selectById(Integer id, Integer shopId);
}

View File

@@ -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);
}
}

View File

@@ -37,4 +37,11 @@ public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbSho
.eq(TbShopTable::getShopId, shopId)
.eq(TbShopTable::getQrcode, tableId));
}
@Override
public TbShopTable selectById(Integer id, Integer shopId) {
return getOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getId, id)
.eq(TbShopTable::getShopId, shopId));
}
}

View File

@@ -1,5 +1,8 @@
package cn.ysk.cashier.service.impl.shopimpl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.config.security.service.UserCacheManager;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
@@ -7,6 +10,7 @@ import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.exception.EntityNotFoundException;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
@@ -24,8 +28,11 @@ import cn.ysk.cashier.system.repository.UserRepository;
import cn.ysk.cashier.system.service.ParamsService;
import cn.ysk.cashier.system.service.UserService;
import cn.ysk.cashier.utils.*;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -35,8 +42,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.*;
@@ -322,4 +333,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
}
FileUtil.downloadExcel(list, response);
}
}
}

View File

@@ -2203,4 +2203,19 @@ public class TbShopTableServiceImpl implements TbShopTableService {
}
return null;
}
@Override
public Object bindQrcode(BindTableQrCodeDTO bindTableQrCodeDTO) {
TbShopTable shopTable = mpShopTableService.selectById(bindTableQrCodeDTO.getId(), bindTableQrCodeDTO.getShopId());
if (shopTable == null) {
throw new BadRequestException("台桌不存在");
}
shopTable.setQrcode(bindTableQrCodeDTO.getCode());
if (!mpShopTableService.updateById(shopTable)) {
throw new BadRequestException("绑定失败");
}
return true;
}
}

View File

@@ -88,4 +88,5 @@ public interface TbShopInfoService {
* @throws IOException /
*/
void download(List<TbShopInfoDto> all, HttpServletResponse response) throws IOException;
}
}

View File

@@ -147,4 +147,6 @@ public interface TbShopTableService {
* @return
*/
Object getShopState(Integer shopId, String tableId);
Object bindQrcode(BindTableQrCodeDTO bindTableQrCodeDTO);
}