登录注册鉴权 优化

This commit is contained in:
Jack 2025-03-25 17:31:32 +08:00
parent 9cfe4bee0c
commit d1f68b679c
12 changed files with 401 additions and 189 deletions

View File

@ -46,6 +46,17 @@ public class LoginController extends BaseControllerImpl {
@Autowired
private UserInfoService userInfoService;
/**
* 移动端登录
*/
@RequestMapping(value = "/testcase", method = RequestMethod.GET)
public Object testcase() {
Map<String, Object> arg = new HashMap<String, Object>();
arg.put("password", "HzMk23");
return accountUserBaseService.sendSmsMessage("", "SMS_481085172", arg);
}
@ApiOperation(value = "登录以后返回token")
@ApiImplicitParams({
@ApiImplicitParam(name = "user_account", value = "账号", paramType = "query", required = false, dataType = "String"),
@ -115,7 +126,7 @@ public class LoginController extends BaseControllerImpl {
}
/**
* 注册后直接登录
* (用户端)注册后直接登录
*
* @param user_account
* @param user_email

View File

@ -188,4 +188,14 @@ public interface AccountUserBaseService extends IBaseService<AccountUserBase> {
* @return
*/
CommonResult doForgetPassword(String userAccountOrMobile, String verifyCode, String newPassword);
/**
* 发送短信
*
* @param mobile 发送的手机号码
* @param templateCode 模版编号
* @param msgArgs 模版的参数key与值
* @return
*/
Boolean sendSmsMessage(String mobile, String templateCode, Map<String, Object> msgArgs);
}

View File

@ -1607,47 +1607,49 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
// 是否为手机号注册
String user_account = (String) userInfo.get("user_account");
String user_mobile = (String) userInfo.get("user_mobile");
user_mobile = PhoneNumberUtils.convZhPhoneNumber(user_mobile);
String user_mobile = (String) userInfo.get("user_mobile"); // 带国家码的
String rand_key = (String) userInfo.get("rand_key");
String verifyCode = (String) userInfo.get("verify_code");
String verify_token = (String) userInfo.get("verify_token");
Integer userIsAdmin = Convert.toInt(userInfo.getOrDefault("user_is_admin", CommonConstant.USER_TYPE_NORMAL)); // 用户类型:0-普通买家; 1-管理员2-入驻商家
Integer userType = userIsAdmin; // 用户身份:0-普通买家; 1-管理员2-入驻商家(有歧义废弃)
String user_intl = "";
logger.debug("### 注册参数:{}###", JSONUtil.toJsonStr(userInfo));
// todo 支持国外手机号 isMobile() 方法
String currency_id = "+" + getParameter("currency_id", "");
String currency_id = getParameter("currency_id", "");
if (StrUtil.isNotBlank(currency_id)) {
user_intl = "+" + currency_id;
} else {
user_intl = CommonConstant.IDD_ZH_CN;
}
// org.apache.commons.lang3.StringUtils.isBlank("");
if (StrUtil.isNotBlank(user_mobile) || (CheckUtil.isMobile(user_account, currency_id) && StrUtil.equals(user_account, user_mobile))) {
// 是否为手机号码的注册
// 拆分手机号码为intl + code
// todo 优化根据电话号码查询地区码+86
if (StrUtil.startWith(user_mobile, currency_id)) {
user_intl = currency_id;
// user_account = user_mobile = StrUtil.removePrefix(user_mobile, user_intl);
}
user_mobile = PhoneNumberUtils.convWithIDDCodePhoneNumber(user_mobile, user_intl);
// 有手机参数优先手机注册
if ((StrUtil.isNotBlank(user_mobile) && StrUtil.isNotBlank(verifyCode))
|| (CheckUtil.isMobile(user_account, user_intl) && StrUtil.equals(user_account, user_mobile))) {
if (StrUtil.isNotBlank(rand_key)) {
// 手机验证校验
String verify_code = (String) userInfo.get("verify_code");
if (!checkVerifyCode(user_mobile, verify_code)) {
throw new ApiException(_("验证码异常!"));
if (!checkVerifyCode(user_mobile, verifyCode)) {
throw new ApiException(_("验证码校验失败!"));
}
}
// 判断connect绑定操作
AccountUserBindConnect bind_check_row = bindConnectService.get(user_mobile);
if (bind_check_row != null && CheckUtil.isNotEmpty(bind_check_row.getBind_active())) {
AccountUserBindConnect bind_check_row = bindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, userIsAdmin);
if (bind_check_row != null) {
logger.error("##手机号:{}##", user_mobile);
throw new ApiException(_("手机号已经绑定过,不可以使用此手机号注册"));
}
}
if (StrUtil.isNotBlank(user_account) && StrUtil.isNotBlank(verifyCode) && StrUtil.isNotEmpty(verify_token) && null == userInfo.get("user_email")) {
// 是否为账号的注册
// 是否为账号的注册(好像包含了微信授权openid的)
if (StrUtil.isNotBlank(user_account) && StrUtil.isNotBlank(verifyCode)
&& StrUtil.isNotBlank(verify_token) && ObjectUtil.isNull(userInfo.get("user_email"))) {
if (StrUtil.isNotBlank(verifyCode)) {
// 验证码校验
Boolean hasKey = redisService.hasKey(VERIFY_CODE_KEY + user_account);
@ -1674,22 +1676,22 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
String user_email = (String) userInfo.get("user_email");
Integer bind_type = getParameter("bind_type", 0);
// 是否为邮箱注册
if (StrUtil.isNotBlank(user_email)
|| (CheckUtil.isEmail(user_account) && StrUtil.equals(user_account, user_email))
|| bind_type.equals(2)) {
// 是否为邮箱注册
|| bind_type.equals(BindCode.EMAIL)) {
if (StrUtil.isNotBlank(rand_key)) {
// 邮箱验证码校验
String verify_code = (String) userInfo.get("verify_code");
if (!checkVerifyCode(user_email, verify_code)) {
throw new ApiException(_("验证码异常"));
throw new ApiException(_("验证码校验失败"));
}
}
// 判断connect绑定操作
AccountUserBindConnect bind_check_row = bindConnectService.get(user_email);
if (bind_check_row != null && CheckUtil.isNotEmpty(bind_check_row.getBind_active())) {
AccountUserBindConnect bind_check_row = bindConnectService.getBindByBindId(user_email, BindCode.EMAIL, userIsAdmin);
if (bind_check_row != null) {
throw new ApiException("Email已经绑定过不可以使用此Email注册");
}
}
@ -1712,7 +1714,6 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
// 用户尚未注册立即新增用户基本信息和用户附加信息
String user_nickname = Convert.toStr(userInfo.get("user_nickname"), user_account);
Integer user_state = Convert.toInt(userInfo.get("user_state"), 2);
Integer user_is_admin = Convert.toInt(userInfo.get("user_is_admin"), CommonConstant.USER_TYPE_NORMAL); // 用户类型0-普通用户1-管理员2-入驻商户默认是普通用户
String user_key = IdUtil.simpleUUID();
String user_salt = IdUtil.simpleUUID();
String user_token = IdUtil.simpleUUID();
@ -1730,9 +1731,10 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
user_base_reg_row.setUser_key(user_key);
user_base_reg_row.setUser_salt(user_salt);
user_base_reg_row.setRights_group_id(rights_group_id);
user_base_reg_row.setUser_is_admin(user_is_admin);
user_base_reg_row.setStore_ids(store_ids);
user_base_reg_row.setUser_token(user_token);
user_base_reg_row.setUser_is_admin(userIsAdmin);// 用户类型0-普通用户1-管理员2-入驻商户默认是普通用户
user_base_reg_row.setUser_type(userType); // 用户类型0-普通用户1-管理员2-入驻商户默认是普通用户
if (!saveOrUpdate(user_base_reg_row)) {
throw new ApiException(ResultCode.FAILED);
@ -1789,7 +1791,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
bindConnect.setBind_openid(user_mobile);
bindConnect.setBind_active(CommonConstant.Enable);
if (!bindConnectService.checkBind(user_mobile, BindCode.MOBILE, user_id, user_is_admin, bindConnect)) {
if (!bindConnectService.checkBind(user_mobile, BindCode.MOBILE, user_id, userIsAdmin, bindConnect)) {
throw new ApiException(ResultCode.FAILED);
}
}
@ -2290,7 +2292,6 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
String service_app_key = accountBaseConfigService.getConfig("service_app_key");
number = StrUtil.removePrefix(number, CommonConstant.IDD_ZH_CN);
SmsDto smsDto = new SmsDto();
smsDto.setSmsType(accountBaseConfigService.getConfig("sms_type", 1)); //默认短信通道
smsDto.setSmsSign(accountBaseConfigService.getConfig("sms_sign", "")); //默认短信通道
@ -2311,7 +2312,6 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
smsDto.setHuaweiSmsKey(huaweiSmsKey);
smsDto.setHuaweiSmsKeySecret(huaweiSmsKeySecret);
// 短信应用SDK AppID 1400开头
Integer tengxunAppId = accountBaseConfigService.getConfig("tengxun_sms_app_id", 0);
// 短信应用SDK AppKey
@ -2325,7 +2325,6 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
smsDto.setSmsSign(aliyunSmsSign);
smsDto.setTemplateCode("SMS_308685826");
smsDto.setContent("您的验证码为:${code},请勿泄露于他人!");
Map msgArgs = new HashMap();
@ -2819,14 +2818,16 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
/**
* 商家版app入驻商家手机号绑定登录
*
* @param user_mobile
* @param isMerch
* @param user_mobile +86的中国号码
* @param isMerch 是否是商家入驻的
* @return
*/
public CommonResult doMobileBindLogin(String user_mobile, boolean isMerch) {
AccountUserBindConnect bind_row = bindConnectService.get(user_mobile);
// 查询绑定手机的商家账号
AccountUserBindConnect bind_row = accountUserBindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, CommonConstant.USER_TYPE_MCH);
//bindConnectService.get(user_mobile);
AccountUserBase accountUserBase = null;
if (bind_row != null && ObjectUtil.equal(BindCode.MOBILE, bind_row.getBind_type())) {
if (bind_row != null) {
// 已经注册账号的绑定了手机的情况
Integer user_id = bind_row.getUser_id();
accountUserBase = get(user_id);
@ -2843,11 +2844,10 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
} else {
// 手机号码未绑定的情况直接去注册一个账号
Map<String, Object> userInfo = new HashMap<>();
userInfo.put("user_account", com.suisung.mall.common.utils.StringUtils.genLklOrderNo(4));// 时间 yyyyMMddHHmmss + 4位随机数
userInfo.put("user_account", user_mobile);// 时间 yyyyMMddHHmmss + 4位随机数 com.suisung.mall.common.utils.StringUtils.genLklOrderNo(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);
userInfo.put("user_password", user_password);
userInfo.put("is_admin", CommonConstant.USER_TYPE_MCH); // 商家入驻注册
@ -2858,7 +2858,12 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
throw new ApiException(_("账号注册失败!"));
}
// TODO 发送短信通知用户告知用户随机密码尊敬的商家用户你们刚注册账号的账号密码为" + user_password + "请妥善保管以免丢失
// SMS_481085172 发送短信通知用户告知用户随机密码您已成功注册密码${password}该密码可用于登录商家APP登录后请尽快修改密码
Map<String, Object> smsArgs = new HashMap<>();
smsArgs.put("password", user_password);
sendSmsMessage(user_mobile, "SMS_481085172", smsArgs);
}
Map<String, String> params = new HashMap<>();
@ -3248,5 +3253,58 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
}
@Override
public Boolean sendSmsMessage(String mobile, String templateCode, Map<String, Object> msgArgs) {
//读取sms配置信息
String service_user_id = accountBaseConfigService.getConfig("service_user_id");
String service_app_key = accountBaseConfigService.getConfig("service_app_key");
mobile = StrUtil.removePrefix(mobile, CommonConstant.IDD_ZH_CN);
SmsDto smsDto = new SmsDto();
smsDto.setSmsType(accountBaseConfigService.getConfig("sms_type", 1)); //默认短信通道
smsDto.setSmsSign(accountBaseConfigService.getConfig("sms_sign", "")); //默认短信通道
smsDto.setServiceUserId(service_user_id);
smsDto.setServiceAppKey(service_app_key);
//其它通道要赋值通道信息 appid 以及 key
String aliyunSmsAccessKeyId = accountBaseConfigService.getConfig("aliyun_sms_access_key_id");
String aliyunSmsAccessKeySecret = accountBaseConfigService.getConfig("aliyun_sms_access_key_secret");
String aliyunSmsRegionId = accountBaseConfigService.getConfig("aliyun_sms_region_id");
smsDto.setAliyunSmsAccessKeyId(aliyunSmsAccessKeyId);
smsDto.setAliyunSmsAccessKeySecret(aliyunSmsAccessKeySecret);
smsDto.setAliyunSmsRegionId(aliyunSmsRegionId);
String huaweiSmsKey = accountBaseConfigService.getConfig("huawei_sms_access_key");
String huaweiSmsKeySecret = accountBaseConfigService.getConfig("huawei_sms_access_secret");
smsDto.setHuaweiSmsKey(huaweiSmsKey);
smsDto.setHuaweiSmsKeySecret(huaweiSmsKeySecret);
// 短信应用SDK AppID 1400开头
Integer tengxunAppId = accountBaseConfigService.getConfig("tengxun_sms_app_id", 0);
// 短信应用SDK AppKey
String tengxunAppkey = accountBaseConfigService.getConfig("tengxun_sms_app_key");
smsDto.setTengxunAppId(tengxunAppId);
smsDto.setTengxunAppkey(tengxunAppkey);
smsDto.setTengxunTemplateId(1); //短信模板ID
smsDto.setMobile(mobile);
String aliyunSmsSign = accountBaseConfigService.getConfig("aliyun_sms_sign");
smsDto.setSmsSign(aliyunSmsSign);
smsDto.setTemplateCode(templateCode);
// smsDto.setContent("您的验证码为:${code},请勿泄露于他人!");
smsDto.setParamMap(msgArgs); //传入模板对应参数
try {
ThirdUtil.send(smsDto);
return true;
} catch (Exception e) {
logger.error("发送短信失败:", e);
return false;
}
}
}

View File

@ -78,7 +78,14 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
@Override
public AccountUserBindConnect getBindByBindId(String bind_id, Integer bind_type, Integer user_type) {
if (StrUtil.isEmpty(bind_id)) {
return null;
}
// 如果是手机号码则进行转换带 +86 的手机号码
bind_id = bind_type == BindCode.MOBILE ? PhoneNumberUtils.convZhPhoneNumber(bind_id) : bind_id;
user_type = ObjectUtil.isNotEmpty(user_type) ? user_type : CommonConstant.USER_TYPE_NORMAL;
QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bind_id", bind_id)
.eq("bind_type", bind_type)
@ -89,6 +96,8 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
@Override
public boolean checkBind(String bind_id, int bind_type, Integer user_id, Integer user_type, AccountUserBindConnect user_info_row) {
// 如果是手机号码则进行转换带 +86 的手机号码
bind_id = bind_type == BindCode.MOBILE ? PhoneNumberUtils.convZhPhoneNumber(bind_id) : bind_id;
AccountUserBindConnect currAccountUserBindConnect = get(bind_id);
if (currAccountUserBindConnect != null && CheckUtil.isNotEmpty(currAccountUserBindConnect.getUser_id())) {
@ -281,16 +290,15 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
*/
@Override
public Integer getUserBindConnectUserIdByCondition(String bindId, Integer bindType, Integer userType) {
if (bindId == null) {
if (StrUtil.isEmpty(bindId) || ObjectUtil.isEmpty(bindType)) {
return null;
}
if (BindCode.MOBILE == bindType) {
// 加上 +86 中国区域号
bindId = PhoneNumberUtils.convZhPhoneNumber(bindId);
}
bindId = bindType == BindCode.MOBILE ? PhoneNumberUtils.convZhPhoneNumber(bindId) : bindId;
QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bind_id", bindId).eq("bind_type", bindType);
if (userType != null) {
queryWrapper.eq("bind_id", bindId).eq("bind_type", bindType).eq("bind_active", CommonConstant.Enable);
if (ObjectUtil.isNotEmpty(userType)) {
queryWrapper.eq("user_type", userType);
}

View File

@ -72,7 +72,7 @@ public class AccountUserBase implements Serializable {
private String user_quickcode;
@ApiModelProperty(value = "用户身份0-个人身份1-企业身份;")
private String user_type;
private Integer user_type;
@ApiModelProperty(value = "公司id")
private String user_company_id;

View File

@ -10,6 +10,7 @@ import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import com.suisung.mall.common.constant.CommonConstant;
import java.util.Locale;
import java.util.regex.Pattern;
public class PhoneNumberUtils {
/**
@ -66,6 +67,40 @@ public class PhoneNumberUtils {
return StrUtil.startWith(phoneNumber, "+") ? phoneNumber : CommonConstant.IDD_ZH_CN + phoneNumber;
}
/**
* 如果手机号码不带国家码转换指定国家区号
*
* @param phoneNumber 不带国际码的手机号
* @param IDDCode
* @return
*/
public static String convWithIDDCodePhoneNumber(String phoneNumber, String IDDCode) {
if (StrUtil.isBlank(phoneNumber)
|| phoneNumber.equalsIgnoreCase("null")
|| phoneNumber.equalsIgnoreCase("none")
|| phoneNumber.equalsIgnoreCase("nil")
|| phoneNumber.equalsIgnoreCase("undefined")) {
return "";
}
if (isValidNumber(phoneNumber)) {
return phoneNumber;
}
if (StrUtil.isBlank(IDDCode)) {
IDDCode = CommonConstant.IDD_ZH_CN;
} else {
if (!StrUtil.startWith(IDDCode, "+")) {
IDDCode = "+" + IDDCode;
}
if (!isValidCountryCode(IDDCode)) {
IDDCode = CommonConstant.IDD_ZH_CN;
}
}
return IDDCode + phoneNumber;
}
/**
* 去掉手机的国家码方法不严谨
*
@ -217,4 +252,23 @@ public class PhoneNumberUtils {
return phoneNumberUtil.isValidNumber(pn);
}
/**
* 判断字符串是不是国际电话区号
*
* @param code
* @return
*/
public static boolean isValidCountryCode(String code) {
// 定义正则表达式用于匹配国际电话区号的格式
String regex = "^\\+\\d{1,3}$";
// 编译正则表达式
Pattern pattern = Pattern.compile(regex);
// 检查字符串是否匹配正则表达式
return pattern.matcher(code).matches();
}
public static void main(String[] args) {
System.out.println(isValidNumber("13111111111"));
}
}

View File

@ -66,4 +66,13 @@ public interface EsignContractFillingFileService {
* @return
*/
EsignContractFillingFile getEsignContractFillingFile(String mchMobile, String templateId);
/**
* 更改商家入驻合同关联的店铺ID
*
* @param mchMobile
* @param storeId
* @return
*/
Boolean updateContractFillingStoreId(String mchMobile, Integer storeId);
}

View File

@ -114,4 +114,13 @@ public interface EsignContractService {
* @return
*/
Pair<Integer, String> checkSignFlowStatus(String mchMobile);
/**
* 更改商家入驻合同关联的店铺ID
*
* @param mchMobile
* @param storeId
* @return
*/
Boolean updateContractStoreId(String mchMobile, Integer storeId);
}

View File

@ -10,6 +10,7 @@ package com.suisung.mall.shop.esign.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
@ -613,4 +614,29 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
return list.get(0);
}
/**
* 更改商家入驻合同关联的店铺ID
*
* @param mchMobile
* @param storeId
* @return
*/
@Override
public Boolean updateContractFillingStoreId(String mchMobile, Integer storeId) {
if (StrUtil.isBlank(mchMobile) || ObjectUtil.isEmpty(storeId)) {
return false;
}
try {
// 更改合同记录表的店铺id
UpdateWrapper<EsignContractFillingFile> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("mobile", mchMobile);
updateWrapper.set("store_id", storeId);
return update(updateWrapper);
} catch (Exception e) {
log.error("更改合同关联的店铺ID发生错误", e);
return false;
}
}
}

View File

@ -291,18 +291,14 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
// 新建一个正式的已审核通过的店铺
taskService.executeTask(() -> {
try {
Pair<Integer, String> retPair = shopStoreBaseService.merchEntryInfo2StoreInfo(esignContract.getMch_mobile());
if (retPair.getFirst() > 0) {
// 更改合同记录表的店铺id
UpdateWrapper<EsignContract> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("sign_flow_id", signFlowId);
updateWrapper.set("store_id", retPair.getSecond());
update(updateWrapper);
}
} catch (Exception e) {
log.error("店铺创建失败:", e);
Pair<Integer, String> retPair = shopStoreBaseService.merchEntryInfo2StoreInfo(esignContract.getMch_mobile());
if (retPair.getFirst() > 0) {
// 更改合同记录表的店铺id
updateContractStoreId(esignContract.getMch_mobile(), retPair.getFirst());
esignContractFillingFileService.updateContractFillingStoreId(esignContract.getMch_mobile(), retPair.getFirst());
}
});
return new ResponseEntity<>(new JSONObject().put("code", 200).put("msg", "success").toString(), HttpStatus.OK);
@ -682,6 +678,31 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
return null;
}
/**
* 更改商家入驻合同关联的店铺ID
*
* @param mchMobile
* @param storeId
* @return
*/
@Override
public Boolean updateContractStoreId(String mchMobile, Integer storeId) {
if (StrUtil.isBlank(mchMobile) || ObjectUtil.isEmpty(storeId)) {
return false;
}
try {
// 更改合同记录表的店铺id
UpdateWrapper<EsignContract> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("mch_mobile", mchMobile);
updateWrapper.set("store_id", storeId);
return update(updateWrapper);
} catch (Exception e) {
log.error("更改合同关联的店铺ID发生错误", e);
return false;
}
}
// e签宝签名相关方法

View File

@ -2958,7 +2958,7 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
@Transactional
@Override
public Pair<Integer, String> merchEntryInfo2StoreInfo(String mchMobile) {
Integer storeId = 0;
if (StrUtil.isBlank(mchMobile)) {
logger.error("生成店铺:商家手机号不能为空");
return Pair.of(0, "商家手机号不能为空");
@ -2982,142 +2982,148 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
return Pair.of(0, "店铺名称已存在");
}
// 新增 shop_store_baseshop_store_infoshop_store_company, shop_store_employee 待补充
try {
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
// 新增 shop_store_baseshop_store_infoshop_store_company, shop_store_employee 待补充
// 省市区记录有序列表
List<ShopBaseDistrict> 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_type(1);//店铺类型(ENUM): 1-卖家店铺; 2-供应商店铺
shopStoreBase.setStore_is_open(1);
shopStoreBase.setStore_is_selfsupport(0);
shopStoreBase.setStore_o2o_flag(0);
shopStoreBase.setSubsite_id(0);
shopStoreBase.setStore_state_id(StateCode.STORE_STATE_YES);//店铺资料信息状态(ENUM):3210-待完善资料; 3220-等待审核 ; 3230-资料审核没有通过;3240-资料审核通过,待付款
shopStoreBase.setStore_time(DateUtil.date());
shopStoreBase.setStore_end_time(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365 * 5); // 5年
if (!save(shopStoreBase)) {
logger.error("生成店铺:新增店铺基本信息失败");
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<ShopBaseDistrict> 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_type(1);//店铺类型(ENUM): 1-卖家店铺; 2-供应商店铺
shopStoreBase.setStore_is_open(1);
shopStoreBase.setStore_is_selfsupport(0);
shopStoreBase.setStore_o2o_flag(0);
shopStoreBase.setSubsite_id(0);
shopStoreBase.setStore_state_id(StateCode.STORE_STATE_YES);//店铺资料信息状态(ENUM):3210-待完善资料; 3220-等待审核 ; 3230-资料审核没有通过;3240-资料审核通过,待付款
shopStoreBase.setStore_time(DateUtil.date());
shopStoreBase.setStore_end_time(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365 * 5); // 5年
if (!save(shopStoreBase)) {
logger.error("生成店铺:新增店铺基本信息失败");
// 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 * 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_banner(storeFacadeImage);
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._("新增店铺失败"));
}
// 如果商家是企业则保存商家公司信息
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._("新增店铺公司失败"));
throw new ApiException(I18nUtil._("新增店铺失败"));
}
}
// 保存后店铺Id
Integer storeId = shopStoreBase.getStore_id();
// 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._("新增店铺员工失败"));
}
// 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 * 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_banner(storeFacadeImage);
return Pair.of(storeId, "新增成功");
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._("新增店铺失败"));
}
// 如果商家是企业则保存商家公司信息
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, "新增成功");
} catch (Exception e) {
logger.error("生成店铺失败", e);
return Pair.of(0, I18nUtil._("新增店铺失败"));
}
}
/**

View File

@ -436,7 +436,7 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
accountUserBase.setUser_is_admin(CommonConstant.USER_TYPE_NORMAL);
accountUserBase.setStore_ids(storeId);
accountUserBase.setRights_group_id("0");// 普通用户不是商家
accountUserBase.setUser_type("0");
accountUserBase.setUser_type(CommonConstant.USER_TYPE_NORMAL);
// 默认给了随机密码和盐token
String user_key = IdUtil.simpleUUID();