商家版注册与登录接口

This commit is contained in:
Jack 2025-02-25 11:34:44 +08:00
parent 6400672c49
commit f10674ecb1
11 changed files with 169 additions and 105 deletions

View File

@ -3,6 +3,7 @@ package com.suisung.mall.account.controller;
import cn.hutool.core.lang.Validator; import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.suisung.mall.account.service.AccountUserBaseService; import com.suisung.mall.account.service.AccountUserBaseService;
import com.suisung.mall.account.service.AccountUserInfoService; import com.suisung.mall.account.service.AccountUserInfoService;
import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.CommonResult;
@ -18,10 +19,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -179,10 +177,8 @@ public class LoginController extends BaseControllerImpl {
@ApiOperation(value = "商家版注册与登录") @ApiOperation(value = "商家版注册与登录")
@RequestMapping(value = "/doMerchSmsRegisterAndLogin", method = RequestMethod.POST) @RequestMapping(value = "/doMerchSmsRegisterAndLogin", method = RequestMethod.POST)
public CommonResult doMerchSmsRegisterAndLogin(@RequestParam(name = "user_mobile") String user_mobile, public CommonResult doMerchSmsRegisterAndLogin(@RequestBody JSONObject paramJSON) {
@RequestParam(name = "rand_key", required = false) String rand_key, return accountUserBaseService.doMerchSmsRegisterAndLogin(paramJSON.getStr("user_mobile"), paramJSON.getStr("rand_key"), paramJSON.getStr("verify_code"));
@RequestParam(name = "verify_code") String verify_code) {
return accountUserBaseService.doMerchSmsRegisterAndLogin(user_mobile, rand_key, verify_code);
} }
@ApiOperation("退出登录") @ApiOperation("退出登录")

View File

@ -55,35 +55,26 @@ import java.util.concurrent.ThreadPoolExecutor;
@RequestMapping("/mobile/account/user") @RequestMapping("/mobile/account/user")
public class UserController extends BaseControllerImpl { public class UserController extends BaseControllerImpl {
private final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired @Autowired
private AccountUserBaseService accountUserBaseService; private AccountUserBaseService accountUserBaseService;
@Autowired @Autowired
private AccountBaseRoleLevelService accountBaseRoleLevelService; private AccountBaseRoleLevelService accountBaseRoleLevelService;
@Autowired @Autowired
private AccountBaseUserLevelService accountBaseUserLevelService; private AccountBaseUserLevelService accountBaseUserLevelService;
@Autowired @Autowired
private PayService payService; private PayService payService;
@Autowired @Autowired
private ShopService shopService; private ShopService shopService;
@Autowired @Autowired
private AccountUserSnsService accountUserSnsService; private AccountUserSnsService accountUserSnsService;
@Autowired @Autowired
private AccountBaseConfigService accountBaseConfigService; private AccountBaseConfigService accountBaseConfigService;
@Autowired @Autowired
private AccountUserInfoService accountUserInfoService; private AccountUserInfoService accountUserInfoService;
@Autowired @Autowired
private ThreadPoolExecutor executor; private ThreadPoolExecutor executor;
private Logger logger = LoggerFactory.getLogger(UserController.class);
/** /**
* 用户基本信息管理界面 * 用户基本信息管理界面
* *
@ -283,9 +274,7 @@ public class UserController extends BaseControllerImpl {
if (!PhoneNumberUtils.isValidNumber(mobile)) { if (!PhoneNumberUtils.isValidNumber(mobile)) {
throw new ApiException(I18nUtil._("请输入正确的手机号!")); throw new ApiException(I18nUtil._("请输入正确的手机号!"));
} }
} } else if (StrUtil.isNotBlank(email) && !CheckUtil.isEmail(email)) {
else if (StrUtil.isNotBlank(email) && !CheckUtil.isEmail(email)) {
throw new ApiException(I18nUtil._("请输入正确邮箱格式!")); throw new ApiException(I18nUtil._("请输入正确邮箱格式!"));
} }

View File

@ -202,11 +202,15 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
data.put("callback_url", ""); data.put("callback_url", "");
if (params.get("is_merch") != null && params.get("is_merch").equals("1")) { if (StrUtil.isNotBlank(params.get("user_mobile"))
&& StrUtil.isNotBlank(params.get("is_merch"))
&& params.get("is_merch").equals("1")) {
// 商家版app显示申请入驻的状态 // 商家版app显示申请入驻的状态
data.put("is_merch", 1); data.put("is_merch", 1);
//入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请 //入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请
data.put("merch_approval_status", 4); Map<String, Object> params2 = new HashMap<>();
params2.put("user_mobile", params.get("user_mobile"));
data.put("merch_approval_status", shopService.shopMerchEntryApprovalStatus(params2));
} }
return restResult; return restResult;
@ -1792,15 +1796,18 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
throw new ApiException(ResultCode.FAILED); throw new ApiException(ResultCode.FAILED);
} }
} }
// 远程调用异常忽略掉
try {
// todo trigger // todo trigger
// User_Resource初始化 // User_Resource初始化
if (!payService.initUserPoints(user_id)) { if (!payService.initUserPoints(user_id)) {
throw new ApiException(ResultCode.FAILED); // throw new ApiException(ResultCode.FAILED);
} }
// 初始化用户经验表 // 初始化用户经验表
if (!accountUserInfoService.initUserExperience(user_id)) { if (!accountUserInfoService.initUserExperience(user_id)) {
throw new ApiException(ResultCode.FAILED); // throw new ApiException(ResultCode.FAILED);
} }
// 判断微信h5传递的活动id // 判断微信h5传递的活动id
@ -1829,6 +1836,9 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
shopService.updateCoupons(userParentId, activityId); shopService.updateCoupons(userParentId, activityId);
} }
} }
} catch (Exception e) {
logger.error("用户注册,远程初始化用户周边资料(积分,经验值等)时,发生异常", e);
}
//记录渠道来源 //记录渠道来源
String source_ucc_code = getSourceChannelCode(); String source_ucc_code = getSourceChannelCode();
@ -2667,7 +2677,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
throw new ApiException(_("缺少必要参数!")); throw new ApiException(_("缺少必要参数!"));
} }
if (!PhoneNumberUtils.isValidNumber(user_mobile)) { if (!PhoneNumberUtils.checkPhoneNumber(user_mobile)) {
throw new ApiException(_("请输入正确的手机号!")); throw new ApiException(_("请输入正确的手机号!"));
} }
@ -2679,10 +2689,16 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
throw new ApiException(_("请输入验证码!")); throw new ApiException(_("请输入验证码!"));
} }
// rmk 为什么随机数和手机号一致
if (ObjectUtil.notEqual(user_mobile, rand_key)) { if (ObjectUtil.notEqual(user_mobile, rand_key)) {
throw new ApiException(_("非法数据,或者提交超时,请刷新页面重新提交!")); throw new ApiException(_("非法数据,或者提交超时,请刷新页面重新提交!"));
} }
String verifyMobile = PhoneNumberUtils.convZhPhoneNumber(user_mobile);
if (!checkVerifyCode(verifyMobile, verify_code)) {
throw new ApiException(_("验证码错误!"));
}
// 找出手机对应的绑定用户 // 找出手机对应的绑定用户
// 是否为手机号注册密码6位随机数 // 是否为手机号注册密码6位随机数
return doMobileBindLogin(user_mobile, true); return doMobileBindLogin(user_mobile, true);
@ -2738,15 +2754,15 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
} }
if (ObjectUtil.notEqual(CommonConstant.USER_TYPE_MCH, accountUserBase.getUser_is_admin())) { if (ObjectUtil.notEqual(CommonConstant.USER_TYPE_MCH, accountUserBase.getUser_is_admin())) {
// 不是入驻商家的情况 // 不是入驻商家的情况,已经有普通用户使用了手机号了提示已经被注册
throw new ApiException(_("已被注册,请换一个手机号码!")); throw new ApiException(_("已被注册,请换一个手机号码!"));
} }
} } else {
// 手机号码未绑定的情况直接去注册一个账号 // 手机号码未绑定的情况直接去注册一个账号
Map<String, Object> userInfo = new HashMap<>(); Map<String, Object> userInfo = new HashMap<>();
userInfo.put("user_account", com.suisung.mall.common.utils.StringUtils.genLklOrderNo(4));// 时间 yyyyMMddHHmmss + 4位随机数 userInfo.put("user_account", com.suisung.mall.common.utils.StringUtils.genLklOrderNo(4));// 时间 yyyyMMddHHmmss + 4位随机数
userInfo.put("user_mobile", user_mobile); userInfo.put("user_mobile", user_mobile);
// userInfo.put("verify_code", verifyCode);
// 密码要随机数 // 密码要随机数
String user_password = com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING); String user_password = com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING);
userInfo.put("user_password", user_password); userInfo.put("user_password", user_password);
@ -2759,7 +2775,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
} }
// TODO 发送短信通知用户告知用户随机密码尊敬的商家用户你们刚注册账号的账号密码为" + user_password + "请妥善保管以免丢失 // TODO 发送短信通知用户告知用户随机密码尊敬的商家用户你们刚注册账号的账号密码为" + user_password + "请妥善保管以免丢失
}
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("client_id", isMerch ? AuthConstant.MCH_CLIENT_ID : AuthConstant.MOBILE_CLIENT_ID); params.put("client_id", isMerch ? AuthConstant.MCH_CLIENT_ID : AuthConstant.MOBILE_CLIENT_ID);
@ -2768,6 +2784,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
params.put("verify_pwd", "1001"); // 是否验证密码 1001不验证1002验证内部登录没有用户明文密码只能不验证 params.put("verify_pwd", "1001"); // 是否验证密码 1001不验证1002验证内部登录没有用户明文密码只能不验证
params.put("username", accountUserBase.getUser_account()); params.put("username", accountUserBase.getUser_account());
params.put("password", ""); params.put("password", "");
params.put("user_mobile", user_mobile);
params.put("is_merch", "1"); // 是否为商家入驻 1-其他- params.put("is_merch", "1"); // 是否为商家入驻 1-其他-
return login(params); return login(params);

View File

@ -59,7 +59,15 @@ public class Oauth2ServerConfig extends AuthorizationServerConfigurerAdapter {
.scopes("all") .scopes("all")
.authorizedGrantTypes("password", "refresh_token") .authorizedGrantTypes("password", "refresh_token")
.accessTokenValiditySeconds(AuthConstant.ACCESS_TOKEN_VALIDITY_SECONDS) .accessTokenValiditySeconds(AuthConstant.ACCESS_TOKEN_VALIDITY_SECONDS)
.refreshTokenValiditySeconds(AuthConstant.REFRESH_TOKEN_VALIDITY_SECONDS); .refreshTokenValiditySeconds(AuthConstant.REFRESH_TOKEN_VALIDITY_SECONDS)
.and()
.withClient(AuthConstant.MCH_CLIENT_ID)// 商家端登录标记
.secret(passwordEncoder.encode(AuthConstant.AUTHORITY_MOBILE_SECRET))
.scopes("all")
.authorizedGrantTypes("password", "refresh_token")
.accessTokenValiditySeconds(AuthConstant.ACCESS_TOKEN_VALIDITY_SECONDS)
.refreshTokenValiditySeconds(AuthConstant.REFRESH_TOKEN_VALIDITY_SECONDS)
;
} }
// 用来配置授权以及令牌的访问端点和令牌服务; // 用来配置授权以及令牌的访问端点和令牌服务;

View File

@ -113,7 +113,7 @@ public interface PayService {
long getNumWithdraw(@RequestBody Map wrapper); long getNumWithdraw(@RequestBody Map wrapper);
@PostMapping(value = "/admin/pay/payController/initUserPoints") @PostMapping(value = "/admin/pay/payController/initUserPoints")
boolean initUserPoints(@RequestParam(name = "user_id") Integer user_id); Boolean initUserPoints(@RequestParam(name = "user_id") Integer user_id);
@PostMapping(value = "/admin/pay/payController/getPayPlantformResource") @PostMapping(value = "/admin/pay/payController/getPayPlantformResource")
PayPlantformResource getPayPlantformResource(@RequestParam(name = "plantform_resource_id") Integer plantform_resource_id); PayPlantformResource getPayPlantformResource(@RequestParam(name = "plantform_resource_id") Integer plantform_resource_id);

View File

@ -234,6 +234,7 @@ public interface ShopService {
/** /**
* 获取店铺的拉卡拉商户号和终端号仅仅两个字段 * 获取店铺的拉卡拉商户号和终端号仅仅两个字段
*
* @param store_id * @param store_id
* @return * @return
*/ */
@ -270,5 +271,14 @@ public interface ShopService {
@GetMapping(value = "/admin/shop/shopController/getWaitPayNum") @GetMapping(value = "/admin/shop/shopController/getWaitPayNum")
Long getWaitPayNum(@RequestParam(name = "user_id") Integer user_id); Long getWaitPayNum(@RequestParam(name = "user_id") Integer user_id);
/**
* 通过手机号mobile获取商家入驻审核状态
*
* @param params
* @return
*/
@PostMapping(value = "/mobile/shop/merch/approval/status")
Long shopMerchEntryApprovalStatus(@RequestBody Map<String, Object> params);
} }

View File

@ -1,11 +1,13 @@
package com.suisung.mall.common.utils.phone; package com.suisung.mall.common.utils.phone;
import cn.hutool.core.util.StrUtil;
import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper; import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber; import com.google.i18n.phonenumbers.Phonenumber;
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import com.suisung.mall.common.constant.CommonConstant;
import java.util.Locale; import java.util.Locale;
@ -47,6 +49,16 @@ public class PhoneNumberUtils {
return checkPhoneNumber(COUNTRY_CODE_CHINA, phoneNumber); return checkPhoneNumber(COUNTRY_CODE_CHINA, phoneNumber);
} }
/**
* 如果手机号码不带国家码转换中国大陆区号86的手机号码
*
* @param phoneNumber
* @return
*/
public static String convZhPhoneNumber(String phoneNumber) {
return StrUtil.startWith(phoneNumber, "+") ? phoneNumber : CommonConstant.IDD_ZH_CN + phoneNumber;
}
/** /**
* 判断手机号是否有效国际 * 判断手机号是否有效国际
* *

View File

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.order.ShopOrderReturn; import com.suisung.mall.common.modules.order.ShopOrderReturn;
import com.suisung.mall.common.modules.pay.*; import com.suisung.mall.common.modules.pay.*;
import com.suisung.mall.common.utils.CheckUtil;
import com.suisung.mall.common.utils.MybatisPlusQueryUtil; import com.suisung.mall.common.utils.MybatisPlusQueryUtil;
import com.suisung.mall.pay.service.*; import com.suisung.mall.pay.service.*;
import io.seata.core.context.RootContext; import io.seata.core.context.RootContext;
@ -37,35 +36,26 @@ import java.util.Map;
@RequestMapping("/admin/pay/payController") @RequestMapping("/admin/pay/payController")
public class PayController { public class PayController {
private final Logger logger = LoggerFactory.getLogger(PayController.class);
@Autowired @Autowired
private PayUserResourceService payUserResourceService; private PayUserResourceService payUserResourceService;
@Autowired @Autowired
private PayConsumeDepositService payConsumeDepositService; private PayConsumeDepositService payConsumeDepositService;
@Autowired @Autowired
private PayPaymentChannelService payPaymentChannelService; private PayPaymentChannelService payPaymentChannelService;
@Autowired @Autowired
private PayUserBankCardService payUserBankCardService; private PayUserBankCardService payUserBankCardService;
@Autowired @Autowired
private PayConsumeWithdrawService payConsumeWithdrawService; private PayConsumeWithdrawService payConsumeWithdrawService;
@Autowired @Autowired
private PayConsumeTradeService payConsumeTradeService; private PayConsumeTradeService payConsumeTradeService;
@Autowired @Autowired
private PayConsumeRecordService payConsumeRecordService; private PayConsumeRecordService payConsumeRecordService;
@Autowired @Autowired
private PayPlantformResourceService payPlantformResourceService; private PayPlantformResourceService payPlantformResourceService;
@Autowired @Autowired
private PayUserPayService payUserPayService; private PayUserPayService payUserPayService;
private Logger logger = LoggerFactory.getLogger(PayController.class);
@ApiOperation(value = "根据user_id 删除门店顾客关系数据", notes = "根据user_id 删除门店顾客关系数据") @ApiOperation(value = "根据user_id 删除门店顾客关系数据", notes = "根据user_id 删除门店顾客关系数据")
@RequestMapping(value = "/deleteUserChainByUid", method = RequestMethod.POST) @RequestMapping(value = "/deleteUserChainByUid", method = RequestMethod.POST)
@GlobalTransactional @GlobalTransactional
@ -311,8 +301,8 @@ public class PayController {
@GlobalTransactional @GlobalTransactional
@ApiOperation(value = "初始化用户积分表", notes = "初始化用户积分表") @ApiOperation(value = "初始化用户积分表", notes = "初始化用户积分表")
@RequestMapping(value = "/initUserPoints", method = RequestMethod.POST) @RequestMapping(value = "/initUserPoints", method = RequestMethod.POST)
public boolean initUserPoints(@RequestParam(name = "user_id") Integer user_id) { public Boolean initUserPoints(@RequestParam(name = "user_id") Integer user_id) {
boolean flag = false; Boolean flag = false;
try { try {
flag = payUserResourceService.initUserPoints(user_id); flag = payUserResourceService.initUserPoints(user_id);
} catch (Exception e) { } catch (Exception e) {
@ -320,8 +310,10 @@ public class PayController {
GlobalTransactionContext.reload(RootContext.getXID()).rollback(); GlobalTransactionContext.reload(RootContext.getXID()).rollback();
} catch (TransactionException ex) { } catch (TransactionException ex) {
logger.error("seata 事务异常!"); logger.error("seata 事务异常!");
return false;
} }
} }
return flag; return flag;
} }

View File

@ -54,4 +54,11 @@ public class ShopMerchEntryController extends BaseControllerImpl {
approvalStatusList.add(3); approvalStatusList.add(3);
return shopMerchEntryService.shopMerchEntryDetail(null, jsonParam.getStr("mobile"), approvalStatusList); return shopMerchEntryService.shopMerchEntryDetail(null, jsonParam.getStr("mobile"), approvalStatusList);
} }
@ApiOperation(value = "通过手机号mobile获取商家入驻审核状态", notes = "通过手机号获取商家入驻审核状态")
@RequestMapping(value = "/approval/status", method = RequestMethod.POST)
public Integer shopMerchEntryApprovalStatus(@RequestBody JSONObject jsonParam) {
// approvalStatus 入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请
return shopMerchEntryService.shopMerchEntryApprovalStatus(jsonParam.getStr("mobile"));
}
} }

View File

@ -69,4 +69,13 @@ public interface ShopMerchEntryService {
* @return * @return
*/ */
Boolean isApplied(String mobile, String bizLicenseNumber); Boolean isApplied(String mobile, String bizLicenseNumber);
/**
* 获取商家入驻审核状态
* approval_status 入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请
*
* @param loginMobile
* @return
*/
Integer shopMerchEntryApprovalStatus(String loginMobile);
} }

View File

@ -315,4 +315,28 @@ public class ShopMerchEntryServiceImpl extends BaseServiceImpl<ShopMerchEntryMap
return count(queryWrapper) > 0; return count(queryWrapper) > 0;
} }
/**
* 获取商家入驻审核状态
* approval_status 入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请
*
* @param loginMobile
* @return
*/
@Override
public Integer shopMerchEntryApprovalStatus(String loginMobile) {
if (StrUtil.isBlank(loginMobile)) {
return 1;
}
QueryWrapper<ShopMerchEntry> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("login_mobile", loginMobile).orderByAsc("id");
List<ShopMerchEntry> recordList = list(queryWrapper);
if (CollectionUtil.isEmpty(recordList)) {
return 4;
}
return recordList.get(0).getApproval_status();
}
} }