diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index cbdcdb2..3fced4d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -201,11 +201,11 @@ public class LoginContoller { String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); try { if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { - if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { +// if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber")); - } - log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); - return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); +// } +// log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); +// return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); } } catch (Exception e){ // e.printStackTrace(); @@ -277,6 +277,7 @@ public class LoginContoller { String userId = TokenUtil.parseParamFromToken(token).getString("userId"); userInfo.setId(Integer.valueOf(userId)); userInfo.setUpdatedAt(System.currentTimeMillis()); +// log.info("更新用户信息 param,{}",JSONObject.toJSONString(userInfo)); return loginService.upUserInfo(userInfo); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 28cce38..57a7608 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.service.UserService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -61,6 +62,12 @@ public class UserContoller { // jsonObject.put("data",object); // return jsonObject; // } + + @PostMapping("/openMember") + public Result openMember(@RequestBody OpenMemberVo memberVo){ + return userService.openMember(memberVo); + } + @GetMapping("/shopUserInfo") public Result shopUserInfo(@RequestParam("userId") String userId, @RequestHeader("openId") String openId, @RequestParam("shopId") String shopId) throws Exception { TbShopUser shopUser = new TbShopUser(); @@ -108,8 +115,9 @@ public class UserContoller { } if (tbShopInfo != null) { shopUser.setShopName(tbShopInfo.getShopName()); - }else { - shopUser.setShopName(""); + shopUser.setLng(tbShopInfo.getLng()); + shopUser.setLat(tbShopInfo.getLat()); + shopUser.setAddress(tbShopInfo.getAddress()); } return Result.success(CodeEnum.SUCCESS, shopUser); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java index 13d89fd..1609ea7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java @@ -10,23 +10,24 @@ import java.util.List; @Component @Mapper public interface TbProductGroupMapper { - int deleteByPrimaryKey(Integer id); +// int deleteByPrimaryKey(Integer id); - int insert(TbProductGroup record); +// int insert(TbProductGroup record); - int insertSelective(TbProductGroup record); +// int insertSelective(TbProductGroup record); TbProductGroup selectByPrimaryKey(Integer id); - int updateByPrimaryKeySelective(TbProductGroup record); +// int updateByPrimaryKeySelective(TbProductGroup record); - int updateByPrimaryKeyWithBLOBs(TbProductGroup record); +// int updateByPrimaryKeyWithBLOBs(TbProductGroup record); - int updateByPrimaryKey(TbProductGroup record); +// int updateByPrimaryKey(TbProductGroup record); List selectByIdAndShopId(@Param("code") String code); List selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId); List selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId); + List selectByProductId(@Param("shopId") String shopId,@Param("productId") String productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index ed6e8bf..ba7404d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -137,6 +137,9 @@ public class TbProduct implements Serializable { private Integer stockNumber; private Integer suit; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + public String getImages() { return images; @@ -672,4 +675,12 @@ public class TbProduct implements Serializable { public void setSuit(Integer suit) { this.suit = suit; } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java index 9460370..1c5b0b6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java @@ -31,6 +31,15 @@ public class TbProductGroup implements Serializable { private String productIds; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + //是否使用时间管控 0不使用 1使用 + private Integer useTime = 0; + + private String saleStartTime; + + private String saleEndTime; + @Transient @@ -144,4 +153,37 @@ public class TbProductGroup implements Serializable { public void setProductIds(String productIds) { this.productIds = productIds == null ? null : productIds.trim(); } + + + public Integer getUseTime() { + return useTime; + } + + public void setUseTime(Integer useTime) { + this.useTime = useTime; + } + + public String getSaleStartTime() { + return saleStartTime; + } + + public void setSaleStartTime(String saleStartTime) { + this.saleStartTime = saleStartTime; + } + + public String getSaleEndTime() { + return saleEndTime; + } + + public void setSaleEndTime(String saleEndTime) { + this.saleEndTime = saleEndTime; + } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java index 9531fdf..1621a49 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java @@ -63,7 +63,10 @@ public class TbShopUser implements Serializable { private Long updatedAt; private String miniOpenId; - private String shopName; + private String shopName=""; + private String lat=""; + private String lng=""; + private String address=""; private static final long serialVersionUID = 1L; @@ -307,4 +310,29 @@ public class TbShopUser implements Serializable { public void setMiniOpenId(String miniOpenId) { this.miniOpenId = miniOpenId == null ? null : miniOpenId.trim(); } + + + public String getLat() { + return lat; + } + + public void setLat(String lat) { + this.lat = lat; + } + + public String getLng() { + return lng; + } + + public void setLng(String lng) { + this.lng = lng; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java new file mode 100644 index 0000000..b08c50e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java @@ -0,0 +1,15 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +@Data +public class OpenMemberVo { + private Integer id; + private Integer shopId; + private String headImg; + + private String nickName; + + private String telephone; + private String birthDay; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index b68db15..02b7c10 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -146,7 +146,8 @@ public class DefaultExceptionAdvice { @ResponseStatus(HttpStatus.OK) @ExceptionHandler(MsgException.class) public ResponseEntity handleException(MsgException e) { - LOGGER.error("业务异常", e); + // LOGGER.error("业务异常", e); + LOGGER.error("业务异常", e.getMessage()); Result response = Result.fail(e.getMessage()); response.setMsg(e.getMessage()); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 491aea6..8e844ad 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -18,6 +18,7 @@ import com.chaozhanggui.system.cashierservice.util.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.util.concurrent.AtomicDouble; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +27,10 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -136,25 +141,27 @@ public class ProductService { Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; //招牌菜 List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); - concurrentMap.put("hots", handleDate(tbProducts)); + concurrentMap.put("hots", handleDate(tbProducts,true,1)); List groupList = tbProductGroupMapper.selectByShopId(shopId, id); if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { //热销 TbProductGroup hot = new TbProductGroup(); hot.setName("热销"); List hots = tbProductMapper.selectHot(shopId); - hot.setProducts(handleDate(hots)); + hot.setProducts(handleDate(hots,true,1)); //商品 groupList.parallelStream().forEach(g -> { + if (g.getUseTime()==1) g.setIsSale(getIsSale(g.getSaleStartTime(),g.getSaleEndTime())); String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) { // List products = tbProductMapper.selectByIdIn(in); List products = tbProductMapper.selectByIdInAndCheck(in); - g.setProducts(handleDate(products)); + g.setProducts(handleDate(products,false,g.getIsSale())); } else { g.setProducts(new ArrayList<>()); } }); + groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed()); groupList.add(0, hot); concurrentMap.put("productInfo", groupList); } @@ -162,6 +169,44 @@ public class ProductService { return Result.success(CodeEnum.SUCCESS, concurrentMap); } + /** + * 判断是否在可售时间内 + * @param startTimeStr HH:mm + * @param endTimeStr HH:mm + * @return 1 可售 0 不可售 + */ + public Integer getIsSale(String startTimeStr,String endTimeStr) { + // 定义时间格式 + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + // 解析时间字符串为 LocalTime 对象 + LocalTime startTime = LocalTime.parse(startTimeStr, timeFormatter); + LocalTime endTime = LocalTime.parse(endTimeStr, timeFormatter); + // 获取当前日期 + LocalDate today = LocalDate.now(); + // 创建 LocalDateTime 对象 + LocalDateTime startDateTime = LocalDateTime.of(today, startTime); + LocalDateTime endDateTime = LocalDateTime.of(today, endTime); + // 如果结束时间早于开始时间,说明时间段跨日 + if (endDateTime.isBefore(startDateTime)) { + endDateTime = endDateTime.plusDays(1); + } + // 获取当前日期时间 + LocalDateTime now = LocalDateTime.now(); + if (now.isBefore(startDateTime)) { + // 将当前时间加上24小时(一天),进行比较 + LocalDateTime nowPlus24 = now.plusHours(24); + //当前时间 小于开始时间,且结束时间小于开始时间 + if (nowPlus24.isBefore(endDateTime)) { + return 1; + } + } else { + if (now.isBefore(endDateTime)) { + return 1; + } + } + return 0; + } + public Object querySpec(QuerySpecDTO querySpecDTO) { TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId()); if (tbProduct == null) { @@ -296,9 +341,28 @@ public class ProductService { } } - public List handleDate(List products){ + /** + * 组装商品 + * @param products 商品列表 + * @param check 是否校验可售 + * @return + */ + public List handleDate(List products,boolean check,Integer isSale){ if (!CollectionUtils.isEmpty(products)) { products.parallelStream().forEach(it -> { + if(check){ + List tbProductGroups = tbProductGroupMapper.selectByProductId(it.getShopId(), it.getId().toString()); + for (TbProductGroup g : tbProductGroups) { + if (g.getUseTime()==1) { + if (getIsSale(g.getSaleStartTime(), g.getSaleEndTime()) == 0) { + it.setIsSale(0); + return; + } + } + } + }else { + it.setIsSale(isSale); + } TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : ""); //购物车数量 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 47dbcff..6c93e90 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -5,11 +5,17 @@ import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; -import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; +import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; +import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil; import com.github.pagehelper.PageHelper; @@ -263,4 +269,27 @@ public class UserService { return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray())); } + + public Result openMember(OpenMemberVo memberVo) { + TbUserInfo userInfo = new TbUserInfo(); + userInfo.setId(memberVo.getId()); + userInfo.setHeadImg(memberVo.getHeadImg()); + userInfo.setNickName(memberVo.getNickName()); + userInfo.setTelephone(memberVo.getTelephone()); + userInfo.setBirthDay(memberVo.getBirthDay()); + userInfoMapper.updateByPrimaryKeySelective(userInfo); + List tbShopUsers = shopUserMapper.selectAllByUserId(memberVo.getId().toString()); + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setTelephone(memberVo.getTelephone()); + shopUserMapper.updateByPrimaryKey(tbShopUser); + } + TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(memberVo.getId().toString(), memberVo.getShopId().toString()); + tbShopUser.setName(memberVo.getNickName()); + tbShopUser.setHeadImg(memberVo.getHeadImg()); + tbShopUser.setTelephone(memberVo.getTelephone()); + tbShopUser.setBirthDay(memberVo.getBirthDay()); + tbShopUser.setIsVip(Byte.parseByte("1")); + shopUserMapper.updateByPrimaryKey(tbShopUser); + return Result.success(CodeEnum.SUCCESS); + } } diff --git a/src/main/resources/mapper/TbProductGroupMapper.xml b/src/main/resources/mapper/TbProductGroupMapper.xml index 5082065..a8f0112 100644 --- a/src/main/resources/mapper/TbProductGroupMapper.xml +++ b/src/main/resources/mapper/TbProductGroupMapper.xml @@ -11,6 +11,9 @@ + + + @@ -18,7 +21,7 @@ - id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at + id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at , use_time, sale_start_time, sale_end_time product_ids @@ -234,4 +237,9 @@ order by sort asc + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopUserFlowMapper.xml b/src/main/resources/mapper/TbShopUserFlowMapper.xml index 9e02f10..9d7b16f 100644 --- a/src/main/resources/mapper/TbShopUserFlowMapper.xml +++ b/src/main/resources/mapper/TbShopUserFlowMapper.xml @@ -130,6 +130,7 @@ SELECT f.*, + u.`head_img`, u.`name` FROM tb_shop_user_flow f