Răsfoiți Sursa

fixed 多商户权限问题

fushengqian 1 an în urmă
părinte
comite
40eada97b0

+ 14 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fuint.common.dto.AccountDto;
 import com.fuint.common.dto.AccountInfo;
 import com.fuint.common.service.AccountService;
+import com.fuint.common.service.StaffService;
 import com.fuint.framework.annoation.OperationServiceLog;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.exception.BusinessRuntimeException;
@@ -19,6 +20,7 @@ import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
@@ -51,6 +53,12 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
     @Resource
     private MtStoreMapper mtStoreMapper;
 
+    /**
+     * 员工接口
+     */
+    @Autowired
+    private StaffService staffService;
+
     /**
      * 分页查询账号列表
      *
@@ -232,6 +240,12 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
                 }
             }
         }
+        if (tAccount.getStaffId() != null && tAccount.getStaffId() > 0) {
+            MtStaff mtStaff = staffService.queryStaffById(tAccount.getStaffId());
+            if (mtStaff == null) {
+                tAccount.setStaffId(0);
+            }
+        }
         tAccountMapper.updateById(tAccount);
     }
 

+ 7 - 5
fuint-application/src/main/java/com/fuint/common/service/impl/MerchantServiceImpl.java

@@ -100,7 +100,9 @@ public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchan
         } else {
             mtMerchant.setNo(merchant.getNo());
         }
-
+        if (merchant.getType() != null) {
+            mtMerchant.setType(merchant.getType());
+        }
         mtMerchant.setName(merchant.getName());
         mtMerchant.setLogo(merchant.getLogo());
         mtMerchant.setContact(merchant.getContact());
@@ -165,7 +167,7 @@ public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchan
     /**
      * 根据商户号获取商户ID
      *
-     * @param  merchantNo 商户号
+     * @param merchantNo 商户号
      * @return
      */
     @Override
@@ -184,9 +186,9 @@ public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchan
     /**
      * 更新商户状态
      *
-     * @param id       商户ID
-     * @param operator 操作人
-     * @param status   状态
+     * @param  id       商户ID
+     * @param  operator 操作人
+     * @param  status   状态
      * @throws BusinessCheckException
      */
     @Override

+ 6 - 6
fuint-application/src/main/java/com/fuint/common/service/impl/SettlementServiceImpl.java

@@ -130,13 +130,7 @@ public class SettlementServiceImpl implements SettlementService {
         Integer buyNum = param.getBuyNum() == null ? 1 : param.getBuyNum(); // 立即购买商品数量
         String orderMode = param.getOrderMode()== null ? OrderModeEnum.ONESELF.getKey() : param.getOrderMode(); // 订单模式(配送or自取)
         Integer orderId = param.getOrderId() == null ? null : param.getOrderId(); // 订单ID
-
         Integer merchantId = merchantService.getMerchantId(merchantNo);
-        MtSetting config = settingService.querySettingByName(merchantId, OrderSettingEnum.IS_CLOSE.getKey());
-        if (config != null && config.getValue().equals("true")) {
-            throw new BusinessCheckException("系统已关闭交易功能,请稍后再试!");
-        }
-
         UserInfo loginInfo = TokenUtil.getUserInfoByToken(token);
         MtUser userInfo = null;
         if (loginInfo != null) {
@@ -152,6 +146,7 @@ public class SettlementServiceImpl implements SettlementService {
             operator = accountInfo.getAccountName();
             staffId = accountInfo.getStaffId() == null ? 0 : accountInfo.getStaffId();
             storeId = accountInfo.getStoreId();
+            merchantId = accountInfo.getMerchantId();
             if (storeId <= 0) {
                 MtStore mtStore = storeService.getDefaultStore(merchantNo);
                 if (mtStore != null) {
@@ -175,6 +170,11 @@ public class SettlementServiceImpl implements SettlementService {
             }
         }
 
+        MtSetting config = settingService.querySettingByName(merchantId, OrderSettingEnum.IS_CLOSE.getKey());
+        if (config != null && config.getValue().equals("true")) {
+            throw new BusinessCheckException("系统已关闭交易功能,请稍后再试!");
+        }
+
         // 收银台通过手机号自动注册会员信息
         if ((userInfo == null || StringUtil.isEmpty(token))) {
             String mobile = param.getMobile() == null ? "" : param.getMobile();

+ 7 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java

@@ -134,13 +134,18 @@ public class StaffServiceImpl extends ServiceImpl<MtStaffMapper, MtStaff> implem
             }
         }
 
+        MtUser mtUser = null;
+        if (mtStaff.getUserId() != null) {
+            mtUser = memberService.queryMemberById(mtStaff.getUserId());
+        }
+
         // 关联会员信息
-        if (mtStaff.getUserId() == null) {
+        if (mtStaff.getUserId() == null || mtUser == null) {
             MtUser userInfo = new MtUser();
             userInfo.setName(mtStaff.getRealName());
             userInfo.setDescription("系统自动注册店铺员工账号");
             userInfo.setStoreId(mtStaff.getStoreId());
-            MtUser mtUser = memberService.addMember(userInfo);
+            mtUser = memberService.addMember(userInfo);
             if (mtUser != null) {
                 mtStaff.setUserId(mtUser.getId());
             } else {

+ 1 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendCashierController.java

@@ -376,6 +376,7 @@ public class BackendCashierController extends BaseController {
              String hangNo = "#0" + (i+1);
              Map<String, Object> param = new HashMap<>();
              param.put("hangNo", hangNo);
+             param.put("merchantId", accountInfo.getMerchantId());
              List<MtCart> cartList = cartService.queryCartListByParams(param);
              HangUpDto dto = new HangUpDto();
              dto.setIsEmpty(true);

+ 27 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMerchantController.java

@@ -2,6 +2,7 @@ package com.fuint.module.backendApi.controller;
 
 import com.fuint.common.Constants;
 import com.fuint.common.dto.AccountInfo;
+import com.fuint.common.enums.MerchantTypeEnum;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.service.MerchantService;
 import com.fuint.common.service.SettingService;
@@ -56,6 +57,7 @@ public class BackendMerchantController extends BaseController {
     @RequestMapping(value = "/list")
     @CrossOrigin
     public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
         Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
         Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
 
@@ -63,6 +65,14 @@ public class BackendMerchantController extends BaseController {
         String merchantName = request.getParameter("name");
         String status = request.getParameter("status");
 
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        }
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            merchantId = accountInfo.getMerchantId().toString();
+        }
+
         PaginationRequest paginationRequest = new PaginationRequest();
         paginationRequest.setCurrentPage(page);
         paginationRequest.setPageSize(pageSize);
@@ -133,6 +143,9 @@ public class BackendMerchantController extends BaseController {
         if (accountInfo == null) {
             return getFailureResult(1001, "请先登录");
         }
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            merchantId = accountInfo.getMerchantId();
+        }
 
         String operator = accountInfo.getAccountName();
         merchantService.updateStatus(merchantId, operator, status);
@@ -175,6 +188,10 @@ public class BackendMerchantController extends BaseController {
         merchantInfo.setAddress(address);
         merchantInfo.setLogo(logo);
         merchantInfo.setStatus(status);
+        merchantInfo.setType(MerchantTypeEnum.RETAIL.getKey());
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            merchantInfo.setId(accountInfo.getMerchantId());
+        }
 
         if (StringUtil.isEmpty(name)) {
             return getFailureResult(201, "商户名称不能为空");
@@ -206,7 +223,16 @@ public class BackendMerchantController extends BaseController {
     @ApiOperation(value = "获取商户详情")
     @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
     @CrossOrigin
-    public ResponseObject getMerchantInfo(@PathVariable("id") Integer id) throws BusinessCheckException {
+    public ResponseObject getMerchantInfo(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        if (accountInfo == null) {
+            return getFailureResult(1001, "请先登录");
+        }
+        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+            id = accountInfo.getMerchantId();
+        }
+
         MtMerchant merchantInfo = merchantService.queryMerchantById(id);;
 
         Map<String, Object> result = new HashMap<>();

+ 13 - 2
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientCartController.java

@@ -126,6 +126,9 @@ public class ClientCartController extends BaseController {
         }
 
         Integer merchantId = merchantService.getMerchantId(merchantNo);
+        if (merchantId <= 0) {
+            merchantId = mtUser.getMerchantId();
+        }
 
         MtCart mtCart = new MtCart();
         mtCart.setGoodsId(goodsId);
@@ -204,6 +207,7 @@ public class ClientCartController extends BaseController {
         Integer userId = cartListParam.getUserId() == null ? 0 : cartListParam.getUserId(); // 会员ID
         String point = cartListParam.getPoint() == null ? "" : cartListParam.getPoint();
         String hangNo = cartListParam.getHangNo() == null ? "" : cartListParam.getHangNo();
+        Integer merchantId = merchantService.getMerchantId(merchantNo);
         boolean isUsePoint = false;
         if (point.equals("true")) {
             isUsePoint = true;
@@ -237,6 +241,12 @@ public class ClientCartController extends BaseController {
             param.put("ids", cartIds);
         }
 
+        if (merchantId <= 0) {
+            merchantId = mtUser.getMerchantId();
+        }
+        if (merchantId > 0) {
+            param.put("merchantId", merchantId);
+        }
         param.put("status", StatusEnum.ENABLED.getKey());
         if (StringUtil.isNotEmpty(hangNo)) {
             param = new HashMap<>();
@@ -279,8 +289,9 @@ public class ClientCartController extends BaseController {
             mtCart.setStatus(StatusEnum.ENABLED.getKey());
             cartList.add(mtCart);
         }
-
-        Integer merchantId = merchantService.getMerchantId(merchantNo);
+        if (merchantId <= 0) {
+            merchantId = mtUser.getMerchantId();
+        }
         result = orderService.calculateCartGoods(merchantId, mtUser.getId(), cartList, userCouponId, isUsePoint, platform, OrderModeEnum.EXPRESS.getKey());
 
         return getSuccessResult(result);

+ 3 - 0
fuint-repository/src/main/java/com/fuint/repository/model/MtMerchant.java

@@ -28,6 +28,9 @@ public class MtMerchant implements Serializable {
     @TableId(value = "ID", type = IdType.AUTO)
     private Integer id;
 
+    @ApiModelProperty("类型")
+    private String type;
+
     @ApiModelProperty("商户号")
     private String no;
 

+ 1 - 1
fuint-repository/src/main/resources/mapper/MtUserMapper.xml

@@ -4,7 +4,7 @@
     <select id="queryMemberByMobile" resultType="com.fuint.repository.model.MtUser">
         select * from mt_user t where t.MOBILE = #{mobile}
         <if test="merchantId != null and merchantId > 0">
-            WHERE t.MERCHANT_ID = #{merchantId}
+            AND t.MERCHANT_ID = #{merchantId}
         </if>
     </select>