Procházet zdrojové kódy

feat: 添加子账号管理接口

pangqijun před 3 měsíci
rodič
revize
210656c161

+ 69 - 3
src/main/java/org/springblade/modules/api/controller/ApiMerchantUserController.java

@@ -1,22 +1,34 @@
 package org.springblade.modules.api.controller;
 
+import cn.hutool.core.util.DesensitizedUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
 import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.enums.AuditStatusEnum;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.DigestUtil;
+import org.springblade.core.tool.utils.WebUtil;
+import org.springblade.modules.api.request.AddChildAccountRequest;
+import org.springblade.modules.auth.enums.UserEnum;
+import org.springblade.modules.auth.utils.TokenUtil;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.entity.UserMerchant;
 import org.springblade.modules.system.service.IUserMerchantService;
 import org.springblade.modules.system.service.IUserService;
 import org.springblade.modules.system.vo.UserMerchantVO;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
 
 /**
  * Author pangqijun
@@ -45,4 +57,58 @@ public class ApiMerchantUserController {
         vo.setPhone(user.getPhone());
         return R.data(vo);
     }
+
+    @PostMapping("/addChildAccount")
+    @ApiOperationSupport(order = 2)
+    @ApiOperation(value = "添加子账号", notes = "传入userMerchant")
+    public R<Void> addChildAccount(@Valid @RequestBody AddChildAccountRequest request) {
+        if (!request.getPassword().equals(request.getRePassword())) {
+            return R.fail("密码不一致");
+        }
+        User query1 = iUserService.getOne(Wrappers.<User>query().lambda().eq(User::getAccount, request.getPhone()));
+        if (query1 != null) {
+            return R.fail("手机号已注册!");
+        }
+        String tenantId = WebUtil.getRequest().getHeader(TokenUtil.TENANT_HEADER_KEY);
+        User user = new User();
+        user.setAccount(request.getPhone());
+        user.setPhone(request.getPhone());
+        user.setTenantId(tenantId);
+        user.setUserType(UserEnum.MERCHANT.getCategory());
+        user.setPassword(DigestUtil.encrypt(request.getPassword()));
+        user.setName(request.getNickname() == null ? DesensitizedUtil.mobilePhone(request.getPhone()) : request.getNickname());
+        user.setRealName(request.getRealName());
+        iUserService.save(user);
+
+        UserMerchant userMerchant = new UserMerchant();
+        userMerchant.setUserId(user.getId());
+        userMerchant.setParentId(AuthUtil.getUserId());
+        userMerchant.setAuditStatus(AuditStatusEnum.PASS.getValue());
+        iUserMerchantService.save(userMerchant);
+
+        return R.success("添加成功");
+    }
+
+    @Transactional
+    @PostMapping("/deleteChildAccount")
+    @ApiOperationSupport(order = 3)
+    @ApiOperation(value = "删除子账号", notes = "传入ids")
+    public R<Void> deleteChildAccount(@ApiParam(value = "主键集合", required = true) @RequestParam Long childAccountId) {
+        UserMerchant child = iUserMerchantService.getById(childAccountId);
+        Assert.notNull(child, "未查询到子账号信息");
+        iUserMerchantService.removeById(childAccountId);
+        return R.status(iUserService.removeById(childAccountId));
+    }
+
+    /**
+     * 自定义分页 商家用户表
+     */
+    @GetMapping("/childAccount/list")
+    @ApiOperationSupport(order = 3)
+    @ApiOperation(value = "子账号列表", notes = "传入userMerchant")
+    public R<IPage<UserMerchantVO>> page(UserMerchantVO userMerchant, Query query) {
+        userMerchant.setParentId(AuthUtil.getUserId());
+        IPage<UserMerchantVO> pages = iUserMerchantService.selectUserMerchantPage(Condition.getPage(query), userMerchant);
+        return R.data(pages);
+    }
 }

+ 14 - 0
src/main/java/org/springblade/modules/api/controller/ApiShopController.java

@@ -2,6 +2,7 @@ package org.springblade.modules.api.controller;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -17,7 +18,9 @@ import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.modules.business.entity.Facility;
 import org.springblade.modules.business.entity.Shop;
+import org.springblade.modules.business.service.IFacilityService;
 import org.springblade.modules.business.service.IShopService;
 import org.springblade.modules.business.vo.ShopVO;
 import org.springblade.modules.business.wrapper.ShopWrapper;
@@ -33,6 +36,7 @@ import java.util.List;
 public class ApiShopController {
 
     private final IShopService iShopService;
+    private final IFacilityService iFacilityService;
 
     @PostMapping("/add")
     @ApiOperationSupport(order = 1)
@@ -94,4 +98,14 @@ public class ApiShopController {
         }
         return R.data(shopVOS);
     }
+
+    @GetMapping("/getByDeviceId")
+    @ApiOperationSupport(order = 3)
+    @ApiOperation(value = "根据设备id查询门店信息", notes = "经度纬度")
+    public R<ShopVO> getByDeviceId(@ApiParam(value = "经度", required = true) @RequestParam Long deviceId) {
+        Facility facility = iFacilityService.getById(deviceId);
+        Assert.notNull(facility, "未找到设备信息");
+        Shop shop = iShopService.getById(facility.getShopId());
+        return R.data(ShopWrapper.build().entityVO(shop));
+    }
 }

+ 34 - 0
src/main/java/org/springblade/modules/api/request/AddChildAccountRequest.java

@@ -0,0 +1,34 @@
+package org.springblade.modules.api.request;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class AddChildAccountRequest {
+    @NotBlank(message = "手机号不能为空")
+    @ApiModelProperty(value = "手机号")
+    private String phone;
+    @ApiModelProperty(value = "昵称")
+    private String nickname;
+    @ApiModelProperty(value = "姓名")
+    private String realName;
+    @ApiModelProperty(value = "头像")
+    private String cover;
+    @ApiModelProperty(value = "密码")
+    private String password;
+    @ApiModelProperty(value = "确认密码")
+    private String rePassword;
+    @NotBlank(message = "授权门店不能为空")
+    @ApiModelProperty(value = "授权门店id集合,以逗号分隔")
+    private String authShopIds;
+
+    public String getPassword() {
+        return password == null ? "123456" : password;
+    }
+
+    public String getRePassword() {
+        return rePassword == null ? "123456" : rePassword;
+    }
+}

+ 5 - 0
src/main/java/org/springblade/modules/system/entity/UserMerchant.java

@@ -75,6 +75,11 @@ public class UserMerchant implements Serializable {
 	*/
 	@ApiModelProperty(value = "授权菜单")
 	private String authMenu;
+	/**
+	 * 授权菜单
+	 */
+	@ApiModelProperty(value = "授权门店")
+	private String authShop;
 	/**
 	 * 审核状态 1-已审核 0-待审核
 	 */

+ 5 - 1
src/main/java/org/springblade/modules/system/mapper/UserMerchantMapper.xml

@@ -21,7 +21,8 @@
             u.phone,
             u.real_name,
             u.`name`,
-            u.account
+            u.account,
+            m.id childAccountId
         FROM
             blade_user_merchant m
                 JOIN blade_user u ON m.user_id = u.id
@@ -32,6 +33,9 @@
         <if test="p.auditStatus != null">
             AND m.audit_status = #{p.auditStatus}
         </if>
+        <if test="p.parentId != null">
+            AND m.parent_id = #{p.parentId}
+        </if>
     </select>
 
 

+ 4 - 0
src/main/java/org/springblade/modules/system/vo/UserMerchantVO.java

@@ -49,4 +49,8 @@ public class UserMerchantVO extends UserMerchant {
 	 * 手机
 	 */
 	private String phone;
+	/**
+	 * 子账号id
+	 */
+	private Long childAccountId;
 }