+1
@@ -7,6 +7,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class WorkbenchRegistrationRequestDTO {
|
||||
private Long applicationId;
|
||||
private String wxCode;
|
||||
private String phone;
|
||||
private String verificationCode;
|
||||
private String password;
|
||||
|
||||
+33
-1
@@ -9,6 +9,9 @@ import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRe
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.service.WorkbenchRegistrationService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.vo.WorkbenchRegistrationStatusVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.entity.WechatMiniBindingDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.mapper.WechatMiniBindingMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.WechatMiniClientService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.support.UserShopBindingSupport;
|
||||
@@ -33,6 +36,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
private final UserService userService;
|
||||
private final VerificationCodeService verificationCodeService;
|
||||
private final UserShopBindingSupport userShopBindingSupport;
|
||||
private final WechatMiniBindingMapper wechatMiniBindingMapper;
|
||||
private final WechatMiniClientService wechatMiniClientService;
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
public WorkbenchRegistrationServiceImpl(
|
||||
@@ -41,7 +46,9 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
ShopMapper shopMapper,
|
||||
UserService userService,
|
||||
VerificationCodeService verificationCodeService,
|
||||
UserShopBindingSupport userShopBindingSupport
|
||||
UserShopBindingSupport userShopBindingSupport,
|
||||
WechatMiniBindingMapper wechatMiniBindingMapper,
|
||||
WechatMiniClientService wechatMiniClientService
|
||||
) {
|
||||
this.applicationMapper = applicationMapper;
|
||||
this.userMapper = userMapper;
|
||||
@@ -49,6 +56,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
this.userService = userService;
|
||||
this.verificationCodeService = verificationCodeService;
|
||||
this.userShopBindingSupport = userShopBindingSupport;
|
||||
this.wechatMiniBindingMapper = wechatMiniBindingMapper;
|
||||
this.wechatMiniClientService = wechatMiniClientService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +103,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
user.setStatus(0);
|
||||
user.setIsDelete(0);
|
||||
userMapper.insert(user);
|
||||
bindWechatUser(request.getWxCode(), user.getId());
|
||||
userShopBindingSupport.syncUserShopBindings(user.getId(), List.of(shop.getId()));
|
||||
userShopBindingSupport.updateBindingStatus(user.getId(), shop.getId(), 0);
|
||||
|
||||
@@ -204,6 +214,28 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
private void bindWechatUser(String wxCode, Long userId) {
|
||||
if (!StringUtils.hasText(wxCode)) {
|
||||
return;
|
||||
}
|
||||
WechatMiniClientService.SessionInfo sessionInfo = wechatMiniClientService.code2Session(wxCode);
|
||||
String appId = wechatMiniClientService.getConfiguredAppId();
|
||||
WechatMiniBindingDO binding = wechatMiniBindingMapper.selectOne(Wrappers.lambdaQuery(WechatMiniBindingDO.class).eq(WechatMiniBindingDO::getAppId, appId).eq(WechatMiniBindingDO::getOpenId, sessionInfo.openId()).last("limit 1"));
|
||||
if (binding == null) {
|
||||
binding = new WechatMiniBindingDO();
|
||||
binding.setAppId(appId);
|
||||
binding.setOpenId(sessionInfo.openId());
|
||||
}
|
||||
binding.setUserId(userId);
|
||||
binding.setUnionId(sessionInfo.unionId());
|
||||
binding.setStatus(1);
|
||||
if (binding.getId() == null) {
|
||||
wechatMiniBindingMapper.insert(binding);
|
||||
} else {
|
||||
wechatMiniBindingMapper.updateById(binding);
|
||||
}
|
||||
}
|
||||
|
||||
private void require(boolean condition, String message) {
|
||||
if (!condition) {
|
||||
throw new IllegalArgumentException(message);
|
||||
|
||||
@@ -477,8 +477,14 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
goRegister() {
|
||||
wx.navigateTo({ url: '/pages/register/index' })
|
||||
async getWechatCode() {
|
||||
const result = await new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject }))
|
||||
return result.code
|
||||
},
|
||||
|
||||
goRegister(wxCode) {
|
||||
const query = wxCode ? `?wxCode=${encodeURIComponent(wxCode)}` : ''
|
||||
wx.navigateTo({ url: `/pages/register/index${query}` })
|
||||
},
|
||||
|
||||
async wechatLogin() {
|
||||
@@ -489,7 +495,8 @@ Page({
|
||||
const result = await authApi.wechatAutoLogin(loginResult.code)
|
||||
if (result.status === 'NEED_MANUAL_LOGIN') {
|
||||
wx.showToast({ title: '新账号请先完成手机号注册和身份审核', icon: 'none', duration: 2500 })
|
||||
setTimeout(() => this.goRegister(), 900)
|
||||
const wxCode = await this.getWechatCode()
|
||||
setTimeout(() => this.goRegister(wxCode), 900)
|
||||
return
|
||||
}
|
||||
if (result.status !== 'SUCCESS' || !result.accessToken) {
|
||||
|
||||
@@ -8,6 +8,7 @@ Page({
|
||||
role: 'manager',
|
||||
passwordMode: false,
|
||||
form: { phone: '', code: '', password: '', confirmPassword: '', shopName: '', shopAddress: '', shopId: '' },
|
||||
wxCode: '',
|
||||
shopOptions: [],
|
||||
shopIndex: 0,
|
||||
selectedShopName: '',
|
||||
@@ -17,7 +18,8 @@ Page({
|
||||
countdownTimer: null
|
||||
},
|
||||
|
||||
async onLoad() {
|
||||
async onLoad(options) {
|
||||
this.setData({ wxCode: options && options.wxCode ? options.wxCode : '' })
|
||||
try {
|
||||
const shopOptions = await authApi.getAvailableRegistrationShops()
|
||||
this.setData({ shopOptions: Array.isArray(shopOptions) ? shopOptions : [] })
|
||||
@@ -65,7 +67,7 @@ Page({
|
||||
if (this.data.role === 'staff') { wx.showToast({ title: '店员申请功能即将开放', icon: 'none' }); return }
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
await authApi.register({ phone: form.phone, verificationCode: form.code, password: form.password, confirmPassword: form.confirmPassword, shopName: form.shopName, shopAddress: form.shopAddress, shopId: form.shopId, roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF', agreementAccepted: true })
|
||||
await authApi.register({ phone: form.phone, verificationCode: form.code, password: form.password, confirmPassword: form.confirmPassword, shopName: form.shopName, shopAddress: form.shopAddress, shopId: form.shopId, roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF', agreementAccepted: true, wxCode: this.data.wxCode })
|
||||
this.setData({ step: 4 })
|
||||
} catch (error) { wx.showToast({ title: error.message || '提交失败', icon: 'none' }) } finally { this.setData({ loading: false }) }
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user