小程序店铺信息接口
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 小程序店铺相关
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/shopInfo")
|
||||
public class UShopInfoController {
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
|
||||
/**
|
||||
* 桌码换取详细店铺信息
|
||||
* @return 店铺信息
|
||||
*/
|
||||
@GetMapping
|
||||
public CzgResult<ShopInfoByCodeDTO> getByCode(@RequestParam @NotEmpty String tableCode, String lat, String lng) {
|
||||
return CzgResult.success(shopInfoService.getByCode(tableCode, lat, lng, true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
|
||||
package com.czg.account.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import java.io.Serial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌配置 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopTableDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer shopId;
|
||||
|
||||
/**
|
||||
* 客座数,允许的客座数量
|
||||
*/
|
||||
private Integer maxCapacity;
|
||||
|
||||
/**
|
||||
* 台桌排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 区域Id
|
||||
*/
|
||||
private Integer areaId;
|
||||
|
||||
/**
|
||||
* 是否接受网络预定
|
||||
*/
|
||||
private Integer isPredate;
|
||||
|
||||
/**
|
||||
* 网络预定台桌支付金额
|
||||
*/
|
||||
private BigDecimal predateAmount;
|
||||
|
||||
/**
|
||||
* idle-空闲 using-使用中 subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中
|
||||
*/
|
||||
private String status;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 二维码
|
||||
*/
|
||||
private String qrcode;
|
||||
|
||||
/**
|
||||
* 自动清台 0手动 1自动
|
||||
*/
|
||||
private Integer autoClear;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime useTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 已点商品数量
|
||||
*/
|
||||
private Integer productNum;
|
||||
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 应付金额
|
||||
*/
|
||||
private BigDecimal realAmount;
|
||||
|
||||
/**
|
||||
* 用餐人数
|
||||
*/
|
||||
private Integer useNum;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.czg.account.dto.shopinfo;
|
||||
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ShopInfoByCodeDTO {
|
||||
/**
|
||||
* 当前用户距离店铺的米数
|
||||
*/
|
||||
private double distance;
|
||||
/**
|
||||
* 店铺信息
|
||||
*/
|
||||
private ShopInfo shopInfo;
|
||||
/**
|
||||
* 台桌信息
|
||||
*/
|
||||
private ShopTable shopTable;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.czg.account.entity;
|
||||
|
||||
import com.czg.enums.ShopTableStatusEnum;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌配置 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_table")
|
||||
public class ShopTable implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 客座数,允许的客座数量
|
||||
*/
|
||||
private Integer maxCapacity;
|
||||
|
||||
/**
|
||||
* 台桌排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 区域Id
|
||||
*/
|
||||
private Integer areaId;
|
||||
|
||||
/**
|
||||
* 是否接受网络预定
|
||||
*/
|
||||
private Integer isPredate;
|
||||
|
||||
/**
|
||||
* 网络预定台桌支付金额
|
||||
*/
|
||||
private BigDecimal predateAmount;
|
||||
|
||||
/**
|
||||
* idle-空闲 using-使用中 subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中
|
||||
*/
|
||||
private String status;
|
||||
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 二维码
|
||||
*/
|
||||
private String tableCode;
|
||||
|
||||
/**
|
||||
* 自动清台 0手动 1自动
|
||||
*/
|
||||
private Integer autoClear;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private LocalDateTime useTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 已点商品数量
|
||||
*/
|
||||
private Integer productNum;
|
||||
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 应付金额
|
||||
*/
|
||||
private BigDecimal realAmount;
|
||||
|
||||
/**
|
||||
* 用餐人数
|
||||
*/
|
||||
private Integer useNum;
|
||||
|
||||
public boolean canUseByStatus() {
|
||||
return !ShopTableStatusEnum.CLOSED.equalsVal(status) && !ShopTableStatusEnum.CLEANING.equalsVal(status) && !ShopTableStatusEnum.SUBSCRIBE.equalsVal(status);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoAddDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoEditDTO;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@@ -18,4 +19,6 @@ public interface ShopInfoService extends IService<ShopInfo> {
|
||||
Boolean edit(ShopInfoEditDTO shopInfoEditDTO);
|
||||
|
||||
ShopInfo detail();
|
||||
|
||||
ShopInfoByCodeDTO getByCode(String tableCode, String lat, String lng, boolean checkState);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.account.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
|
||||
/**
|
||||
* 台桌配置 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
public interface ShopTableService extends IService<ShopTable> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.czg.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 台桌状态枚举
|
||||
* @author Administrator
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum ShopTableStatusEnum {
|
||||
// 空闲
|
||||
IDLE("idle"),
|
||||
// 使用中
|
||||
USING("using"),
|
||||
// 关台
|
||||
CLOSED("closed"),
|
||||
// 预定
|
||||
SUBSCRIBE("subscribe"),
|
||||
// 清台
|
||||
CLEANING("cleaning");
|
||||
private final String value;
|
||||
|
||||
ShopTableStatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean equalsVal(String val) {
|
||||
return val.equals(value);
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,19 @@ import lombok.Getter;
|
||||
public enum ShopUserFlowBizEnum {
|
||||
// 会员充值
|
||||
CASH_IN("cashIn"),
|
||||
// 重置奖励
|
||||
AWARD_IN("awardIn"),
|
||||
// 微信小程序充值
|
||||
WECHAT_IN("wechatIn"),
|
||||
// 支付宝小程序重置
|
||||
ALIPAY_IN("alipayIn"),
|
||||
// 订单支付奖励
|
||||
ORDER_PAY("orderPay"),
|
||||
// 订单退款
|
||||
ORDER_REFUND("orderRefund"),
|
||||
// 充值退款
|
||||
RECHARGE_REFUND("rechargeRefund"),
|
||||
// 管理员手动增减余额
|
||||
ADMIN_IN("adminIn");
|
||||
private final String code;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.czg.utils;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
public class GeoUtil {
|
||||
// 地球半径,单位:公里
|
||||
private static final double EARTH_RADIUS = 6371.0;
|
||||
|
||||
/**
|
||||
* 计算两点之间的球面距离
|
||||
* @param lat1 第一个点的纬度
|
||||
* @param lon1 第一个点的经度
|
||||
* @param lat2 第二个点的纬度
|
||||
* @param lon2 第二个点的经度
|
||||
* @return 距离(单位:米)
|
||||
*/
|
||||
public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
// 将角度转换为弧度
|
||||
double radLat1 = Math.toRadians(lat1);
|
||||
double radLat2 = Math.toRadians(lat2);
|
||||
double deltaLat = radLat2 - radLat1;
|
||||
double deltaLon = Math.toRadians(lon2 - lon1);
|
||||
|
||||
// Haversine 公式
|
||||
double a = Math.pow(Math.sin(deltaLat / 2), 2) +
|
||||
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLon / 2), 2);
|
||||
double c = 2 * Math.asin(Math.sqrt(a));
|
||||
|
||||
// 计算距离(米)
|
||||
return EARTH_RADIUS * c * 1000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
|
||||
/**
|
||||
* 台桌配置 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
public interface ShopTableMapper extends BaseMapper<ShopTable> {
|
||||
|
||||
}
|
||||
@@ -2,23 +2,29 @@ package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.CoordinateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoAddDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoEditDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.enums.StatusEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopInfoMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.GeoUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
@@ -28,11 +34,27 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
@Resource
|
||||
private SysUsersRolesService sysUsersRolesService;
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private MerchantRegisterService merchantRegisterService;
|
||||
@Resource
|
||||
private ShopTableService shopTableService;
|
||||
|
||||
private ShopInfo getShopInfo(Long shopId) {
|
||||
ShopInfo shopInfo = getById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new ApiNotPrintException("店铺不存在");
|
||||
}
|
||||
if ((DateUtil.date().toLocalDateTime().isAfter(shopInfo.getExpireTime())) || shopInfo.getStatus() != StatusEnum.ENABLED.value()) {
|
||||
throw new ApiNotPrintException("店铺已过期,请联系商家");
|
||||
}
|
||||
if (StatusEnum.DISABLE.value() == shopInfo.getOnSale()) {
|
||||
throw new ApiNotPrintException("店铺已停业,请联系商家");
|
||||
}
|
||||
|
||||
shopInfo.setBookingSms(null);
|
||||
shopInfo.setOperationPwd(null);
|
||||
shopInfo.setBindAccount(null);
|
||||
return shopInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status) {
|
||||
@@ -99,4 +121,24 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
public ShopInfo detail() {
|
||||
return queryChain().eq(ShopInfo::getId, StpKit.USER.getLoginIdAsLong()).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopInfoByCodeDTO getByCode(String tableCode, String lat, String lng, boolean checkState) {
|
||||
ShopTable shopTable = shopTableService.queryChain().eq(ShopTable::getTableCode, tableCode).one();
|
||||
if (shopTable == null) {
|
||||
throw new ApiNotPrintException("错误的台桌码");
|
||||
}
|
||||
|
||||
if (checkState && !shopTable.canUseByStatus()) {
|
||||
throw new ApiNotPrintException("台桌状态不可用");
|
||||
}
|
||||
ShopInfo shopInfo = getShopInfo(shopTable.getShopId());
|
||||
|
||||
double distance = 0;
|
||||
if (StrUtil.isAllNotBlank(lat, lng, shopInfo.getLat(), shopInfo.getLng())) {
|
||||
// 计算距离,单位:米
|
||||
distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng));
|
||||
}
|
||||
return new ShopInfoByCodeDTO(distance, shopInfo, shopTable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
import com.czg.account.service.ShopTableService;
|
||||
import com.czg.service.account.mapper.ShopTableMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 台桌配置 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable> implements ShopTableService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?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.czg.service.account.mapper.ShopTableMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -23,13 +23,13 @@ public class Main {
|
||||
// packageName 指定生成代码项目
|
||||
// tableName 指定需要生成的表
|
||||
|
||||
String packageName = "system";
|
||||
// String packageName = "account";
|
||||
// String packageName = "product";
|
||||
// String packageName = "order";
|
||||
// String servicePackageName = "system";
|
||||
// String servicePackageName = "account";
|
||||
// String servicePackageName = "product";
|
||||
String packageName = "account";
|
||||
|
||||
String tableName = "tb_order_detail";
|
||||
String author = "ww";
|
||||
String tableName = "tb_shop_table";
|
||||
String author = "zs";
|
||||
|
||||
//配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
|
||||
Reference in New Issue
Block a user