feat(shop): 营业时间总开关
This commit is contained in:
1 parent
265f1647b0
commit
c18fdcbad2
9 files changed
+94
-40
No files matched your search
+7
@@ -50,6 +50,7 @@ import co.yixiang.yshop.module.store.convert.storeshop.StoreShopConvert;
|
|||||||
import co.yixiang.yshop.module.store.dal.dataobject.storeshop.StoreShopDO;
|
import co.yixiang.yshop.module.store.dal.dataobject.storeshop.StoreShopDO;
|
||||||
import co.yixiang.yshop.module.store.service.storeshop.AppStoreShopService;
|
import co.yixiang.yshop.module.store.service.storeshop.AppStoreShopService;
|
||||||
import co.yixiang.yshop.module.store.service.storeshop.DeliveryCalculator;
|
import co.yixiang.yshop.module.store.service.storeshop.DeliveryCalculator;
|
||||||
|
import co.yixiang.yshop.module.store.service.storeshop.ShopBusinessHoursUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
@@ -180,6 +181,12 @@ public class AppStoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper,Store
|
|||||||
List<String> cartIds = new ArrayList<>();
|
List<String> cartIds = new ArrayList<>();
|
||||||
|
|
||||||
StoreShopDO storeShopDO = appStoreShopService.getById(param.getShopId());
|
StoreShopDO storeShopDO = appStoreShopService.getById(param.getShopId());
|
||||||
|
if (storeShopDO == null) {
|
||||||
|
throw exception(co.yixiang.yshop.module.store.enums.ErrorCodeConstants.SHOP_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
if (!ShopBusinessHoursUtils.isCurrentlyOpen(storeShopDO)) {
|
||||||
|
throw exception(co.yixiang.yshop.module.store.enums.ErrorCodeConstants.STORE_SHOP_NOT_OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
BigDecimal sumPrice = BigDecimal.ZERO;
|
BigDecimal sumPrice = BigDecimal.ZERO;
|
||||||
BigDecimal couponPrice = BigDecimal.ZERO;
|
BigDecimal couponPrice = BigDecimal.ZERO;
|
||||||
|
|||||||
+1
@@ -8,4 +8,5 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode STORE_REVENUE_NOT_EXISTS = new ErrorCode(1008016002, "店铺收支明细不存在");
|
ErrorCode STORE_REVENUE_NOT_EXISTS = new ErrorCode(1008016002, "店铺收支明细不存在");
|
||||||
ErrorCode WITHDRAWAL_NOT_EXISTS = new ErrorCode(1008016003, "提现管理不存在");
|
ErrorCode WITHDRAWAL_NOT_EXISTS = new ErrorCode(1008016003, "提现管理不存在");
|
||||||
ErrorCode USER_BANK_NOT_EXISTS = new ErrorCode(1008016004, "提现账户不存在");
|
ErrorCode USER_BANK_NOT_EXISTS = new ErrorCode(1008016004, "提现账户不存在");
|
||||||
|
ErrorCode STORE_SHOP_NOT_OPEN = new ErrorCode(1008016005, "店铺不在营业中,暂时无法下单");
|
||||||
}
|
}
|
||||||
+1
-1
@@ -75,7 +75,7 @@ public class StoreShopBaseVO {
|
|||||||
@NotNull(message = "公告不能为空")
|
@NotNull(message = "公告不能为空")
|
||||||
private String notice;
|
private String notice;
|
||||||
|
|
||||||
@Schema(description = "是否营业:0=否,1=是", required = true, example = "2")
|
@Schema(description = "是否营业总开关:0=否,1=是(为是且配置了营业时段时,下单以时段为准)", required = true, example = "1")
|
||||||
@NotNull(message = "是否营业:0=否,1=是不能为空")
|
@NotNull(message = "是否营业:0=否,1=是不能为空")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -78,7 +78,10 @@ public class AppStoreShopVO {
|
|||||||
@Schema(description = "桌面订单", required = true)
|
@Schema(description = "桌面订单", required = true)
|
||||||
private String deskOrderId;
|
private String deskOrderId;
|
||||||
|
|
||||||
@Schema(description = "是否营业:0=否,1=是", required = true)
|
@Schema(description = "是否营业总开关:0=否,1=是", required = true)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "当前是否可下单:0=否,1=是(总开关为是且在营业时段内)")
|
||||||
|
private Integer open;
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -93,7 +93,7 @@ public class StoreShopDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String notice;
|
private String notice;
|
||||||
/**
|
/**
|
||||||
* 是否营业:0=否,1=是
|
* 是否营业总开关:0=否,1=是
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-1
@@ -34,7 +34,16 @@ public class AppStoreShopServiceImpl extends ServiceImpl<StoreShopMapper, StoreS
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AppStoreShopVO> getStoreList(double lon, double lat,String name,Integer shopId) {
|
public List<AppStoreShopVO> getStoreList(double lon, double lat,String name,Integer shopId) {
|
||||||
return shopMapper.getStoreList(lon,lat,name,shopId);
|
List<AppStoreShopVO> list = shopMapper.getStoreList(lon, lat, name, shopId);
|
||||||
|
if (list == null) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
for (AppStoreShopVO shop : list) {
|
||||||
|
boolean open = ShopBusinessHoursUtils.isCurrentlyOpen(
|
||||||
|
shop.getStatus(), shop.getStartTime(), shop.getEndTime());
|
||||||
|
shop.setOpen(open ? 1 : 0);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package co.yixiang.yshop.module.store.service.storeshop;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import co.yixiang.yshop.module.store.dal.dataobject.storeshop.StoreShopDO;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店是否可下单:status 为总开关;为营业且配置了起止时间时,再按营业时段判断。
|
||||||
|
*/
|
||||||
|
public final class ShopBusinessHoursUtils {
|
||||||
|
|
||||||
|
private ShopBusinessHoursUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param status 是否营业总开关:0=否,1=是
|
||||||
|
* @param startTime 营业开始时间(可空,仅取时分)
|
||||||
|
* @param endTime 营业结束时间(可空,仅取时分)
|
||||||
|
* @return 当前是否允许下单
|
||||||
|
*/
|
||||||
|
public static boolean isCurrentlyOpen(Integer status, Date startTime, Date endTime) {
|
||||||
|
if (status == null || status != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (startTime == null || endTime == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return isWithinBusinessHours(startTime, endTime, new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCurrentlyOpen(StoreShopDO shop) {
|
||||||
|
if (shop == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isCurrentlyOpen(shop.getStatus(), shop.getStartTime(), shop.getEndTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前时刻是否落在营业时段内(仅比较时、分;不支持跨天)。
|
||||||
|
*/
|
||||||
|
public static boolean isWithinBusinessHours(Date startTime, Date endTime, Date now) {
|
||||||
|
if (startTime == null || endTime == null || now == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int sH = DateUtil.hour(startTime, true);
|
||||||
|
int sM = DateUtil.minute(startTime);
|
||||||
|
int eH = DateUtil.hour(endTime, true);
|
||||||
|
int eM = DateUtil.minute(endTime);
|
||||||
|
int nH = DateUtil.hour(now, true);
|
||||||
|
int nM = DateUtil.minute(now);
|
||||||
|
if (nH < sH) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (eH < nH) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (nH == sH && sM > nM) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (eH == nH && eM < nM) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-36
@@ -1,7 +1,5 @@
|
|||||||
package co.yixiang.yshop.module.store.service.storeshop;
|
package co.yixiang.yshop.module.store.service.storeshop;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||||
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
|
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
@@ -43,10 +41,8 @@ public class StoreShopServiceImpl implements StoreShopService {
|
|||||||
throw exception(new ErrorCode(1000,"管理员ID:"+val+"已经绑定过其他门店,不能再次绑定"));
|
throw exception(new ErrorCode(1000,"管理员ID:"+val+"已经绑定过其他门店,不能再次绑定"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 插入
|
// 插入:status 为总开关,按后台提交值落库,不再按营业时间覆盖
|
||||||
StoreShopDO shop = StoreShopConvert.INSTANCE.convert(createReqVO);
|
StoreShopDO shop = StoreShopConvert.INSTANCE.convert(createReqVO);
|
||||||
Integer status = doShopStatus(shop.getStartTime(),shop.getEndTime());
|
|
||||||
shop.setStatus(status);
|
|
||||||
shopMapper.insert(shop);
|
shopMapper.insert(shop);
|
||||||
// 返回
|
// 返回
|
||||||
return shop.getId();
|
return shop.getId();
|
||||||
@@ -67,41 +63,11 @@ public class StoreShopServiceImpl implements StoreShopService {
|
|||||||
});
|
});
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateShopExists(updateReqVO.getId());
|
validateShopExists(updateReqVO.getId());
|
||||||
// 更新
|
// 更新:status 为总开关,按后台提交值落库
|
||||||
StoreShopDO updateObj = StoreShopConvert.INSTANCE.convert(updateReqVO);
|
StoreShopDO updateObj = StoreShopConvert.INSTANCE.convert(updateReqVO);
|
||||||
Integer status = doShopStatus(updateObj.getStartTime(),updateObj.getEndTime());
|
|
||||||
updateObj.setStatus(status);
|
|
||||||
shopMapper.updateById(updateObj);
|
shopMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理营业时间
|
|
||||||
* @param startTime
|
|
||||||
* @param endTime
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Integer doShopStatus(Date startTime,Date endTime){
|
|
||||||
Date now = new Date();
|
|
||||||
Integer sH = DateUtil.hour(startTime,true);
|
|
||||||
Integer sM = DateUtil.minute(startTime);
|
|
||||||
Integer eH = DateUtil.hour(endTime,true);
|
|
||||||
Integer eM = DateUtil.minute(endTime);
|
|
||||||
Integer nH = DateUtil.hour(now,true);
|
|
||||||
Integer nM = DateUtil.minute(now);
|
|
||||||
if(nH < sH){
|
|
||||||
return 0;
|
|
||||||
}else if(eH < nH){
|
|
||||||
return 0;
|
|
||||||
}else if(nH == sH && sM > nM){
|
|
||||||
return 0;
|
|
||||||
}else if(eH == nH && eM < nM){
|
|
||||||
return 0;
|
|
||||||
} else{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteShop(Long id) {
|
public void deleteShop(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
<el-radio :label="1">是</el-radio>
|
<el-radio :label="1">是</el-radio>
|
||||||
<el-radio :label="0">否</el-radio>
|
<el-radio :label="0">否</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
<div style="color: #909399; font-size: 12px;">总开关:选「是」后,若填写了营业起止时间,下单以时段为准;选「否」则全天不可下单</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user