diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountController.java index fac9296b..972975f1 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountController.java @@ -28,38 +28,28 @@ import java.util.Map; @RequestMapping("/admin/account/accountController") public class AccountController { - @Autowired - private AccountUserBaseService accountUserBaseService; - + private static final Logger logger = LoggerFactory.getLogger(AccountController.class); @Autowired AccountUserAnalyticsService accountUserAnalyticsService; - + @Autowired + private AccountUserBaseService accountUserBaseService; @Autowired private AccountUserLoginService accountUserLoginService; - @Autowired private AccountUserInfoService accountUserInfoService; - @Autowired private AccountBaseUserLevelService accountBaseUserLevelService; - @Autowired private AccountBaseRoleLevelService accountBaseRoleLevelService; - @Autowired private AccountUserSnsService accountUserSnsService; - @Autowired private AccountUserBindConnectService accountUserBindConnectService; - @Autowired private AccountUserChainService accountUserChainService; - @Autowired private AccountUserTypeService accountUserTypeService; - private static final Logger logger = LoggerFactory.getLogger(AccountController.class); - @ApiOperation(value = "用户基本信息", notes = "用户基本信息") @RequestMapping(value = "/getUserBase", method = RequestMethod.GET) public AccountUserBase getUserBase(@RequestParam(name = "user_id") Integer user_id) { @@ -211,8 +201,9 @@ public class AccountController { @ApiOperation(value = "用户SNS信息", notes = "用户SNS信息") @RequestMapping(value = "/getBind", method = RequestMethod.GET) public Map getBind(@RequestParam(name = "user_id") Integer user_id, - @RequestParam(name = "bind_type") Integer bind_type) { - return accountUserBindConnectService.getBind(user_id, bind_type); + @RequestParam(name = "bind_type") Integer bind_type, + @RequestParam(name = "user_type", defaultValue = "0") Integer user_type) { + return accountUserBindConnectService.getBind(user_id, bind_type, user_type); } @RequestMapping(value = "/getUserInfoAndBase", method = RequestMethod.GET) diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java index e9e2ddcb..99c100c4 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java @@ -76,5 +76,14 @@ public class AccountUserBindConnectController { return CommonResult.success(flag); } + + @ApiOperation(value = "获取绑定关系的用户Id", notes = "根据 bind_id 和 bind_type user_type 获取绑定关系的用户Id(仅供内部调用)") + @RequestMapping(value = "/get-userid-by-condition", method = RequestMethod.POST) + public Integer getUserBindConnectUserIdByCondition(@RequestParam(name = "bind_id") String bind_id, + @RequestParam(name = "bind_type") Integer bind_type, + @RequestParam(name = "user_type", required = false) Integer user_type) { + return accountUserBindConnectService.getUserBindConnectUserIdByCondition(bind_id, bind_type, user_type); + } + } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java index cfac1a14..585922e7 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java @@ -20,23 +20,25 @@ public interface AccountUserBindConnectService extends IBaseService args = new HashMap<>(); args.put("user_account", user_nickname); @@ -2223,6 +2227,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl userInfo = new HashMap<>(); userInfo.put("user_account", com.suisung.mall.common.utils.StringUtils.genLklOrderNo(4));// 时间 yyyyMMddHHmmss + 4位随机数 userInfo.put("user_mobile", user_mobile); + userInfo.put("user_is_admin", CommonConstant.USER_TYPE_MCH); // 商家入驻注册 // userInfo.put("verify_code", verifyCode); // 密码要随机数 String user_password = com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING); @@ -2866,6 +2882,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_id", user_id) - .eq("bind_active", CommonConstant.Enable) - .eq("bind_type", bind_type); + queryWrapper.eq("user_id", user_id).eq("bind_type", bind_type) + .eq("user_type", user_type) + .eq("bind_active", CommonConstant.Enable); + return findOne(queryWrapper); } @@ -67,45 +72,51 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("bind_id", bind_id) - .eq("bind_active", CommonConstant.Enable) - .eq("bind_type", bind_type); + .eq("bind_type", bind_type) + .eq("user_type", user_type) + .eq("bind_active", CommonConstant.Enable); return findOne(queryWrapper); } @Override - public boolean checkBind(String bind_id, int bind_type, Integer user_id, AccountUserBindConnect user_info_row) { + public boolean checkBind(String bind_id, int bind_type, Integer user_id, Integer user_type, AccountUserBindConnect user_info_row) { - AccountUserBindConnect bind_row = get(bind_id); - if (bind_row != null && CheckUtil.isNotEmpty(bind_row.getUser_id())) { + AccountUserBindConnect currAccountUserBindConnect = get(bind_id); + if (currAccountUserBindConnect != null && CheckUtil.isNotEmpty(currAccountUserBindConnect.getUser_id())) { // 验证通过, 登录成功. - Integer bind_user_id = bind_row.getUser_id(); + Integer bind_user_id = currAccountUserBindConnect.getUser_id(); if (CheckUtil.isNotEmpty(user_id) && ObjectUtil.equal(user_id, bind_user_id)) { throw new ApiException(I18nUtil._("非法请求,已经登录用户不应该访问到此页面-重复绑定")); } else if (CheckUtil.isEmpty(user_id) && ObjectUtil.equal(user_id, bind_user_id)) { throw new ApiException(I18nUtil._("非法请求,错误绑定数据")); } - } else if (bind_row != null && CheckUtil.isEmpty(bind_row.getUser_id())) { + } else if (currAccountUserBindConnect != null && CheckUtil.isEmpty(currAccountUserBindConnect.getUser_id())) { user_info_row.setUser_id(user_id); user_info_row.setBind_id(bind_id); + user_info_row.setUser_type(user_type); + // (重要)新增或更新用户绑定关系 if (!saveOrUpdate(user_info_row)) { throw new ApiException(ResultCode.FAILED); } - } else if (bind_row == null) { + } else if (currAccountUserBindConnect == null) { // todo 头像会变动, 需要本地缓存, 生成新网址. user_info_row.setBind_id(bind_id); user_info_row.setBind_type(bind_type); user_info_row.setUser_id(user_id); + user_info_row.setUser_type(user_type); + // (重要)新增或更新用户绑定关系 if (!saveOrUpdate(user_info_row)) { throw new ApiException(ResultCode.FAILED); } @@ -183,92 +194,110 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("bind_unionid", user_info_row.getBind_unionid()); - AccountUserBindConnect find_bind_row = findOne(queryWrapper); - if (find_bind_row != null) { - user_base_row = accountUserBaseService.get(find_bind_row.getUser_id()); + //根据unionId,判断已经绑定的用户 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("bind_unionid", accountUserBindConnect.getBind_unionid()); + AccountUserBindConnect find_bind_row = findOne(queryWrapper); + if (find_bind_row != null) { + accountUserBase = accountUserBaseService.get(find_bind_row.getUser_id()); - //运行到此处 - //判断bind openid是否存在,不存在则需要添加 - //支付地方需要调用到openid, 此处必须冗余存放openid - AccountUserBindConnect open_bind_row = get(bind_id); + //运行到此处 + //判断bind openid是否存在,不存在则需要添加 + //支付地方需要调用到openid, 此处必须冗余存放openid + AccountUserBindConnect open_bind_row = get(bind_id); + if (null == open_bind_row) { + accountUserBindConnect.setBind_active(CommonConstant.Enable); + accountUserBindConnect.setBind_type(accountUserBindConnect.getBind_type()); + save(accountUserBindConnect); + } - if (null == open_bind_row) { - user_info_row.setBind_active(1); - user_info_row.setBind_type(user_info_row.getBind_type()); - save(user_info_row); - } - AccountUserBase accountUserBase = accountUserBaseService.get(find_bind_row.getUser_id()); - if (accountUserBase != null) { - user_id = accountUserBase.getUser_id(); - AccountUserBindConnect userBindConnect = new AccountUserBindConnect(); - userBindConnect.setBind_id(bind_id); - userBindConnect.setUser_id(user_id); - edit(userBindConnect); - return user_id; - } + AccountUserBase updAccountUserBase = accountUserBaseService.get(find_bind_row.getUser_id()); + if (updAccountUserBase != null) { + user_id = updAccountUserBase.getUser_id(); + AccountUserBindConnect userBindConnect = new AccountUserBindConnect(); + userBindConnect.setBind_id(bind_id); + userBindConnect.setUser_id(user_id); + edit(userBindConnect); + return user_id; } } - } else { - //throw new Exception(__('unionId 不存在')); } //自动注册用户 - if (user_base_row != null) { - user_id = user_base_row.getUser_id(); + if (accountUserBase != null) { + user_id = accountUserBase.getUser_id(); } else { - boolean flag = false; + //需要注册用户 - if (reg_flag) { + if (needRegNow) { Map reg_info = new HashMap(); reg_info.put("user_account", bind_id); reg_info.put("user_password", "Ss@123" + UUID.randomUUID()); - reg_info.put("user_nickname", user_info_row.getBind_nickname()); + reg_info.put("user_nickname", accountUserBindConnect.getBind_nickname()); reg_info.put("activity_id", activity_id); - user_base_row = accountUserBaseService.register(reg_info); + accountUserBase = accountUserBaseService.register(reg_info); - if (user_base_row != null) { - user_id = user_base_row.getUser_id(); + if (accountUserBase != null) { + user_id = accountUserBase.getUser_id(); //添加user info Map info = new HashMap(); - info.put("user_nickname", user_info_row.getBind_nickname());// 名称 - info.put("user_avatar", user_info_row.getBind_icon()); - info.put("user_gender", user_info_row.getBind_gender()); // 性别 1:男 2:女 + info.put("user_nickname", accountUserBindConnect.getBind_nickname());// 名称 + info.put("user_avatar", accountUserBindConnect.getBind_icon()); + info.put("user_gender", accountUserBindConnect.getBind_gender()); // 性别 1:男 2:女 - /* - if ($qy_userid) - { - $info['user_level_id'] = 1006 ; // 性别 1:男 2:女 - $info['user_notename'] = $qy_userid ; // - } - */ - - flag = accountUserInfoService.editAccount(user_id, info); - flag = checkBind(bind_id, user_info_row.getBind_type(), user_id, user_info_row); + accountUserInfoService.editAccount(user_id, info); + checkBind(bind_id, accountUserBindConnect.getBind_type(), user_id, accountUserBindConnect.getUser_type(), accountUserBindConnect); } } else { //读取用户信息 - user_id = user_info_row.getUser_id(); - flag = checkBind(bind_id, user_info_row.getBind_type(), user_id, user_info_row); + user_id = accountUserBindConnect.getUser_id(); + checkBind(bind_id, accountUserBindConnect.getBind_type(), user_id, accountUserBindConnect.getUser_type(), accountUserBindConnect); } } return user_id; } + + /** + * 根据 bind_id 和 bind_type user_type 获取绑定关系的 user_id + * + * @param bindId 必填 + * @param bindType + * @param userType + * @return + */ + @Override + public Integer getUserBindConnectUserIdByCondition(String bindId, Integer bindType, Integer userType) { + if (bindId == null) { + return null; + } + if (BindCode.MOBILE == bindType) { + // 加上 +86 中国区域号 + bindId = PhoneNumberUtils.convZhPhoneNumber(bindId); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("bind_id", bindId).eq("bind_type", bindType); + if (userType != null) { + queryWrapper.eq("user_type", userType); + } + + queryWrapper.select("user_id").orderByAsc("user_id"); + + AccountUserBindConnect accountUserBindConnect = findOne(queryWrapper); + return accountUserBindConnect != null ? accountUserBindConnect.getUser_id() : null; + + } } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/impl/WeiXinServiceImpl.java b/mall-account/src/main/java/com/suisung/mall/account/service/impl/WeiXinServiceImpl.java index 2f2d71d0..1128a80c 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/impl/WeiXinServiceImpl.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/impl/WeiXinServiceImpl.java @@ -340,7 +340,7 @@ public class WeiXinServiceImpl implements WeiXinService { UserDto userDto = JSONUtil.toBean(jwsObject.getPayload().toString(), UserDto.class); Integer rid = userDto.getRole_id(); Map userInfo = accountUserBaseService.getUserInfo(userDto.getId()); - Map bind = accountUserBindConnectService.getBind(user_id, BindCode.MOBILE); + Map bind = accountUserBindConnectService.getBind(user_id, BindCode.MOBILE, userDto.getUserType()); userInfo.put("id", user_id); userInfo.put("k", wxUserToken); userInfo.put("key", wxUserToken); @@ -481,7 +481,7 @@ public class WeiXinServiceImpl implements WeiXinService { public Map getOpenIdByCode(String code, UserDto user) { Map data = new HashMap(); if (user != null && CheckUtil.isNotEmpty(user.getId())) { - Map bind_row = accountUserBindConnectService.getBind(user.getId(), BindCode.WEIXIN_XCX); + Map bind_row = accountUserBindConnectService.getBind(user.getId(), BindCode.WEIXIN_XCX, user.getUserType()); if (CollUtil.isNotEmpty(bind_row) && StrUtil.isNotBlank(Convert.toStr(bind_row.get("bind_openid")))) { data.put("openid", bind_row.get("bind_openid")); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java b/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java index 291b1090..fec451e9 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java +++ b/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java @@ -20,7 +20,7 @@ public class CommonConstant { public static final Integer Delivery_Amount_Comput_Type_Payment = 3; /** - * 用户类型:0-普通用户;1-管理员;2-商户 + * 用户类型:0-普通用户;1-管理员;2-入驻商户 */ public static final Integer USER_TYPE_NORMAL = 0; public static final Integer USER_TYPE_ADMIN = 1; diff --git a/mall-common/src/main/java/com/suisung/mall/common/domain/UserDto.java b/mall-common/src/main/java/com/suisung/mall/common/domain/UserDto.java index 8945da1a..b8e683fc 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/domain/UserDto.java +++ b/mall-common/src/main/java/com/suisung/mall/common/domain/UserDto.java @@ -3,6 +3,7 @@ package com.suisung.mall.common.domain; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.suisung.mall.common.constant.AuthConstant; +import com.suisung.mall.common.constant.CommonConstant; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -87,4 +88,20 @@ public class UserDto { public boolean isMerchant() { return ObjectUtil.equal(client_id, AuthConstant.MCH_CLIENT_ID); } + + /** + * 获取用户类型:对应user_base 的 is_admin:0-普通用户;1-管理员;2-入驻商家; + * + * @return + */ + public Integer getUserType() { + Integer user_type = CommonConstant.USER_TYPE_NORMAL; // 用户类型,对应user_base 的 is_admin:0-普通用户;1-管理员;2-入驻商家; + if (isAdmin()) { + user_type = CommonConstant.USER_TYPE_ADMIN; + } else if (isMerchant()) { + user_type = CommonConstant.USER_TYPE_MCH; + } + + return user_type; + } } diff --git a/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java b/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java index 5bb66d81..379cfc0b 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java +++ b/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java @@ -3,6 +3,7 @@ package com.suisung.mall.common.feignService; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.modules.account.*; import com.suisung.mall.common.pojo.output.TimelineOutput; +import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; @@ -136,6 +137,7 @@ public interface AccountService { /** * 判断一个店铺是否存在某个昵称的会员 + * * @param nickname * @param storeId * @return @@ -207,4 +209,10 @@ public interface AccountService { @GetMapping("/admin/account/analytics/user/getUserTimeLineInfo") List getUserTimeLine(@RequestParam("startTime") Long startTime, @RequestParam("endTime") Long endTime); + + @ApiOperation(value = "获取绑定关系的用户Id", notes = "根据 bind_id 和 bind_type user_type 获取绑定关系的用户Id(仅供内部调用)") + @PostMapping(value = "/admin/account/account-user-bind-connect/get-userid-by-condition") + Integer getUserBindConnectUserIdByCondition(@RequestParam(name = "bind_id") String bind_id, + @RequestParam(name = "bind_type") Integer bind_type, + @RequestParam(name = "user_type", required = false) Integer user_type); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/account/AccountUserBindConnect.java b/mall-common/src/main/java/com/suisung/mall/common/modules/account/AccountUserBindConnect.java index 5a085566..62e4eba3 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/account/AccountUserBindConnect.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/account/AccountUserBindConnect.java @@ -33,12 +33,15 @@ public class AccountUserBindConnect implements Serializable { @TableId(value = "bind_id", type = IdType.INPUT) private String bind_id; - @ApiModelProperty(value = "绑定类型(EMUN):1-mobile; 2-email; 11-sinaweibo; 12-qq; 13-weixin") + @ApiModelProperty(value = "绑定类型(EMUN):1-手机号; 2-邮箱; 11-新浪微博; 12-QQ; 13-微信;14-微信公众号;15-微信小程序;16-企业微信;17-苹果;18-支付宝;19-facebook;20-谷歌;21-建行用户;") private Integer bind_type; @ApiModelProperty(value = "用户编号") private Integer user_id; + @ApiModelProperty(value = "用户类型,对应user_base 的 is_admin:0-普通用户;1-管理员;2-入驻商家;") + private Integer user_type; + @ApiModelProperty(value = "绑定时间") private Date bind_time; diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseDistrictService.java b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseDistrictService.java index 5e780edd..ce71b5fc 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseDistrictService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseDistrictService.java @@ -35,4 +35,25 @@ public interface ShopBaseDistrictService extends IBaseService List getDistrictByParentId(Integer district_parent_id, boolean recursive, Integer district_level); + /** + * 根据省或市或区编号获取完整关联省市区列表 + * + * @param districtCode + * @return 关联省市区列表 + */ + List getFullDistrictByDistrictCode(String districtCode); + + + /** + * 把一个三个有序的关联省市区列表,拼接名字或者拼接id,输出字符串 + * 如:广东省/深圳市/南山区 440000/440300/440306 + * + * @param list + * @param joinKey + * @param hasSeparator + * @param separator + * @return + */ + String joinDistrict(List list, Integer joinKey, Boolean hasSeparator, String separator); + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/impl/ShopBaseDistrictServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/impl/ShopBaseDistrictServiceImpl.java index 46596243..833187ae 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/impl/ShopBaseDistrictServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/impl/ShopBaseDistrictServiceImpl.java @@ -20,9 +20,7 @@ import org.springframework.util.FileCopyUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; /** *

@@ -35,14 +33,12 @@ import java.util.Map; @Service public class ShopBaseDistrictServiceImpl extends BaseServiceImpl implements ShopBaseDistrictService { + private static JSON districtData; @Autowired private AccountBaseConfigService accountBaseConfigService; - @Autowired private ShopBaseDistrictMapper shopBaseDistrictMapper; - private static JSON districtData; - @Override public Integer getDefaultDistrictId() { Integer district_id = null; @@ -169,6 +165,147 @@ public class ShopBaseDistrictServiceImpl extends BaseServiceImpl getFullDistrictByDistrictCode(String districtCode) { + if (StrUtil.isBlank(districtCode)) { + return Collections.emptyList(); + } + + List districtList = new LinkedList<>(); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_id", districtCode); + ShopBaseDistrict district = findOne(queryWrapper); + if (ObjectUtil.isEmpty(district)) { + return Collections.emptyList(); + } + + if (ObjectUtil.equals(district.getDistrict_level(), 3)) { + // 如果是第三级 + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_id", district.getDistrict_parent_id()); + ShopBaseDistrict districtSecond = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtSecond)) { + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_id", districtSecond.getDistrict_parent_id()); + ShopBaseDistrict districtFirst = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtFirst)) { + // 1st + districtList.add(districtFirst); + } + //2nd + districtList.add(districtSecond); + } + + //3rd + districtList.add(district); + } else if (ObjectUtil.equals(district.getDistrict_level(), 2)) { + // 如果是第二级 + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_id", district.getDistrict_parent_id()); + ShopBaseDistrict districtFirst = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtFirst)) { + // 1st + districtList.add(districtFirst); + } + + //2nd + districtList.add(district); + + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_parent_id", district.getDistrict_id()); + ShopBaseDistrict districtThird = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtThird)) { + // 3rd + districtList.add(districtThird); + } + } else if (ObjectUtil.equals(district.getDistrict_level(), 1)) { + districtList.add(district); + + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_parent_id", district.getDistrict_id()); + ShopBaseDistrict districtSecond = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtSecond)) { + districtList.add(districtSecond); + + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("district_parent_id", districtSecond.getDistrict_id()); + ShopBaseDistrict districtThird = findOne(queryWrapper); + if (ObjectUtil.isNotEmpty(districtThird)) { + districtList.add(districtThird); + } + } + } + + return districtList; + } + + /** + * 把一个三个有序的关联省市区列表,拼接名字或者拼接id,输出字符串 + * 如:广东省/深圳市/南山区 440000/440300/440306 + * + * @param list 有序列表 + * @param joinKey 1-id 2-name + * @param needSeparator 需要分割字符? + * @param separator 分割字符串 + * @return + */ + @Override + public String joinDistrict(List list, Integer joinKey, Boolean needSeparator, String separator) { + // 参数校验 + if (CollUtil.isEmpty(list)) { + return ""; + } + + if (separator == null) { + separator = ""; + } + + if (needSeparator == null) { + needSeparator = false; + } + + if (joinKey == null || (joinKey != 1 && joinKey != 2)) { + joinKey = 1; // 默认使用 id + } + + StringBuilder result = new StringBuilder(); + boolean first = true; + + for (ShopBaseDistrict district : list) { + if (district == null) { + continue; // 跳过空元素 + } + + String valueToJoin; + if (joinKey == 1) { + valueToJoin = district.getDistrict_id().toString(); // 使用 id + } else { + valueToJoin = district.getDistrict_name(); // 使用 name + } + + if (valueToJoin == null) { + valueToJoin = ""; // 处理空值 + } + + if (needSeparator && !first) { + result.append(separator); + } + + result.append(valueToJoin); + first = false; + } + + return result.toString(); + } + + /** * 读取子类id * diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopMerchEntryAdminController.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopMerchEntryAdminController.java index 3cc33e93..bdf640be 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopMerchEntryAdminController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopMerchEntryAdminController.java @@ -53,4 +53,6 @@ public class ShopMerchEntryAdminController extends BaseControllerImpl { // approvalStatus 入驻商家的审批状态:1-已通过;2-未通过;3-待审核; return shopMerchEntryService.shopMerchEntryApproval(jsonParam.getLong("id"), jsonParam.getInt("approvalStatus"), jsonParam.getStr("approvalRemark"), jsonParam.getStr("approvalInvalidCol")); } + + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopStoreBaseController.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopStoreBaseController.java index edfcb878..44393d0d 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopStoreBaseController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/admin/ShopStoreBaseController.java @@ -3,6 +3,7 @@ package com.suisung.mall.shop.store.controller.admin; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.domain.UserDto; @@ -17,6 +18,7 @@ import com.suisung.mall.shop.store.service.ShopStoreSameCityTransportBaseService import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; @@ -248,5 +250,15 @@ public class ShopStoreBaseController extends BaseControllerImpl { public ShopStoreBase getLklMerchantNoAndTermNo(@RequestParam(name = "store_id") Integer store_id) { return shopStoreBaseService.getLklMerchantNoAndTermNo(store_id); } + + @ApiOperation(value = "商家入驻资料转成店铺", notes = "商家入驻资料转成店铺") + @RequestMapping(value = "/mchinfo/to/storeinfo", method = RequestMethod.POST) + public CommonResult merchEntryInfo2StoreInfo(@RequestBody JSONObject jsonParam) { + Pair result = shopStoreBaseService.merchEntryInfo2StoreInfo(jsonParam.getStr("mchMobile")); + if (result.getFirst().equals(0)) { + return CommonResult.failed(result.getSecond()); + } + return CommonResult.success(); + } } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java index bc04c24a..59712064 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java @@ -142,5 +142,13 @@ public interface ShopStoreBaseService extends IBaseService { * @param mchMobile * @return 店铺Id */ - Integer merchEntryInfo2StoreInfo(String mchMobile); + Pair merchEntryInfo2StoreInfo(String mchMobile); + + /** + * 根据店铺名称判断店铺是否存在 + * + * @param storeName + * @return + */ + Boolean isExistsByStoreName(String storeName); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMerchEntryServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMerchEntryServiceImpl.java index ad70e588..4e766e28 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMerchEntryServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMerchEntryServiceImpl.java @@ -31,6 +31,7 @@ import com.suisung.mall.shop.esign.service.EsignPlatformInfoService; import com.suisung.mall.shop.message.service.ShopMessageTemplateService; import com.suisung.mall.shop.store.mapper.ShopMerchEntryMapper; import com.suisung.mall.shop.store.service.ShopMerchEntryService; +import com.suisung.mall.shop.store.service.ShopStoreBaseService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -66,6 +67,10 @@ public class ShopMerchEntryServiceImpl extends BaseServiceImpl isApplied = isApplied(record.getLogin_mobile(), record.getBiz_license_number()); if (isApplied.getFirst()) { @@ -270,6 +279,10 @@ public class ShopMerchEntryServiceImpl extends BaseServiceImpl merchEntryInfo2StoreInfo(String mchMobile) { Integer storeId = 0; if (StrUtil.isBlank(mchMobile)) { - logger.error("生成店铺:商家注册手机号为空"); - return storeId; + logger.error("生成店铺:商家手机号不能为空"); + return Pair.of(0, "商家手机号不能为空"); } - // 获取商家注册账号信息 - Integer userId = 0; + // 从绑定关系中,获取商家注册账号信息 + Integer userId = accountService.getUserBindConnectUserIdByCondition(mchMobile, BindCode.MOBILE, CommonConstant.USER_TYPE_MCH); + if (userId == null) { + logger.error("生成店铺:绑定关系中获取不到该手机{}商家的账号", mchMobile); + return Pair.of(0, "商家账号异常!"); + } ShopMerchEntry shopMerchEntry = shopMerchEntryService.getShopMerchEntryByCondition(mchMobile, "", CommonConstant.MCH_APPR_STA_PASS); if (ObjectUtil.isEmpty(shopMerchEntry)) { - logger.error("生成店铺:商家入驻信息为空"); - return storeId; + logger.error("生成店铺:入驻信息不能为空"); + return Pair.of(0, "入驻信息不能为空"); + } + + if (isExistsByStoreName(shopMerchEntry.getStore_name())) { + logger.error("生成店铺:店铺名称已存在"); + return Pair.of(0, "店铺名称已存在"); } // 新增 shop_store_base,shop_store_info,shop_store_company, shop_store_employee 待补充 + + String storeFacadeImage = shopMerchEntry.getFront_facade_image(); + + // shop_store_base ShopStoreBase shopStoreBase = new ShopStoreBase(); shopStoreBase.setUser_id(userId); // 店铺管理员用户Id shopStoreBase.setStore_name(shopMerchEntry.getStore_name()); + shopStoreBase.setStore_category_id(shopMerchEntry.getBiz_category()); + shopStoreBase.setStore_logo(storeFacadeImage); // 临时使用门面照片做logo + + // 省市区记录有序列表 + List districtList = shopBaseDistrictService.getFullDistrictByDistrictCode(shopMerchEntry.getCounty_id()); + shopStoreBase.setStore_district_id(shopBaseDistrictService.joinDistrict(districtList, 1, true, "/")); + shopStoreBase.setStore_area(shopBaseDistrictService.joinDistrict(districtList, 2, true, "/")); shopStoreBase.setStore_address(shopMerchEntry.getStore_address()); shopStoreBase.setStore_longitude(shopMerchEntry.getStore_longitude()); shopStoreBase.setStore_latitude(shopMerchEntry.getStore_latitude()); shopStoreBase.setStore_grade_id(1001); // 店铺等级,默认为普通店铺 - shopStoreBase.setStore_category_id(shopMerchEntry.getBiz_category()); shopStoreBase.setStore_type(1);//店铺类型(ENUM): 1-卖家店铺; 2-供应商店铺 - shopStoreBase.setStore_district_id(""); - shopStoreBase.setStore_area(""); shopStoreBase.setStore_is_open(1); shopStoreBase.setStore_is_selfsupport(0); shopStoreBase.setStore_o2o_flag(0); shopStoreBase.setSubsite_id(0); - shopStoreBase.setStore_state_id(3240);//店铺资料信息状态(ENUM):3210-待完善资料; 3220-等待审核 ; 3230-资料审核没有通过;3240-资料审核通过,待付款 + shopStoreBase.setStore_state_id(StateCode.STORE_STATE_YES);//店铺资料信息状态(ENUM):3210-待完善资料; 3220-等待审核 ; 3230-资料审核没有通过;3240-资料审核通过,待付款 shopStoreBase.setStore_time(DateUtil.date()); - shopStoreBase.setStore_end_time(0L); - + shopStoreBase.setStore_end_time(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365 * 5); // 5年 if (!save(shopStoreBase)) { logger.error("生成店铺:新增店铺基本信息失败"); - return storeId; +// return Pair.of(0, "新增店铺失败"); + throw new ApiException(I18nUtil._("新增店铺失败")); } // 保存后店铺Id storeId = shopStoreBase.getStore_id(); + // shop_store_info ShopStoreInfo shopStoreInfo = new ShopStoreInfo(); shopStoreInfo.setStore_id(storeId); shopStoreInfo.setStore_start_time(DateUtil.date()); - shopStoreInfo.setStore_end_time(DateUtil.offsetDay(DateUtil.date(), 365)); + shopStoreInfo.setStore_end_time(DateUtil.offsetDay(DateUtil.date(), 365 * 5)); shopStoreInfo.setStore_opening_hours("08:00"); shopStoreInfo.setStore_close_hours("22:00"); + shopStoreInfo.setStore_discount(BigDecimal.valueOf(10));// 原价 shopStoreInfo.setStore_tel(shopMerchEntry.getLogin_mobile()); - shopStoreInfo.setStore_address(shopMerchEntry.getStore_address()); - shopStoreInfoService.save(shopStoreInfo); + shopStoreInfo.setStore_banner(storeFacadeImage); - ShopStoreCompany shopStoreCompany = new ShopStoreCompany(); - shopStoreCompany.setStore_id(storeId); - shopStoreCompany.setCompany_name(shopMerchEntry.getBiz_license_company()); - shopStoreCompany.setCompany_address(shopMerchEntry.getStore_address()); - // 待补充 - shopStoreCompanyService.save(shopStoreCompany); + JSONArray list = new JSONArray(); + if (StrUtil.isNotBlank(storeFacadeImage)) { + JSONObject slide = new JSONObject(); + slide.put("img", storeFacadeImage); + slide.put("name", "店铺门面照片"); + slide.put("check", true); + slide.put("url", "https://www.gpsxcs.cn"); + list.put(slide); + } + if (StrUtil.isNotBlank(shopMerchEntry.getEnvironment_image())) { + JSONObject slide = new JSONObject(); + slide.put("img", shopMerchEntry.getEnvironment_image()); + slide.put("name", "店铺环境照片"); + slide.put("check", true); + slide.put("url", "https://www.gpsxcs.cn"); + list.put(slide); + } + shopStoreInfo.setStore_slide(list.toString()); + shopStoreInfo.setStore_address(shopMerchEntry.getStore_address()); // 包含省市区的详细地址 + shopStoreInfo.setStore_state_id(StateCode.STORE_STATE_YES); + if (!shopStoreInfoService.save(shopStoreInfo)) { + logger.error("生成店铺:新增店铺info失败"); + throw new ApiException(I18nUtil._("新增店铺失败")); + } - return storeId; + // 如果商家是企业,则保存商家公司信息 + if (CommonConstant.MCH_ENTITY_TYPE_QY.equals(shopMerchEntry.getEntity_type())) { + // shop_store_company + ShopStoreCompany shopStoreCompany = new ShopStoreCompany(); + shopStoreCompany.setUser_id(userId); + shopStoreCompany.setStore_id(storeId); + + // 公司名 + shopStoreCompany.setCompany_name(shopMerchEntry.getBiz_license_company()); + shopStoreCompany.setCompany_area(shopStoreBase.getStore_area()); + shopStoreCompany.setCompany_address(shopMerchEntry.getStore_address()); + + // 营业执照 + shopStoreCompany.setBusiness_id(shopMerchEntry.getBiz_license_number()); + shopStoreCompany.setBusiness_license_electronic(shopMerchEntry.getBiz_license_image()); + + // 企业法人 + shopStoreCompany.setLegal_person(shopMerchEntry.getLegal_person_name()); + shopStoreCompany.setLegal_person_number(shopMerchEntry.getLegal_person_id_number()); + shopStoreCompany.setLegal_person_electronic(shopMerchEntry.getLegal_person_id_images()); + + // 联系人 + shopStoreCompany.setContacts_name(shopMerchEntry.getContact_name()); + shopStoreCompany.setContacts_phone(shopMerchEntry.getLogin_mobile()); + + // 银行对公账号 + shopStoreCompany.setBank_account_name(shopMerchEntry.getAccount_holder_name()); + shopStoreCompany.setBank_account_number(shopMerchEntry.getAccount_number()); + shopStoreCompany.setBank_name(shopMerchEntry.getBank_name()); + + Date today = new Date(); + + shopStoreCompany.setOrganization_code_start(today); + shopStoreCompany.setOrganization_code_end(DateUtil.offsetDay(today, 365 * 5)); + shopStoreCompany.setEstablish_date(today); + shopStoreCompany.setBusiness_licence_start(today); + shopStoreCompany.setBusiness_licence_end(DateUtil.offsetDay(today, 365 * 5)); + + shopStoreCompany.setCompany_description(""); + shopStoreCompany.setStore_class_ids(""); + shopStoreCompany.setStore_class_names(""); + shopStoreCompany.setStore_class_commission(""); + + // 待补充 + if (!shopStoreCompanyService.save(shopStoreCompany)) { + logger.error("生成店铺:新增店铺公司失败"); + throw new ApiException(I18nUtil._("新增店铺公司失败")); + } + } + + // shop_store_employee 店铺员工,添加管理员 + ShopStoreEmployee shopStoreEmployee = new ShopStoreEmployee(); + shopStoreEmployee.setStore_id(storeId); + shopStoreEmployee.setUser_id(userId); + shopStoreEmployee.setRights_group_id("1"); // 店铺管理员 + shopStoreEmployee.setEmployee_is_admin(CommonConstant.Enable); + shopStoreEmployee.setEmployee_is_kefu(CommonConstant.Enable); + shopStoreEmployeeService.save(shopStoreEmployee); + if (!shopStoreEmployeeService.save(shopStoreEmployee)) { + logger.error("生成店铺:新增店铺员工失败"); + throw new ApiException(I18nUtil._("新增店铺员工失败")); + } + + return Pair.of(storeId, "新增成功"); + } + + /** + * 根据店铺名称判断店铺是否存在 + * + * @param storeName + * @return + */ + @Override + public Boolean isExistsByStoreName(String storeName) { + if (StrUtil.isBlank(storeName)) { + return true; + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("store_name", storeName); + + return count(queryWrapper) > 0; } /**