|
@@ -309,45 +309,50 @@ public class usercenter extends Controller {
|
|
@API(title = "微信账号绑定", apiversion = R.ID20240516090402.v1.class, accesstoken = false)
|
|
@API(title = "微信账号绑定", apiversion = R.ID20240516090402.v1.class, accesstoken = false)
|
|
@CACHEING_CLEAN(cms = {@cm(clazz = usercenter.class, method = {"queryUserMsg"})})
|
|
@CACHEING_CLEAN(cms = {@cm(clazz = usercenter.class, method = {"queryUserMsg"})})
|
|
public String WechatBinding() throws YosException {
|
|
public String WechatBinding() throws YosException {
|
|
- String wechat_code = content.getString("wechat_code");
|
|
|
|
|
|
+
|
|
|
|
+ String openid = UserHelper.getWechatUserID(this).getOpenid();
|
|
|
|
+ String unionid = UserHelper.getWechatUserID(this).getUnionid();
|
|
boolean isbinging = content.getBooleanValue("isbinging");
|
|
boolean isbinging = content.getBooleanValue("isbinging");
|
|
- Long sys_enterprise_hrid = 0L;
|
|
|
|
- if (content.containsKey("sys_enterprise_hrid") && content.getLongValue("sys_enterprise_hrid") > 0) {
|
|
|
|
- sys_enterprise_hrid = content.getLongValue("sys_enterprise_hrid");
|
|
|
|
|
|
+ long sys_enterprise_hrid = content.getLongValue("sys_enterprise_hrid");
|
|
|
|
+ long logoutUserid = userid;
|
|
|
|
+ boolean isleader = false;
|
|
|
|
+
|
|
|
|
+ if (isbinging && sys_enterprise_hrid > 0) {
|
|
Rows rows = dbConnect.runSqlQuery("SELECT * from sys_enterprise_hr WHERE sys_enterprise_hrid='" + sys_enterprise_hrid + "' and siteid ='" + siteid + "'");
|
|
Rows rows = dbConnect.runSqlQuery("SELECT * from sys_enterprise_hr WHERE sys_enterprise_hrid='" + sys_enterprise_hrid + "' and siteid ='" + siteid + "'");
|
|
- if (rows.isNotEmpty()) {
|
|
|
|
- if (rows.get(0).getLong("userid") > 0) {
|
|
|
|
- return getErrReturnObject().setErrMsg("团队成员已被绑定").toString();
|
|
|
|
- }
|
|
|
|
|
|
+ if (rows.isEmpty()) {
|
|
|
|
+ return getErrReturnObject().setErrMsg("绑定的主账号或子账号不存在").toString();
|
|
}
|
|
}
|
|
|
|
+ long tempuserid = rows.get(0).getLong("userid");
|
|
|
|
+ if (UserHelper.getOpenidsRows(this, tempuserid).isNotEmpty()) {
|
|
|
|
+ return getErrReturnObject().setErrMsg("主账号或子账号已绑定微信!").toString();
|
|
|
|
+ }
|
|
|
|
+ if (UserHelper.getUnionidsRows(this, tempuserid).isNotEmpty()) {
|
|
|
|
+ return getErrReturnObject().setErrMsg("主账号或子账号已绑定微信!").toJSONString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ isleader = rows.get(0).getBoolean("isleader");
|
|
|
|
+
|
|
rows = dbConnect.runSqlQuery("SELECT * from sys_enterprise_hr WHERE userid='" + userid + "' and siteid ='" + siteid + "'");
|
|
rows = dbConnect.runSqlQuery("SELECT * from sys_enterprise_hr WHERE userid='" + userid + "' and siteid ='" + siteid + "'");
|
|
if (rows.isNotEmpty()) {
|
|
if (rows.isNotEmpty()) {
|
|
- if (rows.get(0).getLong("userid") > 0) {
|
|
|
|
- return getErrReturnObject().setErrMsg("当前账号已绑定微信!").toString();
|
|
|
|
- }
|
|
|
|
|
|
+ return getErrReturnObject().setErrMsg("当前账号已绑定主账号或子账号!").toString();
|
|
}
|
|
}
|
|
|
|
+ //绑定主账号微信
|
|
|
|
+ if (isleader) {
|
|
|
|
+ userid = tempuserid;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
- WechatMiniProgram wechatMiniProgram = new WechatMiniProgram(systemclient);
|
|
|
|
- WechatUserID wechatUser = wechatMiniProgram.getWechatUserID(wechat_code);
|
|
|
|
- String openid = wechatUser.getOpenid();
|
|
|
|
- String unionid = wechatUser.getUnionid();
|
|
|
|
- if (isbinging) {
|
|
|
|
- Rows openidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_openids where userid='" + userid + "' and systemclient='" + systemclient + "'");
|
|
|
|
|
|
+ if (isbinging && sys_enterprise_hrid == 0) {
|
|
|
|
+ Rows openidsRows = UserHelper.getOpenidsRows(this, userid);
|
|
if (openidsRows.isNotEmpty() && !openidsRows.get(0).getString("openid").equals(openid)) {
|
|
if (openidsRows.isNotEmpty() && !openidsRows.get(0).getString("openid").equals(openid)) {
|
|
return getErrReturnObject().setErrMsg("当前账号已绑定微信!").toJSONString();
|
|
return getErrReturnObject().setErrMsg("当前账号已绑定微信!").toJSONString();
|
|
}
|
|
}
|
|
-
|
|
|
|
- Rows unionidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_unionids where userid='" + userid + "'");
|
|
|
|
|
|
+ Rows unionidsRows = UserHelper.getUnionidsRows(this, userid);
|
|
if (unionidsRows.isNotEmpty() && !unionidsRows.get(0).getString("unionid").equals(unionid)) {
|
|
if (unionidsRows.isNotEmpty() && !unionidsRows.get(0).getString("unionid").equals(unionid)) {
|
|
return getErrReturnObject().setErrMsg("当前账号已绑定微信!").toJSONString();
|
|
return getErrReturnObject().setErrMsg("当前账号已绑定微信!").toJSONString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- String wechatuserinfo = "";
|
|
|
|
- if (content.containsKey("wechatuserinfo")) {
|
|
|
|
- wechatuserinfo = content.getString("wechatuserinfo", true);
|
|
|
|
- }
|
|
|
|
ArrayList<String> sqllist = new ArrayList<>();
|
|
ArrayList<String> sqllist = new ArrayList<>();
|
|
if (openid != null && !openid.equals("")) {
|
|
if (openid != null && !openid.equals("")) {
|
|
if (isbinging) {
|
|
if (isbinging) {
|
|
@@ -358,8 +363,13 @@ public class usercenter extends Controller {
|
|
sqlFactory.addParameter("systemclient", systemclient);
|
|
sqlFactory.addParameter("systemclient", systemclient);
|
|
sqlFactory.addParameter("openid", openid);
|
|
sqlFactory.addParameter("openid", openid);
|
|
sqlFactory.addParameter("userid", userid);
|
|
sqlFactory.addParameter("userid", userid);
|
|
- sqlFactory.addParameter("userinfo", wechatuserinfo);
|
|
|
|
|
|
+ sqlFactory.addParameter("userinfo", "");
|
|
sqllist.add(sqlFactory.getSQL());
|
|
sqllist.add(sqlFactory.getSQL());
|
|
|
|
+ } else {
|
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_wechatapp_openids");
|
|
|
|
+ updateSQL.setUniqueid(openidsRows.get(0).getLong("wechatapp_openidsid"));
|
|
|
|
+ updateSQL.setValue("userid", userid);
|
|
|
|
+ sqllist.add(updateSQL.getSQL());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_openids where openid='" + openid + "' and userid='" + userid + "' and systemclient='" + systemclient + "'").isEmpty()) {
|
|
if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_openids where openid='" + openid + "' and userid='" + userid + "' and systemclient='" + systemclient + "'").isEmpty()) {
|
|
@@ -377,8 +387,13 @@ public class usercenter extends Controller {
|
|
sqlFactory.addParameter("wechatapp_unionidsid", createTableID("sys_wechatapp_unionids"));
|
|
sqlFactory.addParameter("wechatapp_unionidsid", createTableID("sys_wechatapp_unionids"));
|
|
sqlFactory.addParameter("unionid", unionid);
|
|
sqlFactory.addParameter("unionid", unionid);
|
|
sqlFactory.addParameter("userid", userid);
|
|
sqlFactory.addParameter("userid", userid);
|
|
- sqlFactory.addParameter("userinfo", wechatuserinfo);
|
|
|
|
|
|
+ sqlFactory.addParameter("userinfo", "");
|
|
sqllist.add(sqlFactory.getSQL());
|
|
sqllist.add(sqlFactory.getSQL());
|
|
|
|
+ } else {
|
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_wechatapp_unionids");
|
|
|
|
+ updateSQL.setUniqueid(openidsRows.get(0).getLong("wechatapp_unionidsid"));
|
|
|
|
+ updateSQL.setValue("userid", userid);
|
|
|
|
+ sqllist.add(updateSQL.getSQL());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_unionids where unionid='" + unionid + "' and userid='" + userid + "'").isEmpty()) {
|
|
if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_unionids where unionid='" + unionid + "' and userid='" + userid + "'").isEmpty()) {
|
|
@@ -395,8 +410,13 @@ public class usercenter extends Controller {
|
|
updateSQL.setValue("userid", userid);
|
|
updateSQL.setValue("userid", userid);
|
|
updateSQL.update();
|
|
updateSQL.update();
|
|
if (usertype == 99) {
|
|
if (usertype == 99) {
|
|
|
|
+ if (isleader) {
|
|
|
|
+ new StoreHelper().updateUserType21(this, userid);
|
|
|
|
+ loguserout(logoutUserid);
|
|
|
|
+ } else {
|
|
|
|
+ new StoreHelper().updateUserType22(this, userid);
|
|
|
|
+ }
|
|
|
|
|
|
- new StoreHelper().updateUserType22(this, userid);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|