公众号绑定手机号时生成pc端用户

This commit is contained in:
lujiang 2024-10-24 20:08:52 +08:00
parent 9d9574011d
commit 4c8237e03a
3 changed files with 43 additions and 4 deletions

View File

@ -216,10 +216,10 @@ public class MeetingReservationController extends BaseController {
/* 预定时间的转换 */
private Date convert(String date, Integer timeFormat, boolean start) {
String time = "";
if (timeFormat == 1) time = start ? " 08:30:00" : " 12:00:00";//1 上午
if (timeFormat == 2) time = start ? " 12:00:01" : " 17:30:00";//2 下午
if (timeFormat == 1) time = start ? " 09:00:00" : " 12:00:00";//1 上午
if (timeFormat == 2) time = start ? " 13:30:00" : " 17:30:00";//2 下午
if (timeFormat == 3) time = start ? " 17:30:01" : " 23:59:59";//3 晚上
if (timeFormat == 4) time = start ? " 08:30:00" : " 23:59:59";//4 全天
if (timeFormat == 4) time = start ? " 09:00:00" : " 23:59:59";//4 全天
try {
return DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, date + time);
} catch (Exception e) {

View File

@ -290,7 +290,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{customerId}
</select>
<select id="selectUserByStaffId" resultType="com.ics.system.domain.User">
select u.username,
select u.id,
u.username,
u.nickname,
u.email,
u.mobile,

View File

@ -2,8 +2,14 @@ package com.ics.controller.mobile;
import com.alibaba.fastjson.JSONObject;
import com.ics.admin.service.IIcsCustomerStaffService;
import com.ics.common.constant.UserConstants;
import com.ics.common.core.domain.IcsCustomerStaff;
import com.ics.common.core.domain.R;
import com.ics.common.utils.RandomUtil;
import com.ics.common.utils.StringUtils;
import com.ics.system.domain.User;
import com.ics.system.service.IUserService;
import com.ics.system.util.PasswordUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
@ -18,6 +24,8 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -48,6 +56,9 @@ public class WxBindController {
@Autowired
private IIcsCustomerStaffService customerStaffService;
@Autowired
private IUserService userService;
//微信公众号网页授权地址
private final static String OAUTH2_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=sh0907#wechat_redirect";
@ -106,6 +117,33 @@ public class WxBindController {
public String bind(String phone, String openid) {
String resultHtml = "<html><body><h1>%s</h1></body></html>";
int row = customerStaffService.updateGzhOpenid(phone, openid);
if (row > 0) {
//插入pc端用户
User user = new User();
user.setUsername(phone);
user.setPassword(phone);
user.setSalt(RandomUtil.randomStr(6));
user.setPassword(PasswordUtils.encryptPassword(user.getUsername(), user.getPassword(), user.getSalt()));
user.setNickname(phone);
user.setMobile(phone);
user.setGender("0");
user.setStatus("0");
user.setDeptId(179L);
List<Long> roles = new ArrayList<>();
roles.add(6L);//关联角色
user.setRoleIds(roles);
user.setVersion(0);
user.setDeleteFlag(0);
user.setCreateTime(new Date());
//登录名和手机号不能重复
if (UserConstants.USER_NAME_UNIQUE.equals(userService.checkUsernameUnique(user))
&& UserConstants.USER_PHONE_UNIQUE.equals(userService.checkMobileUnique(user))) {
IcsCustomerStaff staff = customerStaffService.selectUserByMobile(phone);
user.setStaffId(staff.getId());//关联小程序
userService.insertUser(user);
}
}
//插入pc端用户
return String.format(resultHtml, row > 0 ? "绑定成功" : "绑定失败");
}