Browse Source

门店基础信息 店铺注销前效验

qxy 1 tuần trước cách đây
mục cha
commit
4371380eb0

+ 22 - 8
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -16,6 +16,7 @@ import shop.alien.store.service.StoreInfoService;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -57,14 +58,15 @@ public class StoreInfoController {
     @PostMapping("/saveOrUpdate")
     public R saveOrUpdate(@RequestBody StoreInfo storeInfo) {
         log.info("StoreInfoController.saveOrUpdate?storeInfo={}", storeInfo);
-        Integer id = storeInfo.getId();
-        if (storeInfoService.saveOrUpdate(storeInfo)) {
-            if (null != id) {
-                return R.success("修改成功");
-            }
-            return R.success("新增成功");
-        }
-        return R.fail("失败");
+        return R.data(storeInfoService.saveOrUpdateStoreInfo(storeInfo));
+//        Integer id = storeInfo.getId();
+//        if (storeInfoService.saveOrUpdate(storeInfo)) {
+//            if (null != id) {
+//                return R.success("修改成功");
+//            }
+//            return R.success("新增成功");
+//        }
+//        return R.fail("失败");
     }
 
     @ApiOperation("web端新增门店")
@@ -511,4 +513,16 @@ public class StoreInfoController {
         return R.data(storeInfoService.getStoreInfoByStoreTel(storeTel));
     }
 
+    /**
+     * 商家端注销店铺效验
+     * @param id 门店id
+     */
+    @ApiOperation("商家端注销店铺效验")
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "门店id", dataType = "int", paramType = "query", required = true)})
+    @GetMapping("/storeInfoVerification")
+    public R<Map<String, String>> storeInfoVerification(int id) {
+        log.info("StoreInfoController.storeInfoVerification?id={}", id);
+        return R.data(storeInfoService.storeInfoVerification(id));
+    }
+
 }

+ 15 - 0
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.multipart.MultipartRequest;
+import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreInfo;
 import shop.alien.entity.store.StoreInfoDraft;
 import shop.alien.entity.store.dto.StoreInfoDto;
@@ -11,6 +12,7 @@ import shop.alien.entity.store.vo.*;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 二期-门店信息 服务类
@@ -214,4 +216,17 @@ public interface StoreInfoService extends IService<StoreInfo> {
      * @return
      */
     int editStoreCommissionRate(StoreInfoDto storeInfoDto);
+
+    /**
+     * 新增或修改店铺信息
+     * @param storeInfo
+     * @return
+     */
+    R saveOrUpdateStoreInfo(StoreInfo storeInfo);
+
+    /**
+     * 商家注销店铺效验
+     */
+    Map<String,String> storeInfoVerification(int id);
+
 }

+ 97 - 11
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartRequest;
+import shop.alien.entity.result.R;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.dto.NearMeDto;
 import shop.alien.entity.store.dto.StoreInfoDto;
@@ -348,7 +349,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                     record.setDaysToExpire(daysToExpire);
                 }
                 // 处理状态
-                if(record.getLogoutFlag() == 1){
+                if (record.getLogoutFlag() == 1) {
                     record.setStoreStatusStr("已注销");
                     record.setStoreStatus(2);
                 }
@@ -439,7 +440,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                 return false;
             }
             store.setStorePosition(LonAndLat);
-            if(null == store.getCommissionRate()){
+            if (null == store.getCommissionRate()) {
                 store.setCommissionRate("0.03");
             }
             this.save(store);
@@ -539,7 +540,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         EssentialCityCode essentialCityCode3 =
                 essentialCityCodeMapper.selectOne(new LambdaQueryWrapper<EssentialCityCode>().eq(EssentialCityCode::getAreaCode, storeInfo.getAdministrativeRegionDistrictAdcode()));
         storeInfo.setAdministrativeRegionDistrictName(essentialCityCode3.getAreaName());
-        if(null == storeInfo.getCommissionRate()){
+        if (null == storeInfo.getCommissionRate()) {
             storeInfo.setCommissionRate("3");
         }
         storeInfoMapper.insert(storeInfo);
@@ -730,7 +731,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         List<LifeUserOrder> lifeUserOrders = lifeUserOrderMapper.selectList(new LambdaQueryWrapper<LifeUserOrder>().in(LifeUserOrder::getStatus, 0, 3).eq(ObjectUtils.isNotEmpty(storeUser), LifeUserOrder::getUserId, storeUser.getId()).eq(LifeUserOrder::getDeleteFlag, 0));
         if (ObjectUtils.isNotEmpty(lifeUserOrders)) {
             return "您有暂未完成的订单无法删除店铺,请在完成后删除";
-        }else {
+        } else {
             //判断是否修改变更过的用户账户
             if (storeUser != null) {
                 LambdaUpdateWrapper<StoreUser> storeUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
@@ -1058,11 +1059,11 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                         LocalTime end = LocalTime.of(Integer.parseInt(endList.get(0)), Integer.parseInt(startList.get(1)));
                         if (now.isAfter(start) && now.isBefore(end)) {
                             result.setYyFlag(1);
-                        }else {
+                        } else {
                             result.setYyFlag(0);
                         }
                     }
-                }else {
+                } else {
                     result.setYyFlag(0);
                 }
             }
@@ -1076,15 +1077,15 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
         storeInfo.setStoreApplicationStatus(approvalStatus);
         storeInfo.setReason(reason);
-        StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()).eq(StoreUser::getDeleteFlag,0));
+        StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()).eq(StoreUser::getDeleteFlag, 0));
         // 发送审核通知
         LifeNotice lifeNotice = new LifeNotice();
         lifeNotice.setSenderId("system");
-        lifeNotice.setReceiverId("store_"+ storeUser.getPhone());
+        lifeNotice.setReceiverId("store_" + storeUser.getPhone());
         lifeNotice.setBusinessId(storeInfo.getId());
         lifeNotice.setTitle("店铺审核通知");
-        if(2 == approvalStatus){
-            lifeNotice.setContext("您的店铺申请被驳回,原因为:"+reason);
+        if (2 == approvalStatus) {
+            lifeNotice.setContext("您的店铺申请被驳回,原因为:" + reason);
         } else {
             lifeNotice.setContext("您的店铺申请已通过");
         }
@@ -1321,7 +1322,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                         .map(item -> String.valueOf(item.getStoreId()))
                         .collect(Collectors.toList());
             }
-            if(!CollectionUtils.isEmpty(storeIds)) {
+            if (!CollectionUtils.isEmpty(storeIds)) {
                 LambdaQueryWrapper<StoreInfo> queryWrapper = new LambdaQueryWrapper<>();
                 queryWrapper.in(StoreInfo::getId, storeIds);
                 storeInfoIPage = storeInfoMapper.selectPage(page, queryWrapper);
@@ -1421,4 +1422,89 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         wrapper.set(StoreInfo::getCommissionRate, storeInfoDto.getCommissionRate());
         return storeInfoMapper.update(null, wrapper);
     }
+
+    @Override
+    public R saveOrUpdateStoreInfo(StoreInfo storeInfo) {
+        try {
+            boolean flag = false;
+            if (storeInfo.getId() != null) {
+                //效验当前店铺存在未完成的订单及正在销售的商品
+                verificationStoreInfoStatus(storeInfo);
+                if (storeInfo.getBusinessStatus() == 0) {
+                    StoreInfo storeInfoOne = storeInfoMapper.selectOne(new LambdaQueryWrapper<StoreInfo>().eq(StoreInfo::getId, storeInfo.getId()));
+                    if (storeInfoOne.getBusinessStatus() == 99) {
+                        throw new RuntimeException("该店铺已经永久关闭不能更改状态为正常营业");
+                    }
+                }
+                int num = storeInfoMapper.updateById(storeInfo);
+                if (num > 0) {
+                    flag = true;
+                } else {
+                    throw new RuntimeException("修改失败");
+                }
+
+            } else {
+                int num = storeInfoMapper.insert(storeInfo);
+                if (num > 0) {
+                    flag = true;
+                } else {
+                    throw new RuntimeException("新增失败");
+                }
+            }
+            return null;
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+    @Override
+    public Map<String, String> storeInfoVerification(int id) {
+        Map<String, String> storeInfoMap = new HashMap<>();
+        LambdaQueryWrapper<StoreInfo> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StoreInfo::getId, id);
+        StoreInfo storeInfo = storeInfoMapper.selectOne(queryWrapper);
+        if(storeInfo!=null){
+            //判断店铺存在未体现金额 0:未通过 1:通过
+            //钱包功能暂未完成此效验默认状态都是1通过
+            StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId,id));
+            if(storeUser.getMoney() != null && storeUser.getMoney() > 0){
+                storeInfoMap.put("storetMoneyStatus","1");
+            }else{
+                storeInfoMap.put("storetMoneyStatus","1");
+            }
+            //判断店铺存在未完成订单 0:未通过 1:通过
+            List<LifeUserOrder> lifeUserOrders = lifeUserOrderMapper.selectList(new LambdaQueryWrapper<LifeUserOrder>().in(LifeUserOrder::getStatus, 0, 3).eq(LifeUserOrder::getStoreId, id).eq(LifeUserOrder::getDeleteFlag, 0));
+            if(!CollectionUtils.isEmpty(lifeUserOrders)){
+                storeInfoMap.put("storeOrderStatus","0");
+            }else{
+                storeInfoMap.put("storeOrderStatus","1");
+            }
+            //判断店铺存在正在售卖的商品 0:未通过 1:通过
+            List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getStatus, 0, 1)
+                    .and(qw -> qw.gt(LifeCoupon::getStockQty, 0).or().gt(LifeCoupon::getSingleQty, 0)).eq(LifeCoupon::getStoreId, id).eq(LifeCoupon::getDeleteFlag, 0));
+            if(!CollectionUtils.isEmpty(lifeCoupons)){
+                storeInfoMap.put("storeGoodsStatus","0");
+            }else{
+                storeInfoMap.put("storeGoodsStatus","1");
+            }
+        }
+        return storeInfoMap;
+    }
+
+    void verificationStoreInfoStatus(StoreInfo storeInfo) {
+        //营业状态 0:正常营业, 1:暂停营业, 2:筹建中, 99:永久关门
+         if (storeInfo.getBusinessStatus() == 2 || storeInfo.getBusinessStatus() == 99) {
+            //判断店铺有未完成的订单
+            List<LifeUserOrder> lifeUserOrders = lifeUserOrderMapper.selectList(new LambdaQueryWrapper<LifeUserOrder>().in(LifeUserOrder::getStatus, 0, 3).eq(LifeUserOrder::getStoreId, storeInfo.getId()).eq(LifeUserOrder::getDeleteFlag, 0));
+            if (!CollectionUtils.isEmpty(lifeUserOrders)) {
+                throw new RuntimeException("店铺有未完成的订单");
+            }
+            //判断店铺有正在售卖的商品
+            List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getStatus, 0, 1)
+                    .and(qw -> qw.gt(LifeCoupon::getStockQty, 0).or().gt(LifeCoupon::getSingleQty, 0)).eq(LifeCoupon::getStoreId, storeInfo.getId()).eq(LifeCoupon::getDeleteFlag, 0));
+            if (!CollectionUtils.isEmpty(lifeCoupons)) {
+                throw new RuntimeException("店铺有正在销售的商品");
+            }
+        }
+    }
 }

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreUserServiceImpl.java

@@ -583,11 +583,12 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
             if (null != storeUser.getStoreId()) {
                 StoreInfo storeInfo = storeInfoMapper.selectById(storeUser.getStoreId());
                 //vaule为0代表有商铺未注销
-                storeMap.put("accountStore", "1");
+                storeMap.put("accountStore", "0");
             } else {
                 //vaule为1代表绑定店铺已注销
                 storeMap.put("accountStore", "1");
             }
+            //钱包功能暂未完成此效验默认状态都是1通过
             if (storeUser.getMoney() != null && storeUser.getMoney() > 0) {
                 //vaule为0代表有未体现的现金
                 storeMap.put("accountMoney", "1");