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

# Conflicts:
#	src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java
This commit is contained in:
牛叉闪闪
2024-08-19 17:47:34 +08:00
38 changed files with 1452 additions and 609 deletions

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.StrUtil;
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
import com.chaozhanggui.system.cashierservice.entity.dto.WxMsgSubDTO;
@@ -208,7 +209,6 @@ public class CommonController {
redisUtil.getIncrNum(key, "2");
}
/**
* 订阅消息
* @param wxMsgSubDTO
@@ -220,7 +220,7 @@ public class CommonController {
if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) {
return Result.fail("shopId或openId缺失");
}
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), wxMsgSubDTO.getType());
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), null, wxMsgSubDTO.getNickname(), wxMsgSubDTO.getAvatar());
return Result.success(CodeEnum.SUCCESS);
}
}

View File

@@ -200,11 +200,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();
@@ -276,6 +276,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);
}

View File

@@ -3,11 +3,12 @@ package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
import com.chaozhanggui.system.cashierservice.service.CartService;
import com.chaozhanggui.system.cashierservice.service.ProductService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -22,6 +23,8 @@ public class ProductController {
@Autowired
private ProductService productService;
@Autowired
private CartService cartService;
/**
* 通过桌码获取shopId
@@ -29,12 +32,15 @@ public class ProductController {
* @param code
* @return shopid
*/
@RequestMapping("queryShopIdByTableCode")
@RequestMapping("queryShop")
public Result queryShopIdByTableCode(
@RequestHeader("openId") String openId,
@RequestHeader("id") String userId,
@RequestParam("code") String code) {
return productService.queryShopIdByTableCode(userId, openId, code);
@RequestParam String lat,
@RequestParam String lng,
@RequestParam("code") String code
) {
return productService.queryShopIdByTableCode(userId, openId, code,lat,lng);
}
/**
@@ -46,24 +52,54 @@ public class ProductController {
@RequestMapping("queryProduct")
public Result queryProduct(@RequestBody Map<String, String> map) {
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("code")) {
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("shopId")) {
return Result.fail("参数错误");
}
return productService.queryProduct(
map.get("code").toString(),
map.get("shopId").toString(),
(map.containsKey("productGroupId") && ObjectUtil.isNotEmpty(map.get("productGroupId"))) ? map.get("productGroupId").toString() : "");
}
/**
* 查询规格
*
* @return
*/
@PostMapping("querySpec")
public Result querySpec(
@RequestBody QuerySpecDTO querySpecDTO
) {
if (querySpecDTO.getProductId() == null) {
return Result.fail("id不为空");
}
return Result.successWithData(productService.querySpec(querySpecDTO));
}
@GetMapping("queryProductSku")
public Result queryProductSku(
@RequestParam(value = "code", required = false) String code,
@RequestParam("shopId") String shopId,
@RequestParam("productId") String productId,
@RequestParam("spec_tag") String spec_tag
) {
return productService.queryProductSku(shopId, productId, spec_tag);
return productService.queryProductSku(code,shopId, productId, spec_tag);
}
@PostMapping("addCart")
public Result addCart(@RequestBody JSONObject jsonObject) {
log.info("添加购物车数据:{}", jsonObject);
return cartService.createCart(jsonObject);
}
@PostMapping("cleanCart")
public Result cleanCart(@RequestBody JSONObject jsonObject) {
log.info("清空购物车数据:{}", jsonObject);
cartService.clearCart(jsonObject);
return Result.success(CodeEnum.SUCCESS);
}
/**
* 团购商品详情/商品类型为 套餐商品
*/

View File

@@ -0,0 +1,40 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.TbShopAd;
import com.chaozhanggui.system.cashierservice.entity.dto.TbShopAdDto;
import com.chaozhanggui.system.cashierservice.service.TbShopAdService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* (TbShopAd)表控制层
*
* @author GYJ
* @since 2024-08-19 14:25:09
*/
@RestController
@RequestMapping("tbShopAd")
public class TbShopAdController {
private final TbShopAdService tbShopAdService;
public TbShopAdController(@Qualifier("tbShopAdServiceImpl") TbShopAdService tbShopAdService) {
this.tbShopAdService = tbShopAdService;
}
@GetMapping("/list")
public Result list(@RequestParam(value = "shopId") Integer shopId) {
List<TbShopAd> tbShopAds = tbShopAdService.shopAdList(shopId);
return Result.success(CodeEnum.ENCRYPT, TbShopAdDto.convertShopAdDoToDtoList(tbShopAds));
}
}

View File

@@ -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,42 +62,56 @@ 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 {
if(shopId.equals("undefined")){
return Result.fail("店铺信息错误,请联系管理员!");
}
TbShopUser shopUser = new TbShopUser();
TbShopInfo tbShopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
TbShopInfo tbShopInfo = new TbShopInfo();
if (StringUtils.isNotBlank(shopId) && !shopId.equals("null")) {
shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId);
if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
tbShopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if(tbShopInfo!=null){
shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId);
if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
// shopUser = shopUserMapper.selectByPhoneAndShopId(tbUserInfo.getTelephone(), shopId);
// if(ObjectUtil.isEmpty(shopUser)){
shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
shopUserMapper.insert(shopUser);
shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
shopUserMapper.insert(shopUser);
// }else {
// shopUser.setUserId(userId);
// shopUser.setUpdatedAt(System.currentTimeMillis());
// shopUserMapper.updateByPrimaryKey(shopUser);
// }
}
}else {
return Result.fail("店铺信息不存在");
}
} else {
shopUser.setAmount(BigDecimal.ZERO);
@@ -104,8 +119,9 @@ public class UserContoller {
if (tbShopInfo != null) {
shopUser.setIsUser(tbShopInfo.getIsCustom());
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);
}
@@ -152,7 +168,9 @@ public class UserContoller {
* @return
*/
@GetMapping("/subQrCode")
public Result getSubQrCode(String shopId) throws Exception {
public Result getSubQrCode(
@RequestParam String shopId
) throws Exception {
String url = userService.getSubQrCode(shopId);
return Result.successWithData(url);
}

View File

@@ -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<TbProductGroup> selectByIdAndShopId(@Param("code") String code);
List<TbProductGroup> selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId);
List<TbProductGroup> selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId);
List<TbProductGroup> selectByProductId(@Param("shopId") String shopId,@Param("productId") String productId);
}

View File

@@ -20,9 +20,13 @@ public interface TbProductMapper {
List<TbProduct> selectByIdIn(@Param("ids") String ids);
List<TbProduct> selectByIdInAndCheck(@Param("ids") String ids);
List<TbProduct> selectHot(@Param("shopId") String shopId);
List<TbProduct> selectIsSpecialty(@Param("shopId") Integer shopId);
List<TbProduct> selectByIds(@Param("list") List<String> ids);
Integer selectByQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId);
Integer selectByCodeAndSkuId(@Param("code") String code,@Param("skuId") Integer skuId,@Param("shopId") String shopId);
Integer selectByNewQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId,@Param("list") List<String> list);
List<ShopGroupInfoVo> selGroups(@Param("proName") String proName,@Param("type") String type,

View File

@@ -0,0 +1,23 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopAd;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* (TbShopAd)表数据库访问层
*
* @author GYJ
* @since 2024-08-19 14:25:09
*/
public interface TbShopAdDao {
/**
* 查询指定行数据
*
* @return 对象列表
*/
@Select("select * from fycashier.tb_shop_ad where (shop_id = #{songId} or shop_id = 1) and status=1")
List<TbShopAd> shopAdList(Integer shopId);
}

View File

@@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@@ -30,4 +31,23 @@ public interface TbShopOpenIdMapper {
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(@Param("shopId") Integer shopId);
@Select("select * from tb_shop_open_id where open_id=#{openId} and status=1")
List<TbShopOpenId> selectByOpenId(@Param("openId") String openId);
@Update("update tb_shop_open_id set nickname=#{nickName}, avatar=#{avatar} where open_id=#{openId} and status=1 ")
int updateBaseInfoByOpenId(@Param("openId") String openId, @Param("nickName") String nickName, @Param("avatar") String avatar);
@Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1;")
int selectStateByShopId(@Param("shopId") String shopId);
@Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1 and type=#{type};")
int countStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type);
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1) group by open_id;")
List<TbShopOpenId> selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type);
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and open_id=#{openId};")
List<TbShopOpenId> selectStateByShopIdAndOpenId(@Param("openId") String openId, @Param("shopId") String shopId);
}

View File

@@ -0,0 +1,17 @@
package com.chaozhanggui.system.cashierservice.entity.Enum;
public enum ShopWxMsgTypeEnum {
ALL_MSG(-1),
STOCK_MSG(0),
CONSUMABLES_MSG(1),
OPERATION_MSG(2);
private final Integer type;
ShopWxMsgTypeEnum(Integer type) {
this.type = type;
}
public Integer getType() {
return type;
}
}

View File

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

View File

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

View File

@@ -3,12 +3,33 @@ package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable {
private String tagSnap;
private String specInfo;
private String specSnap;
private Integer number;
private static final long serialVersionUID = 1L;
public String getTagSnap() {
return tagSnap;
}
public void setTagSnap(String tagSnap) {
this.tagSnap = tagSnap;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getSpecInfo() {
return specInfo;
}
@@ -24,4 +45,4 @@ public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable
public void setSpecSnap(String specSnap) {
this.specSnap = specSnap == null ? null : specSnap.trim();
}
}
}

View File

@@ -0,0 +1,63 @@
package com.chaozhanggui.system.cashierservice.entity;
import lombok.Data;
import java.util.Date;
import java.io.Serializable;
/**
* (TbShopAd)实体类
*
* @author GYJ
* @since 2024-08-19 14:25:09
*/
@Data
public class TbShopAd implements Serializable {
private static final long serialVersionUID = -34028307481923067L;
/**
* 自增id
*/
private Integer id;
/**
* 店铺id如果是通用广告则为0
*/
private Integer shopId;
/**
* 广告图片地址
*/
private String imgUrl;
/**
* 跳转页面路径
*/
private String linkPath;
/**
* 广告展示圆角
*/
private Integer borderRadius;
/**
* 弹窗展示位置home首页make_order点餐页
*/
private String showPosition;
/**
* 显示频率only_one 仅首次展示, every_show 每次打开都展示every_day 每天展示一次three_day 每三天展示一次, seven_day 每七天展示一次, thirty_day 没30天展示一次
*/
private String frequency;
/**
* 广告状态0未启用1已启用
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}

View File

@@ -0,0 +1,94 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName tb_shop_msg_state
*/
@Data
public class TbShopMsgState implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private Integer shopId;
/**
*
*/
private Integer type;
/**
*
*/
private Integer state;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
TbShopMsgState other = (TbShopMsgState) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", shopId=").append(shopId);
sb.append(", type=").append(type);
sb.append(", state=").append(state);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@@ -3,15 +3,17 @@ package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 商家openid信息表
* @TableName tb_shop_open_id
*/
@EqualsAndHashCode
@Data
public class TbShopOpenId implements Serializable {
/**
*
*
*/
private Integer id;
@@ -26,69 +28,24 @@ public class TbShopOpenId implements Serializable {
private String openId;
/**
*
*
*/
private Integer status;
/**
*
*
*/
private Date createTime;
/**
*
*
*/
private Date updateTime;
private String nickname;
private String avatar;
private Integer type;
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
TbShopOpenId other = (TbShopOpenId) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
&& (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", shopId=").append(shopId);
sb.append(", openId=").append(openId);
sb.append(", status=").append(status);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
}

View File

@@ -1,7 +1,5 @@
package com.chaozhanggui.system.cashierservice.entity;
import org.springframework.data.annotation.Transient;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -65,15 +63,10 @@ public class TbShopUser implements Serializable {
private Long updatedAt;
private String miniOpenId;
private String shopName;
@Transient
private String isUser;
private String shopName="";
private String lat="";
private String lng="";
private String address="";
private static final long serialVersionUID = 1L;
@@ -318,11 +311,28 @@ public class TbShopUser implements Serializable {
this.miniOpenId = miniOpenId == null ? null : miniOpenId.trim();
}
public String getIsUser() {
return isUser;
public String getLat() {
return lat;
}
public void setIsUser(String isUser) {
this.isUser = isUser;
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;
}
}

View File

@@ -0,0 +1,21 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
import java.util.List;
@Data
public class QuerySpecDTO {
@Data
@AllArgsConstructor
@EqualsAndHashCode
public static class QuerySpec {
private String name;
private String value;
}
private Integer productId;
private List<QuerySpec> querySpecList = new ArrayList<>();
}

View File

@@ -0,0 +1,61 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import com.chaozhanggui.system.cashierservice.entity.TbShopAd;
import lombok.Data;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author GYJ
*/
@Data
public class TbShopAdDto {
private Integer id;
/**
* 店铺id如果是通用广告则为0
*/
private Integer shopId;
/**
* 广告图片地址
*/
private String imgUrl;
/**
* 跳转页面路径
*/
private String linkPath;
/**
* 广告展示圆角
*/
private Integer borderRadius;
/**
* 弹窗展示位置home首页make_order点餐页
*/
private String showPosition;
/**
* 显示频率only_one 仅首次展示, every_show 每次打开都展示every_day 每天展示一次three_day 每三天展示一次, seven_day 每七天展示一次, thirty_day 没30天展示一次
*/
private String frequency;
/**
* 更新时间
*/
private Long updateTime;
public static List<TbShopAdDto> convertShopAdDoToDtoList(List<TbShopAd> adList) {
return adList.stream().map(TbShopAdDto::convertShopAdDoToDto).collect(Collectors.toList());
}
public static TbShopAdDto convertShopAdDoToDto(TbShopAd ad) {
TbShopAdDto dto = new TbShopAdDto();
dto.setId(ad.getId());
dto.setShopId(ad.getShopId());
dto.setImgUrl(ad.getImgUrl());
dto.setLinkPath(ad.getLinkPath());
dto.setBorderRadius(ad.getBorderRadius());
dto.setShowPosition(ad.getShowPosition());
dto.setFrequency(ad.getFrequency());
dto.setUpdateTime(ad.getUpdateTime().getTime());
return dto;
}
}

View File

@@ -7,4 +7,6 @@ public class WxMsgSubDTO {
private String shopId;
private String openId;
private Integer type;
private String nickname;
private String avatar;
}

View File

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

View File

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

View File

@@ -0,0 +1,28 @@
package com.chaozhanggui.system.cashierservice.mapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState;
import org.apache.ibatis.annotations.Select;
/**
* @author Administrator
* @description 针对表【tb_shop_msg_state】的数据库操作Mapper
* @createDate 2024-08-12 14:38:33
* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopMsgState
*/
public interface TbShopMsgStateMapper {
int deleteByPrimaryKey(Long id);
int insert(TbShopMsgState record);
int insertSelective(TbShopMsgState record);
TbShopMsgState selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(TbShopMsgState record);
int updateByPrimaryKey(TbShopMsgState record);
@Select("select * from tb_shop_msg_state where shop_id=#{shopId} and type=#{type};")
TbShopMsgState selectByType(Integer type, Integer shopId);
}

View File

@@ -36,12 +36,14 @@ public class CartConsumer {
String shopId = jsonObject.getString("shopId");
if (jsonObject.getString("type").equals("initCart") ) {
cartService.initCart(jsonObject);
}else if (jsonObject.getString("type").equals("addcart") ) {
if (!jsonObject.containsKey("num")) {
throw new MsgException("商品数量错误");
}
cartService.createCart(jsonObject);
}else if (jsonObject.getString("type").equals("queryCart") ) {
}
// else if (jsonObject.getString("type").equals("addcart") ) {
// if (!jsonObject.containsKey("num")) {
// throw new MsgException("商品数量错误");
// }
// cartService.createCart(jsonObject);
// }
else if (jsonObject.getString("type").equals("queryCart") ) {
cartService.queryCart(jsonObject);
} else if(jsonObject.getString("type").equals("createOrder")){
String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
@@ -54,9 +56,9 @@ public class CartConsumer {
cartService.createOrder(jsonObject);
}
}
else if(jsonObject.getString("type").equals("clearCart")){
cartService.clearCart(jsonObject);
}
// else if(jsonObject.getString("type").equals("clearCart")){
// cartService.clearCart(jsonObject);
// }
} catch (Exception e) {
log.info("数据处理失败:{}",e.getMessage());
e.printStackTrace();

View File

@@ -6,11 +6,14 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.LockUtils;
@@ -130,300 +133,150 @@ public class CartService {
* 加入购物车
* @param jsonObject 商品信息
*/
// @Transactional(rollbackFor = Exception.class)
// public void createCart(JSONObject jsonObject) {
// try {
// String tableId = jsonObject.getString("tableId");
// String shopId = jsonObject.getString("shopId");
// String productId = jsonObject.getString("productId");
//
// String key = tableId + "-" + shopId;
// TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
// if (tbProduct == null) {
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("status", "fail");
// jsonObject1.put("msg", "该商品不存在");
// jsonObject1.put("data", new ArrayList<>());
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
// log.error("该商品不存在 productId:{}", productId);
// throw new MsgException("该商品不存在");
// }
//
// String skuId = jsonObject.getString("skuId");
// JSONArray jsonArray = new JSONArray();
// BigDecimal amount = BigDecimal.ZERO;
// TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
//
//
//
//
// JSONObject objectMsg=new JSONObject();
// objectMsg.put("skuId",tbProductSkuWithBLOBs.getId());
// objectMsg.put("shopId",Integer.valueOf(shopId));
//
//
// producer.con_msg(objectMsg.toString());
//
//
// if (Integer.valueOf(tbProduct.getIsPauseSale()).equals(1)) {
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("status", "fail");
// jsonObject1.put("msg", "该商品已售罄");
// jsonObject1.put("data", new ArrayList<>());
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
// log.error("该商品已售罄 productId:{}", productId);
// throw new MsgException("该商品已售罄");
// }
//
// String skuNum;
//
// // 1:共享库存 0:独立库存
// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":product" + productId);
// if (!exist) {
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, tbProduct.getStockNumber() + "");
// }
// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":product" + productId);
//
// if (!skuNum.equals(tbProduct.getStockNumber() + "")) {
// skuNum = tbProduct.getStockNumber() + "";
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum);
// }
// } else {
// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":" + skuId);
// if (!exist) {
// Double stock = tbProductSkuWithBLOBs.getStockNumber();
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":" + skuId, Math.round(stock) + "");
// }
// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":" + skuId);
//
// if (!skuNum.equals(Math.round(tbProductSkuWithBLOBs.getStockNumber()) + "")) {
// skuNum = Math.round(tbProductSkuWithBLOBs.getStockNumber()) + "";
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum);
// }
// }
//
// Integer buyNum = jsonObject.getInteger("num");
// if (tbProduct.getIsStock() == 1) {
// boolean flag = false;
//
// String id = skuId;
// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
// if (tbProduct.getStockNumber() < 1 && buyNum > 0) {
// flag = true;
// id = productId;
// }
// } else {
// if (tbProductSkuWithBLOBs.getIsPauseSale().equals(1)) {
// flag = true;
// } else if (Integer.valueOf(skuNum) < 1 && buyNum > 0) {
// flag = true;
// }
// }
//
// if (flag) {
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("status", "fail");
// jsonObject1.put("msg", "该商品库存已售罄");
// jsonObject1.put("data", new ArrayList<>());
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
// log.error("该商品库存已售罄 skuId:{}", id);
// throw new MsgException("该商品库存已售罄");
// }
// }
//
// if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
// JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
// if (Objects.isNull(array) || array.isEmpty()) {
// if (buyNum > 0) {
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
// jsonObject.getInteger("userId"), buyNum, tableId, shopId);
// jsonArray.add(cashierCart);
// amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
//
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
// }
// } else {
// boolean flag = true;
// for (int i = 0; i < array.size(); i++) {
// JSONObject object = array.getJSONObject(i);
// TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
// if (cashierCart.getSkuId().equals(skuId)) {
// cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
// cashierCart.setNumber(cashierCart.getNumber() + buyNum);
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
// if (cashierCart.getNumber() > 0) {
// cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
// cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
// cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
// } else {
// cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
// continue;
// }
// flag = false;
// }
// jsonArray.add(cashierCart);
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
// }
// if (flag && buyNum > 0) {
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
// jsonArray.add(cashierCart);
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
// }
// }
// } else {
// if (buyNum > 0) {
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
// jsonArray.add(cashierCart);
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
// }
// }
// redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString());
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("status", "success");
// jsonObject1.put("msg", "成功");
// jsonObject1.put("type", jsonObject.getString("type"));
// jsonObject1.put("data", jsonArray);
// jsonObject1.put("amount", amount);
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
// } catch (Exception e) {
// log.error("长链接错误 createCart{}", e.getMessage());
// }
// }
public void createCart(JSONObject jsonObject) {
public Result createCart(JSONObject jsonObject) {
try {
String tableId = jsonObject.getString("tableId");
String shopId = jsonObject.getString("shopId");
String productId = jsonObject.getString("productId");
String skuId = jsonObject.getString("skuId");
Integer type = jsonObject.getInteger("type");
Integer buyNum = jsonObject.getInteger("num");
if (StringUtils.isBlank(tableId) || StringUtils.isBlank(shopId) || StringUtils.isBlank(productId)
|| StringUtils.isBlank(skuId) || type==null || buyNum == null) {
return Result.fail("参数缺失");
}
String key = tableId + "-" + shopId;
TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
if (tbProduct == null) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品不存在");
jsonObject1.put("data", new ArrayList<>());
jsonObject1.put("reqData", jsonObject);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.error("该商品不存在 productId:{}", productId);
throw new MsgException("该商品不存在");
return Result.fail("该商品不存在");
}
Integer buyNum = jsonObject.getInteger("num");
String skuId = jsonObject.getString("skuId");
// 判断商品是否已下架
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (tbProductSkuWithBLOBs ==null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "此商品已下架");
jsonObject1.put("data", new ArrayList<>());
jsonObject1.put("reqData", jsonObject);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.error("商品已下架 skuId:{}", skuId);
return;
rmCart(jsonObject,skuId,key);
return Result.fail("商品已下架");
}
if (tbProduct.getIsStock() == 1) {
// 1:共享库存 0:独立库存
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
if (tbProduct.getIsPauseSale() == 1 || tbProduct.getStockNumber() < buyNum ) {//是否售罄
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品已售罄");
jsonObject1.put("data", new ArrayList<>());
jsonObject1.put("reqData", jsonObject);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.error("该商品已售罄 productId:{}", productId);
throw new MsgException("该商品已售罄");
if (tbProduct.getIsPauseSale() == 1) {//是否售罄
rmCart(jsonObject,skuId,key);
return Result.fail("该商品已售罄");
}
} else {
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1 || tbProductSkuWithBLOBs.getStockNumber() < buyNum ) {//是否售罄
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品已售罄");
jsonObject1.put("data", new ArrayList<>());
jsonObject1.put("reqData", jsonObject);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.error("该商品已售罄 productId:{}", productId);
throw new MsgException("该商品已售罄");
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄
rmCart(jsonObject,skuId,key);
return Result.fail("该商品已售罄");
}
}
}
JSONArray jsonArray = new JSONArray();
BigDecimal amount = BigDecimal.ZERO;
if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
if (Objects.isNull(array) || array.isEmpty()) {
if (buyNum > 0) {
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
try{
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
if (Objects.isNull(array) || array.isEmpty()) {
if (type == 1) {
TbCashierCart cashierCart = addCart(productId, skuId,
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
} else {
boolean flag = true;
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
if (cashierCart.getSkuId().equals(skuId)) {
cashierCart.setTotalNumber(buyNum);
cashierCart.setNumber(buyNum);
if (type == 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue;
}
if (cashierCart.getNumber() > 0) {
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
} else {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue;
}
flag = false;
}
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
if (flag && type == 1) {
TbCashierCart cashierCart = addCart(productId, skuId,
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
}
} else {
boolean flag = true;
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
if (cashierCart.getSkuId().equals(skuId)) {
cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
cashierCart.setNumber(cashierCart.getNumber() + buyNum);
if (buyNum < 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue;
}
if (cashierCart.getNumber() > 0) {
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
} else {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue;
}
flag = false;
}
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
if (flag && buyNum > 0) {
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
if (type == 1) {
TbCashierCart cashierCart = addCart(productId, skuId,
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
}
} else {
if (buyNum > 0) {
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}catch (MsgException e){
if(e.getMessage().equals("商品起售库存不足")){
return Result.fail("商品起售库存不足");
}
}
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString());
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", jsonObject.getString("type"));
jsonObject1.put("type", "addcart");
jsonObject1.put("data", jsonArray);
jsonObject1.put("amount", amount);
jsonObject1.put("reqData", jsonObject);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false);
} catch (Exception e) {
log.error("长链接错误 createCart{}", e.getMessage());
}
return Result.success(CodeEnum.SUCCESS);
}
private void rmCart(JSONObject jsonObject,String skuId, String key) {
JSONArray jsonArray = new JSONArray();
BigDecimal amount = BigDecimal.ZERO;
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
if (!Objects.isNull(array) && !array.isEmpty()) {
boolean flag = false;
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
if (cashierCart.getSkuId().equals(skuId)) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
flag = true;
continue;
}
jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", "addcart");
jsonObject1.put("data", jsonArray);
jsonObject1.put("amount", amount);
jsonObject1.put("reqData", jsonObject);
if(flag){
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false);
}
}
}
}
/**
* 修改库存并根据警告线发送消息
*
@@ -484,13 +337,13 @@ public class CartService {
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
if (message == null) {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
, item.getOpenId());
, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId());
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
}else {
log.info("{}已在30分钟内推送过消息跳过发送", item.getOpenId());
@@ -500,51 +353,40 @@ public class CartService {
}
}
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws RuntimeException {
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception{
try {
TbProduct product = productMapper.selectById(Integer.valueOf(productId));
String key = tableId + "-" + shopId;
if (Objects.isNull(product)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品不存在");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常,该商品不存在:{}", productId);
throw new MsgException("该商品不存在");
}
TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (Objects.isNull(productSku)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品规格不存在");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常该商品sku不存在{}", productId);
throw new MsgException("该商品规格不存在");
}
TbCashierCart cashierCart = new TbCashierCart();
if (productSku.getSuit() != null && productSku.getSuit() > 1) {
if (product.getIsStock() == 1) {
boolean isSale = false;
// 1:共享库存 0:独立库存
if (Integer.valueOf(product.getIsDistribute()).equals(1)) {
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
if (num > productSku.getSuit()) {
if (num > product.getStockNumber()) isSale = true;
}else {
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
}
} else {
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
if (num > productSku.getSuit()) {
if (num > productSku.getStockNumber()) isSale = true;
}else {
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
}
}
if (isSale) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品库存不足");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常,该商品起售库存不足:{}", productId);
throw new MsgException("该商品起售库存不足");
throw new MsgException("商品起售库存不足");
}
}
cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit());
if(num > productSku.getSuit()){
cashierCart.setNumber(num);
cashierCart.setTotalNumber(num);
}else {
cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit());
}
} else {
cashierCart.setNumber(num);
cashierCart.setTotalNumber(num);
@@ -592,8 +434,7 @@ public class CartService {
String tableId = jsonObject.getString("tableId");
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
String key = tableId + "-" + shopId;
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
List<Integer> ids = new ArrayList<>();
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal packAMount = BigDecimal.ZERO;
BigDecimal originAmount = BigDecimal.ZERO;
@@ -602,7 +443,7 @@ public class CartService {
BigDecimal couponAmount = BigDecimal.ZERO;
List<TbOrderDetail> orderDetails = new ArrayList<>();
Integer orderId = 0;
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId"));
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(shopId);
if (tbMerchantAccount == null) {
MsgException.throwException("生成订单错误");
}
@@ -643,7 +484,7 @@ public class CartService {
} catch (Exception e) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "商品库存不足" + tbProduct1.getName());
jsonObject1.put("msg", tbProduct1.getName() + "库存不足");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
return;
@@ -949,7 +790,7 @@ public class CartService {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", "clearCart");
jsonObject1.put("type", "addcart");
jsonObject1.put("amount", BigDecimal.ZERO);
jsonObject1.put("data", new ArrayList<>());
// //修改耗材数据

View File

@@ -1,11 +1,14 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -58,41 +61,66 @@ public class LoginService {
private final TbShopOpenIdMapper shopOpenIdMapper;
private final static int[] MSG_TYPE_LIST = new int[] {0, 1, 2};
public LoginService(TbShopOpenIdMapper shopOpenIdMapper) {
this.shopOpenIdMapper = shopOpenIdMapper;
}
public void addShopId(String openId, String shopId, Integer type) {
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
if(Objects.isNull(shopMsg)){
shopMsg=new TbUserShopMsg();
shopMsg.setShopId(Integer.valueOf(shopId));
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg);
public void addShopId(String openId, String shopId, Integer type1, String nickName, String avatar) {
// 为商家绑定openid
// TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null);
List<TbShopOpenId> shopOpenIdList = shopOpenIdMapper.selectStateByShopIdAndOpenId(openId, shopId);
int openCount = shopOpenIdMapper.selectStateByShopId(shopId);
if (shopOpenIdList.isEmpty()) {
for (int type : MSG_TYPE_LIST) {
addShopOpenId(openId, shopId, nickName, avatar, openCount, type);
}
} else {
boolean fullSize = shopOpenIdList.size() == MSG_TYPE_LIST.length;
HashMap<String, Object> typeMap = new HashMap<>();
for (TbShopOpenId tbShopOpenId : shopOpenIdList) {
typeMap.put(tbShopOpenId.getType().toString(), tbShopOpenId.getOpenId());
tbShopOpenId.setType(null);
tbShopOpenId.setUpdateTime(DateUtil.date());
tbShopOpenId.setNickname(nickName);
tbShopOpenId.setAvatar(avatar);
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
}
if (fullSize) {
return;
}
for (int type : MSG_TYPE_LIST) {
if (typeMap.get(String.valueOf(type)) == null) {
addShopOpenId(openId, shopId, nickName, avatar, openCount, type);
}
}
}
// 为商家绑定openid
TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type);
if ( tbShopOpenId == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId);
}else {
tbShopOpenId.setUpdateTime(DateUtil.date());
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
}
}
private void addShopOpenId(String openId, String shopId, String nickName, String avatar, int openCount, int type) {
int count = shopOpenIdMapper.countStateByShopIdAndType(shopId, type);
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(openCount > 0 ? count > 0 ? 1 : 0 : 0);
shopOpenId.setNickname(nickName);
shopOpenId.setAvatar(avatar);
shopOpenId.setType(type);
shopOpenIdMapper.insert(shopOpenId);
}
public Result wxBusinessLogin(String openId,String shopId){
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
if(Objects.isNull(shopMsg)){
shopMsg=new TbUserShopMsg();
public Result wxBusinessLogin(String openId, String shopId) {
TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId);
if (Objects.isNull(shopMsg)) {
shopMsg = new TbUserShopMsg();
shopMsg.setShopId(Integer.valueOf(shopId));
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
@@ -109,14 +137,14 @@ public class LoginService {
shopOpenId.setStatus(1);
// shopOpenIdMapper.insert(shopOpenId);
}
return Result.success(CodeEnum.SUCCESS,shopMsg);
return Result.success(CodeEnum.SUCCESS, shopMsg);
}
public Result wxCustomLogin(String openId,String headImage,String nickName,String telephone,String ip) {
TbUserInfo userInfo= tbUserInfoMapper.selectByOpenId(openId);
if(ObjectUtil.isNull(userInfo)){
userInfo=new TbUserInfo();
public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String ip) {
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
if (ObjectUtil.isNull(userInfo)) {
userInfo = new TbUserInfo();
userInfo.setAmount(BigDecimal.ZERO);
userInfo.setChargeAmount(BigDecimal.ZERO);
userInfo.setLineOfCredit(BigDecimal.ZERO);
@@ -124,9 +152,9 @@ public class LoginService {
userInfo.setConsumeAmount(BigDecimal.ZERO);
userInfo.setTotalScore(0);
userInfo.setLockScore(0);
userInfo.setHeadImg(ObjectUtil.isNotNull(headImage)?headImage:"");
userInfo.setNickName(ObjectUtil.isNotNull(nickName)?nickName:"微信用户");
userInfo.setTelephone(ObjectUtil.isNotNull(telephone)?telephone:"");
userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : "");
userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户");
userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : "");
userInfo.setMiniAppOpenId(openId);
userInfo.setStatus(Byte.parseByte("1"));
userInfo.setParentType("PERSON");
@@ -142,7 +170,7 @@ public class LoginService {
userInfo.setLastLogInAt(System.currentTimeMillis());
userInfo.setUpdatedAt(System.currentTimeMillis());
tbUserInfoMapper.insert(userInfo);
}else {
} else {
userInfo.setUpdatedAt(System.currentTimeMillis());
userInfo.setLastLogInAt(System.currentTimeMillis());
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
@@ -283,7 +311,7 @@ public class LoginService {
* @param nickName
* @return
*/
public TbUserInfo register(String phone, String openId,String password, String nickName) {
public TbUserInfo register(String phone, String openId, String password, String nickName) {
TbUserInfo userInfo = new TbUserInfo();
userInfo.setAmount(BigDecimal.ZERO);
@@ -313,7 +341,7 @@ public class LoginService {
if (StringUtils.isNotBlank(password)) {
userInfo.setPassword(MD5Utils.MD5Encode(password, "UTF-8"));
}
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(phone);
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(phone);
for (TbShopUser tbShopUser : tbShopUsers) {
tbShopUser.setUserId(userInfo.getId() + "");
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
@@ -342,13 +370,13 @@ public class LoginService {
}
@Transactional(rollbackFor = Exception.class)
public Result appLogin(String username,String openId, String password) {
public Result appLogin(String username, String openId, String password) {
TbUserInfo userInfo = tbUserInfoMapper.selectByPhone(username);
if (ObjectUtil.isNull(userInfo)) {
if (StringUtils.isNotBlank(password)) {
return Result.fail("暂未设置密码,请使用验证码登录");
}
userInfo = register(username,openId, password, username);
userInfo = register(username, openId, password, username);
} else {
if (StringUtils.isNotBlank(userInfo.getMiniAppOpenId())) {
if (!userInfo.getMiniAppOpenId().equals(openId)) {
@@ -423,7 +451,7 @@ public class LoginService {
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
return Result.success(CodeEnum.SUCCESS, "46"+dynamicCode);
return Result.success(CodeEnum.SUCCESS, "46" + dynamicCode);
}
@@ -439,14 +467,14 @@ public class LoginService {
public Result upPhone(String openId, String phone, String shopId) {
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
// 同一个手机号 同一个店 userId 不为空
TbShopUser tbShopUserPC = tbShopUserMapper.selectPCByPhoneAndShopId(userInfo.getTelephone(),shopId);
TbShopUser tbShopUserPC = tbShopUserMapper.selectPCByPhoneAndShopId(userInfo.getTelephone(), shopId);
if (tbShopUserPC != null) {
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
tbShopUserMapper.deleteByPrimaryKey(tbShopUserSM.getId());
tbShopUserPC.setUserId(userInfo.getId().toString());
tbShopUserMapper.updateByPrimaryKey(tbShopUserPC);
}else {
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
} else {
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
if (tbShopUserSM != null) {
tbShopUserSM.setIsVip(Byte.parseByte("1"));
tbShopUserSM.setTelephone(phone);
@@ -460,7 +488,7 @@ public class LoginService {
return Result.success(CodeEnum.SUCCESS);
}
public void registerShopUser(TbUserInfo userInfo,String shopId) {
public void registerShopUser(TbUserInfo userInfo, String shopId) {
TbShopUser shopUser = new TbShopUser();
shopUser.setName(userInfo.getNickName());
shopUser.setSex(userInfo.getSex());

View File

@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -16,6 +17,8 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
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;
@@ -24,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;
@@ -68,165 +75,380 @@ public class ProductService {
@Autowired
private TbUserInfoMapper tbUserInfoMapper;
public Result queryShopIdByTableCode(String userId,String openId,String code) {
String shopId = tbShopTableMapper.queryShopIdByTableCode(code);
if (StringUtils.isBlank(shopId)) {
public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) {
if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
lat = "34.343207";
lng = "108.939645";
}
TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code);
if (tbShopTable == null) {
return Result.fail("台桌信息不存在");
}
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId);
try{
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(tbShopTable.getShopId());
String distance = LocationUtils.getDistanceString(
Double.parseDouble(lng), Double.parseDouble(lat),
Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat()));
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
concurrentMap.put("shopTableInfo", tbShopTable);
concurrentMap.put("storeInfo", shopInfo);
concurrentMap.put("distance", distance);
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, tbShopTable.getShopId().toString());
try {
if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
// shopUser = tbShopUserMapper.selectByPhoneAndShopId(tbUserInfo.getTelephone(), shopId);
// if(ObjectUtil.isEmpty(shopUser)){
shopUser=new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.insert(shopUser);
shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(tbShopTable.getShopId().toString());
shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.insert(shopUser);
// }else {
// shopUser.setUserId(userId);
// shopUser.setUpdatedAt(System.currentTimeMillis());
// tbShopUserMapper.updateByPrimaryKey(shopUser);
// }
}else {
} else {
shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKey(shopUser);
}
}catch (Exception e){
log.info("通过桌码获取shopId 进行用户绑定错误:{}",e.getMessage());
} catch (Exception e) {
log.info("通过桌码获取shopId 进行用户绑定错误:{}", e.getMessage());
e.printStackTrace();
}
return Result.success(CodeEnum.SUCCESS, shopId);
return Result.success(CodeEnum.SUCCESS, concurrentMap);
}
public Result queryProduct(String code, String productGroupId) {
public Result queryProduct(String shopId, String productGroupId) {
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code);
if (ObjectUtil.isEmpty(tbShopTable) || ObjectUtil.isNull(tbShopTable)) {
return Result.fail("台桌信息不存在");
}
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
List<TbProductGroup> groupList = tbProductGroupMapper.selectByQrcode(code, id);
//招牌菜
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
concurrentMap.put("hots", handleDate(tbProducts,true,1));
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
TbProductGroup group = groupList.get(0);
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(group.getShopId());
concurrentMap.put("shopTableInfo", tbShopTable);
concurrentMap.put("storeInfo", shopInfo);
//热销
TbProductGroup hot = new TbProductGroup();
hot.setName("热销");
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
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<TbProduct> products = tbProductMapper.selectByIdIn(in);
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
if (ObjectUtil.isNotEmpty(products) && products.size() > 0) {
products.parallelStream().forEach(it -> {
Integer sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId());
it.setCartNumber(sum == null ? "0" : String.valueOf(sum));
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
// 上下架对应的sku
HashSet<String> specSet = new HashSet<>();
BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) {
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice();
}
String specSnap = item.getSpecSnap();
if (specSnap != null) {
specSet.addAll(Arrays.asList(specSnap.split(",")));
}
}
if (lowerPrice == null) {
lowerPrice = BigDecimal.ZERO;
}
it.setLowPrice(lowerPrice);
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
if (tagSnap != null) {
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
JSONObject snapJSON;
JSONArray finalSnap = new JSONArray();
for (Object snap : tagSnaps) {
snapJSON = (JSONObject) snap;
String values = snapJSON.getString("value");
String finalValues = "";
if (StrUtil.isNotBlank(values)) {
String[] valueList = values.split(",");
for (String value : valueList) {
if (specSet.contains(value)) {
finalValues = finalValues + (value) + ",";
}
}
if (StrUtil.isNotBlank(finalValues)) {
finalValues = StrUtil.removeSuffix(finalValues, ",");
snapJSON.put("value", finalValues);
finalSnap.add(snapJSON);
}
}
}
skuResult.setTagSnap(finalSnap.toJSONString());
}
it.setProductSkuResult(skuResult);
});
g.setProducts(products);
} else {
g.setProducts(new ArrayList<>());
}
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);
}
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 Result queryProductSku(String shopId, String productId, String spec_tag) {
public Object querySpec(QuerySpecDTO querySpecDTO) {
TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId());
if (tbProduct == null) {
throw new MsgException("商品不存在");
}
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(querySpecDTO.getProductId());
// 重组有效规格数据
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(querySpecDTO.getProductId());
JSONArray finalSnap = new JSONArray();
// if (tagSnap != null) {
// JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
// HashMap<String, String> reverseTagSnapMap = new HashMap<>();
// JSONObject snapJSON;
// for (Object snap : tagSnaps) {
// snapJSON = (JSONObject)snap;
// reverseTagSnapMap.put(snapJSON.getString("value"), snapJSON.getString("name"));
// }
// // 上下架对应的sku
// HashSet<String> specSet = new HashSet<>();
// for (TbProductSku item : tbProductSkus) {
// String specSnap = item.getSpecSnap();
//
// ArrayList<QuerySpecDTO.QuerySpec> skuSpecList = new ArrayList<>();
// if (specSnap != null) {
// String[] split = specSnap.split(",");
// for (String snap : split) {
// reverseTagSnapMap.forEach((k, v) -> {
// if (k.contains(snap)) {
// skuSpecList.add(new QuerySpecDTO.QuerySpec(v, snap));
// }
// });
// }
//
// boolean isHave = false;
// for (QuerySpecDTO.QuerySpec spec : querySpecDTO.getQuerySpecList()) {
// for (QuerySpecDTO.QuerySpec querySpec : skuSpecList) {
// isHave = querySpec.equals(spec);
// if (isHave) break;
// }
//
// }
// if (querySpecDTO.getQuerySpecList().isEmpty() || isHave) {
// specSet.addAll(Arrays.asList(split));
// }
// }
// }
//
//
// for (Object snap : tagSnaps) {
// snapJSON = (JSONObject) snap;
// String values = snapJSON.getString("value");
//
// ArrayList<LinkedHashMap<String, Object>> data = new ArrayList<>();
// if (StrUtil.isNotBlank(values)) {
// String[] valueList = values.split(",");
// for (String value : valueList) {
// LinkedHashMap<String, Object> finalValue = new LinkedHashMap<>();
// finalValue.put("info", value);
// finalValue.put("isGrounding", specSet.contains(value));
// data.add(finalValue);
// }
// if (!data.isEmpty()) {
// snapJSON.put("value", data);
// finalSnap.add(snapJSON);
// }
//
// }
// }
// }
List<String> result = new ArrayList<>();
if (tagSnap != null) {
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
List<List<String>> valuesList = new ArrayList<>();
// 提取所有 value 的列表
for (int i = 0; i < tagSnaps.size(); i++) {
JSONObject jsonObject = tagSnaps.getJSONObject(i);
if (jsonObject.containsKey("value")) {
String[] values = jsonObject.getString("value").split(",");
valuesList.add(Arrays.asList(values));
}
}
// 生成所有可能的排列组合
generateCombinations(valuesList, 0, new ArrayList<>(), result);
}
ArrayList<HashMap<String, Object>> specList = new ArrayList<>();
tbProductSkus.forEach(item -> {
HashMap<String, Object> itemMap = new HashMap<>();
itemMap.put("specSnap", item.getSpecSnap());
itemMap.put("skuId", item.getId());
specList.add(itemMap);
});
ArrayList<HashMap<String, Object>> otherVal = new ArrayList<>();
for (String res : result) {
boolean found = false;
for (HashMap<String, Object> spec : specList) {
if (res.equals(spec.get("specSnap").toString())) {
spec.put("isGrounding", true);
found = true;
break;
}
}
if (!found) {
HashMap<String, Object> itemMap = new HashMap<>();
itemMap.put("specSnap", res);
itemMap.put("skuId", null);
itemMap.put("isGrounding", false);
otherVal.add(itemMap);
}
}
specList.addAll(otherVal);
return specList;
}
private static void generateCombinations(List<List<String>> valuesList, int index, List<String> current, List<String> result) {
if (index == valuesList.size()) {
result.add(String.join(",", current));
return;
}
for (String value : valuesList.get(index)) {
current.add(value);
generateCombinations(valuesList, index + 1, current, result);
current.remove(current.size() - 1); // 回溯
}
}
/**
* 组装商品
* @param products 商品列表
* @param check 是否校验可售
* @return
*/
public List<TbProduct> handleDate(List<TbProduct> products,boolean check,Integer isSale){
if (!CollectionUtils.isEmpty(products)) {
products.parallelStream().forEach(it -> {
if(check){
List<TbProductGroup> 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() : "");
//购物车数量
it.setCartNumber("0");
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
// 上下架对应的sku
// HashSet<String> specSet = new HashSet<>();
AtomicDouble sum = new AtomicDouble(0.0);
BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) {
if (item.getRealSalesNumber() != null) {
sum.addAndGet(item.getRealSalesNumber());
}
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice();
}
String specSnap = item.getSpecSnap();
// if (specSnap != null) {
// specSet.addAll(Arrays.asList(specSnap.split(",")));
// }
}
//销量
it.setStockNumber(sum.intValue());
if (lowerPrice == null) {
lowerPrice = BigDecimal.ZERO;
}
//售价
it.setLowPrice(lowerPrice);
// String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
// if (tagSnap != null) {
// JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
// JSONObject snapJSON;
// JSONArray finalSnap = new JSONArray();
// for (Object snap : tagSnaps) {
// snapJSON = (JSONObject) snap;
// String values = snapJSON.getString("value");
// String finalValues = "";
// if (StrUtil.isNotBlank(values)) {
// String[] valueList = values.split(",");
// for (String value : valueList) {
// if (specSet.contains(value)) {
// finalValues = finalValues + (value) + ",";
// }
// }
// if (StrUtil.isNotBlank(finalValues)) {
// finalValues = StrUtil.removeSuffix(finalValues, ",");
// snapJSON.put("value", finalValues);
// finalSnap.add(snapJSON);
// }
// }
// }
// //sku Result
// skuResult.setTagSnap(finalSnap.toJSONString());
// }
it.setProductSkuResult(skuResult);
});
return products;
}else {
return new ArrayList<>();
}
}
public Result queryProductSku(String code, String shopId, String productId, String spec_tag) {
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
return Result.fail("参数错误");
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag);
if (tbProductSkuWithBLOBs == null) {
tbProductSkuWithBLOBs = new TbProductSkuWithBLOBs();
tbProductSkuWithBLOBs.setNumber(0);
tbProductSkuWithBLOBs.setSalePrice(BigDecimal.ZERO);
tbProductSkuWithBLOBs.setOriginPrice(BigDecimal.ZERO);
tbProductSkuWithBLOBs.setId(null);
}else {
if (StringUtils.isNotBlank(code)) {
Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId);
tbProductSkuWithBLOBs.setNumber(sum);
}
}
return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs);
}
@@ -263,13 +485,13 @@ public class ProductService {
stTime = enTime - 3600000L * 2;
}
shopGroupInfoVos = tbProductMapper.selHotGroups(
homeDto.getProName(),homeDto.getType(),
homeDto.getProName(), homeDto.getType(),
// DateUtils.getStrTime(new Date(stTime)), DateUtils.getStrTime(new Date(enTime)),
null, null,
homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat());
} else {
shopGroupInfoVos = tbProductMapper.selGroups(
homeDto.getProName(),homeDto.getType(),
homeDto.getProName(), homeDto.getType(),
topAndBottomMap.get("rightTopPoint")[1], topAndBottomMap.get("rightTopPoint")[0],
topAndBottomMap.get("leftBottomPoint")[1], topAndBottomMap.get("leftBottomPoint")[0],
homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat());
@@ -415,7 +637,7 @@ public class ProductService {
productInfo.setPhone(tbShopInfo.getPhone());
productInfo.setLat(tbShopInfo.getLat());
productInfo.setLng(tbShopInfo.getLng());
if(StringUtils.isNotBlank(tbShopInfo.getBusinessStartDay())){
if (StringUtils.isNotBlank(tbShopInfo.getBusinessStartDay())) {
productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime());
}
String distance = LocationUtils.getDistanceString(
@@ -496,16 +718,16 @@ public class ProductService {
/**
* 库存修改
*
* @param tbProduct 商品
* @param tbProduct 商品
* @param tbProductSkuWithBLOBs sku
* @param buyNum 购买数量
* @param buyNum 购买数量
*/
public void updateStock(TbProduct tbProduct, TbProductSkuWithBLOBs tbProductSkuWithBLOBs, Integer buyNum) {
if (tbProduct.getIsDistribute() == 1) {
if (tbProductMapper.decrStock(String.valueOf(tbProduct.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试");
}
}else {
} else {
if (tbProductSkuMapper.decrStock(String.valueOf(tbProductSkuWithBLOBs.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试");
}
@@ -517,7 +739,7 @@ public class ProductService {
if (tbProductMapper.decrStock(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}else {
} else {
if (tbProductSkuMapper.decrStock(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
@@ -529,10 +751,11 @@ public class ProductService {
if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}else {
} else {
if (tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}
}
}

View File

@@ -0,0 +1,20 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbShopAd;
import java.util.List;
/**
* (TbShopAd)表服务接口
*
* @author GYJ
* @since 2024-08-19 14:25:17
*/
public interface TbShopAdService {
/**
* 分页查询
*
* @return 查询结果
*/
List<TbShopAd> shopAdList(Integer shopId);
}

View File

@@ -1,19 +1,19 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.alibaba.fastjson.JSON;
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.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.*;
@@ -23,14 +23,11 @@ import com.github.pagehelper.PageInfo;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -264,10 +261,35 @@ public class UserService {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
InputStream inputStream = resource.getInputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500).
// String url = wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1);
String url = StrUtil.format("https://invoice.sxczgkj.cn/index/wechat/weuserk?shopId={}", shopId);
QrCodeUtil.generate(url, new QrConfig(500, 500).
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);
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<TbShopUser> 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);
}
}

View File

@@ -0,0 +1,27 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.chaozhanggui.system.cashierservice.dao.TbShopAdDao;
import com.chaozhanggui.system.cashierservice.entity.TbShopAd;
import com.chaozhanggui.system.cashierservice.service.TbShopAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* (TbShopAd)表服务实现类
*
* @author GYJ
* @since 2024-08-19 14:25:17
*/
@Service
public class TbShopAdServiceImpl implements TbShopAdService {
@Autowired
private TbShopAdDao tbShopAdDao;
@Override
public List<TbShopAd> shopAdList(Integer shopId) {
System.out.println("shopId = " + shopId);
return tbShopAdDao.shopAdList(shopId);
}
}

View File

@@ -6,7 +6,10 @@ import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -27,6 +30,8 @@ public class WxAccountUtil {
@Value("${wx.ysk.warnMsgTmpId}")
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
private final TbShopMsgStateMapper shopMsgStateMapper;
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
static {
@@ -53,7 +58,7 @@ public class WxAccountUtil {
req.put("action_name", "QR_STR_SCENE");
HashMap<Object, Object> actionInfo = new HashMap<>();
HashMap<String, Object> scene = new HashMap<>();
scene.put("scene_str", "msg" + shopId + ":" + type);
scene.put("scene_str", "msg" + shopId + "," + type);
actionInfo.put("scene", scene);
req.put("action_info", actionInfo);
log.info("开始获取公众号二维码, 请求数据: {}", req);
@@ -98,7 +103,18 @@ public class WxAccountUtil {
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
}
public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) {
public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) {
TbShopMsgState allState = shopMsgStateMapper.selectByType(ShopWxMsgTypeEnum.ALL_MSG.getType(), shopId);
if (allState == null || allState.getState().equals(0)) {
log.info("店铺未开启全局推送:{}", allState);
return null;
}
TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId);
if (shopMsgState == null || shopMsgState.getState().equals(0)) {
log.info("店铺未开启推送:{}", shopMsgState);
return null;
}
stock = stock < 0 ? 0 : stock;
Integer finalStock = stock;
Map<String, Object> data = new HashMap<String, Object>() {{

View File

@@ -11,6 +11,9 @@
<result column="detail" jdbcType="VARCHAR" property="detail" />
<result column="style" jdbcType="VARCHAR" property="style" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="use_time" jdbcType="INTEGER" property="useTime" />
<result column="sale_start_time" jdbcType="INTEGER" property="saleStartTime" />
<result column="sale_end_time" jdbcType="INTEGER" property="saleEndTime" />
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
</resultMap>
@@ -18,7 +21,7 @@
<result column="product_ids" jdbcType="LONGVARCHAR" property="productIds" />
</resultMap>
<sql id="Base_Column_List">
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
</sql>
<sql id="Blob_Column_List">
product_ids
@@ -229,9 +232,14 @@
FROM
tb_product_group
where shop_id=#{shopId} and is_show=1
<if test="groupId != null">
<if test="groupId != null and groupId != ''">
and id = #{groupId}
</if>
order by g.sort asc
order by sort asc
</select>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM tb_product_group WHERE `shop_id` = #{shopId,jdbcType=VARCHAR} AND is_show = 1
AND `product_ids` LIKE concat('%',#{productId,jdbcType=VARCHAR},'%')
</select>
</mapper>

View File

@@ -932,11 +932,47 @@
select min( sku.suit ) as suit,tb.*
from tb_product tb
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1
where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1 and tb.type_enum!='group' and tb.status = 1
group by tb.id
order by tb.sort asc
</select>
<select id="selectHot" resultMap="BaseResultMap">
select min(sku.suit) as suit, tb.*
from tb_product tb
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
JOIN (SELECT product_id
FROM tb_product_sku
WHERE shop_id = #{shopId}
GROUP BY product_id
ORDER BY SUM(real_sales_number) DESC LIMIT 3) AS top_products ON tb.id = top_products.product_id
where is_show_mall = 1
and tb.status = 1
and tb.type_enum != 'group'
and sku.is_del = 0
and sku.is_grounding = 1
group by tb.id
order by tb.sort asc
</select>
<select id="selectIsSpecialty" resultMap="BaseResultMap">
select min(sku.suit) as suit, tb.*
from tb_product tb
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
where is_hot = 1
and is_show_mall = 1
and tb.shop_id = #{shopId}
and tb.status = 1
and sku.is_del = 0
and sku.is_grounding = 1
and tb.type_enum != 'group'
group by tb.id
order by tb.sort asc
</select>
<!-- <select id="selectByIdIn" resultMap="BaseResultMap">-->
<!-- select *-->
<!-- from tb_product-->
@@ -963,6 +999,17 @@
t.shop_id,
t.product_id
</select>
<select id="selectByCodeAndSkuId" resultType="java.lang.Integer">
SELECT
IFNULL(t.number, 0 )
FROM
tb_cashier_cart t
WHERE
t.shop_id = #{shopId}
AND t.sku_id = #{skuId}
AND t.`status` = 'create'
AND t.table_id = #{code}
</select>
<select id="selectByNewQcode" resultType="java.lang.Integer">
SELECT
IFNULL( sum( t.number ), 0 )

View File

@@ -362,11 +362,11 @@
</update>
<select id="selectByShopIdAndProductIdAndSpec" resultMap="ResultMapWithBLOBs">
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0 and is_grounding=1
<if test="spec != null and spec !=''">
and spec_snap = #{spec}
</if>
limit 1
</select>
<select id="selectAll" resultType="com.chaozhanggui.system.cashierservice.entity.TbProductSku">
select * from tb_product_sku

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chaozhanggui.system.cashierservice.dao.TbShopAdDao">
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbShopAd" id="TbShopAdMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="imgUrl" column="img_url" jdbcType="VARCHAR"/>
<result property="linkPath" column="link_path" jdbcType="VARCHAR"/>
<result property="borderRadius" column="border_radius" jdbcType="INTEGER"/>
<result property="showPosition" column="show_position" jdbcType="VARCHAR"/>
<result property="frequency" column="frequency" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="INTEGER"/>
<result property="sort" column="sort" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,shop_id,type,
state,create_time,update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
insert into tb_shop_msg_state
( id,shop_id,type
,state,create_time,update_time
)
values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{type,jdbcType=INTEGER}
,#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
insert into tb_shop_msg_state
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="shopId != null">shop_id,</if>
<if test="type != null">type,</if>
<if test="state != null">state,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id,jdbcType=INTEGER},</if>
<if test="shopId != null">#{shopId,jdbcType=INTEGER},</if>
<if test="type != null">#{type,jdbcType=INTEGER},</if>
<if test="state != null">#{state,jdbcType=INTEGER},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
update tb_shop_msg_state
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="state != null">
state = #{state,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
update tb_shop_msg_state
set
shop_id = #{shopId,jdbcType=INTEGER},
type = #{type,jdbcType=INTEGER},
state = #{state,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@@ -41,10 +41,10 @@
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId" useGeneratedKeys="true">
insert into tb_shop_open_id
( id,shop_id,open_id
,status,create_time,update_time
,status,create_time,update_time, type, nickname, avatar
)
values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{openId,jdbcType=VARCHAR}
,#{status,jdbcType=TINYINT},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}
,#{status,jdbcType=TINYINT},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{type,jdbcType=INTEGER}, #{nickname,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId" useGeneratedKeys="true">
@@ -84,6 +84,15 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="type != null">
`type` = #{type,jdbcType=INTEGER},
</if>
<if test="nickname != null">
`nickname` = #{nickname,jdbcType=INTEGER},
</if>
<if test="avatar != null">
`avatar` = #{avatar,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>

View File

@@ -130,6 +130,7 @@
SELECT
f.*,
u.`head_img`,
u.`name`
FROM
tb_shop_user_flow f