|
|
@@ -14,6 +14,7 @@ import com.ruoyi.app.service.UserService;
|
|
|
import com.ruoyi.app.utils.DateUtil;
|
|
|
import com.ruoyi.app.utils.ImageCompressUtils;
|
|
|
import com.ruoyi.app.user.dto.StoreOutput;
|
|
|
+import com.ruoyi.app.user.MerchantTokenSessionService;
|
|
|
import com.ruoyi.app.utils.PayPush;
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
@@ -83,6 +84,12 @@ public class PosStoreController extends BaseController {
|
|
|
private IPosStoreEzpayService posStoreEzpayService;
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private MerchantStoreAccessService merchantStoreAccessService;
|
|
|
+ @Autowired
|
|
|
+ private MerchantTokenSessionService merchantTokenSessionService;
|
|
|
+ @Autowired
|
|
|
+ private IMerchantSubaccountStoreService merchantSubaccountStoreService;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -119,15 +126,23 @@ public class PosStoreController extends BaseController {
|
|
|
//删除我的门店
|
|
|
@Anonymous
|
|
|
@Auth
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@GetMapping("/delemendian")
|
|
|
- public AjaxResult delemendian(@RequestParam String id) {
|
|
|
+ public AjaxResult delemendian(@RequestHeader String token, @RequestParam String id) {
|
|
|
+ Long userId = merchantTokenSessionService.requireUserId(token);
|
|
|
+ merchantStoreAccessService.requireOwner(userId);
|
|
|
+ merchantStoreAccessService.requireStoreAccess(userId, Long.valueOf(id));
|
|
|
QueryWrapper<PosFenlei> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("mendid", id);
|
|
|
List<PosFenlei> list = posFenleiService.list(queryWrapper);
|
|
|
if (list.size() > 0) {
|
|
|
return error(MessageUtils.message("no.mendian.exist.classify.not.del"));
|
|
|
} else {
|
|
|
- return toAjax(posStoreService.deletePosStoreById(Long.valueOf(id)));
|
|
|
+ int rows = posStoreService.deletePosStoreById(Long.valueOf(id));
|
|
|
+ if (rows > 0) {
|
|
|
+ merchantSubaccountStoreService.deleteByStoreId(Long.valueOf(id));
|
|
|
+ }
|
|
|
+ return toAjax(rows);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -140,8 +155,7 @@ public class PosStoreController extends BaseController {
|
|
|
public AjaxResult storelistlist(@RequestHeader String token,
|
|
|
@RequestParam Integer page,
|
|
|
@RequestParam Integer size) {
|
|
|
- JwtUtil jwtUtil = new JwtUtil();
|
|
|
- String id = jwtUtil.getusid(token);
|
|
|
+ Long id = merchantTokenSessionService.requireUserId(token);
|
|
|
IPage<PosStore> stlist = new Page<>(page, size);
|
|
|
QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
|
@@ -154,7 +168,12 @@ public class PosStoreController extends BaseController {
|
|
|
queryWrapper.eq("id", -1); // 无关联摊位,返回空列表
|
|
|
}
|
|
|
} else {
|
|
|
- queryWrapper.eq("user_id", id);
|
|
|
+ Set<Long> storeIds = merchantStoreAccessService.getAccessibleStoreIds(id);
|
|
|
+ if (storeIds.isEmpty()) {
|
|
|
+ queryWrapper.eq("id", -1);
|
|
|
+ } else {
|
|
|
+ queryWrapper.in("id", storeIds);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
IPage<PosStore> list = posStoreService.page(stlist, queryWrapper);
|
|
|
@@ -177,10 +196,19 @@ public class PosStoreController extends BaseController {
|
|
|
@Auth
|
|
|
@GetMapping("/getmystorelist")
|
|
|
public AjaxResult getmystorelist(@RequestHeader String token) {
|
|
|
- JwtUtil jwtUtil = new JwtUtil();
|
|
|
- String id = jwtUtil.getusid(token);
|
|
|
+ Long id = merchantTokenSessionService.requireUserId(token);
|
|
|
QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("user_id", id);
|
|
|
+ InfoUser loginUser = infoUserService.selectInfoUserByUserId(id);
|
|
|
+ if (loginUser != null && "4".equals(loginUser.getUserType())) {
|
|
|
+ queryWrapper.eq("id", loginUser.getStoreId() == null ? -1 : loginUser.getStoreId());
|
|
|
+ } else {
|
|
|
+ Set<Long> storeIds = merchantStoreAccessService.getAccessibleStoreIds(id);
|
|
|
+ if (storeIds.isEmpty()) {
|
|
|
+ queryWrapper.eq("id", -1);
|
|
|
+ } else {
|
|
|
+ queryWrapper.in("id", storeIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
List<PosStore> list = posStoreService.list(queryWrapper);
|
|
|
return success(list);
|
|
|
}
|
|
|
@@ -260,12 +288,23 @@ public class PosStoreController extends BaseController {
|
|
|
|
|
|
//添加门店
|
|
|
@Anonymous
|
|
|
+ @Auth
|
|
|
@PostMapping("/addmendian")
|
|
|
@Transactional
|
|
|
- public AjaxResult addmendian(@RequestBody PosStore posStore) {
|
|
|
- // 新增时校验商家审核状态(未审核不能新增门市);不强制 token,身份取请求体 userId
|
|
|
- if (posStore.getId() == null && posStore.getUserId() != null) {
|
|
|
- userService.checkUserStatus(posStore.getUserId());
|
|
|
+ public AjaxResult addmendian(@RequestHeader String token, @RequestBody PosStore posStore) {
|
|
|
+ Long loginUserId = merchantTokenSessionService.requireUserId(token);
|
|
|
+ InfoUser loginUser = infoUserService.selectInfoUserByUserId(loginUserId);
|
|
|
+ if (posStore.getId() == null) {
|
|
|
+ merchantStoreAccessService.requireOwner(loginUserId);
|
|
|
+ userService.checkUserStatus(loginUserId);
|
|
|
+ posStore.setUserId(loginUserId);
|
|
|
+ } else {
|
|
|
+ requireStoreAccess(loginUserId, loginUser, posStore.getId().longValue());
|
|
|
+ PosStore existing = posStoreService.getById(posStore.getId());
|
|
|
+ if (existing == null) {
|
|
|
+ throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
|
|
|
+ }
|
|
|
+ posStore.setUserId(existing.getUserId());
|
|
|
}
|
|
|
try {
|
|
|
// 1. 先保存门店信息
|
|
|
@@ -296,8 +335,11 @@ public class PosStoreController extends BaseController {
|
|
|
posStoreEzpayService.uploadUbn(store.getId().longValue(), posStore.getUbn());
|
|
|
}
|
|
|
return success(MessageUtils.message("no.success"), store);
|
|
|
- } catch (Exception e) {
|
|
|
- return error("添加门店失败: " + e.getMessage());
|
|
|
+ } catch (ServiceException exception) {
|
|
|
+ throw exception;
|
|
|
+ } catch (Exception exception) {
|
|
|
+ logger.error("保存商家门店失败,userId:{},storeId:{}", loginUserId, posStore.getId(), exception);
|
|
|
+ return error(MessageUtils.message("no.system.error"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -342,7 +384,9 @@ public class PosStoreController extends BaseController {
|
|
|
@Anonymous
|
|
|
@Auth
|
|
|
@GetMapping("/getMdBusinessHours")
|
|
|
- public AjaxResult getMdBusinessHours(@RequestParam Long mdId){
|
|
|
+ public AjaxResult getMdBusinessHours(@RequestHeader String token, @RequestParam Long mdId){
|
|
|
+ Long userId = merchantTokenSessionService.requireUserId(token);
|
|
|
+ requireStoreAccess(userId, infoUserService.selectInfoUserByUserId(userId), mdId);
|
|
|
LambdaQueryWrapper<OperatingHours> query=new LambdaQueryWrapper<>();
|
|
|
query.eq(OperatingHours::getMdId,mdId);
|
|
|
List<OperatingHours> list = operatingHoursService.list(query);
|
|
|
@@ -361,11 +405,17 @@ public class PosStoreController extends BaseController {
|
|
|
@Anonymous
|
|
|
@Auth
|
|
|
@PostMapping("/saveMdBusinessHours")
|
|
|
- public AjaxResult saveMdBusinessHours(@RequestBody List<StoreOperatOutput> businessHours) {
|
|
|
+ public AjaxResult saveMdBusinessHours(@RequestHeader String token,
|
|
|
+ @RequestBody List<StoreOperatOutput> businessHours) {
|
|
|
if(businessHours == null || businessHours.isEmpty()) {
|
|
|
throw new ServiceException(MessageUtils.message("no.mendian.not.set.business.hours"));
|
|
|
}
|
|
|
Long mdId = businessHours.get(0).getMdId();
|
|
|
+ Long userId = merchantTokenSessionService.requireUserId(token);
|
|
|
+ requireStoreAccess(userId, infoUserService.selectInfoUserByUserId(userId), mdId);
|
|
|
+ if (businessHours.stream().anyMatch(item -> !Objects.equals(mdId, item.getMdId()))) {
|
|
|
+ throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
|
|
|
+ }
|
|
|
PosStore store = posStoreService.getById(businessHours.get(0).getMdId());
|
|
|
// 先删除旧的营业时间记录
|
|
|
LambdaQueryWrapper<OperatingHours> query = new LambdaQueryWrapper<>();
|
|
|
@@ -392,6 +442,16 @@ public class PosStoreController extends BaseController {
|
|
|
return success();
|
|
|
}
|
|
|
|
|
|
+ private void requireStoreAccess(Long loginUserId, InfoUser loginUser, Long storeId) {
|
|
|
+ if (loginUser != null && "4".equals(loginUser.getUserType())) {
|
|
|
+ if (!Objects.equals(loginUser.getStoreId(), storeId)) {
|
|
|
+ throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ merchantStoreAccessService.requireStoreAccess(loginUserId, storeId);
|
|
|
+ }
|
|
|
+
|
|
|
//返回营业时间(按星期分组)
|
|
|
private List<StoreOperatOutput> getStoreOperatOutput(List<OperatingHours> list, Long mdId){
|
|
|
List<StoreOperatOutput> data= new ArrayList<>();
|