|
@@ -83,7 +83,7 @@ func (m *MiniProgram) AutoLogin() {
|
|
|
})
|
|
|
status := m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
|
if status == -1 {
|
|
|
- if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone, "") {
|
|
|
+ if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone, "") > 0 {
|
|
|
status = m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
|
}
|
|
|
}
|
|
@@ -162,8 +162,30 @@ func (m *MiniProgram) BindPhone() error {
|
|
|
unionid := common.ObjToString(sessVal["unionid"])
|
|
|
openid := common.ObjToString(sessVal["openid"])
|
|
|
source := common.ObjToString(sessVal["source"])
|
|
|
- if m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone, source) {
|
|
|
- return m.createSession(unionid, openid, jsonPram.MiniProgramInfo.Code)
|
|
|
+ if createRes := m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone, source); createRes > 0 {
|
|
|
+ status := m.createSession(unionid, openid, jsonPram.MiniProgramInfo.Code)
|
|
|
+ nsqPath, _ := config.Sysconfig["nsq"].(string)
|
|
|
+ nsq_topic, _ := config.Sysconfig["nsq_topic"].(string)
|
|
|
+ sessVal := m.Session().GetMultiple()
|
|
|
+ mgoUserId := common.ObjToString(sessVal["mgoUserId"])
|
|
|
+ if createRes == 1 {
|
|
|
+ if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, jy.Jyapp_phone_register, mgoUserId, jy.Jyapp_node1, nil); err != nil {
|
|
|
+ log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, mgoUserId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if createRes == 2 {
|
|
|
+ if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
+ "code": 1007,
|
|
|
+ "types": "bindPhone",
|
|
|
+ "num": 50,
|
|
|
+ "baseUserId": sessVal["base_user_id"],
|
|
|
+ "positionId": sessVal["positionId"],
|
|
|
+ "isOnlyBind": true,
|
|
|
+ }); err != nil {
|
|
|
+ log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, sessVal["mgoUserId"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return status
|
|
|
}
|
|
|
return 0
|
|
|
}()
|
|
@@ -224,30 +246,23 @@ func (m *MiniProgram) check(jsonParam *JsonParam) bool {
|
|
|
}
|
|
|
|
|
|
//
|
|
|
-func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source string) bool {
|
|
|
+func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source string) int {
|
|
|
if phone == "" || unionid == "" || openid == "" {
|
|
|
log.Println("phone", phone, "unionid", unionid, "openid", openid, "创建用户失败,缺少phone、unionid、openid")
|
|
|
- return false
|
|
|
- }
|
|
|
- if countRes, countErr := public.MQFW.CountByErr("user", map[string]interface{}{"i_appid": 2, "s_unionid": unionid}); countErr != nil {
|
|
|
- log.Println(miniprogramCode, unionid, openid, phone, "查询mog库user表unionid总数失败")
|
|
|
- return false
|
|
|
- } else if countRes > 0 {
|
|
|
- public.MQFW.Update("user", map[string]interface{}{"i_appid": 2, "s_unionid": unionid}, map[string]interface{}{"$set": map[string]interface{}{"s_phone": phone, "l_bindphonetime": gtime.Timestamp()}}, false, false)
|
|
|
- return true
|
|
|
+ return 0
|
|
|
}
|
|
|
- users, ok := public.MQFW.Find("user", map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "$or": []map[string]interface{}{
|
|
|
- map[string]interface{}{
|
|
|
- "s_phone": phone,
|
|
|
- }, map[string]interface{}{
|
|
|
- "s_m_phone": phone,
|
|
|
- },
|
|
|
- },
|
|
|
- }, `{"s_phone":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
|
+ users, ok := public.MQFW.Find("user", map[string]interface{}{"i_appid": 2, "s_unionid": unionid}, `{"_id":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
|
if ok && (users == nil || len(*users) == 0) {
|
|
|
- users, ok = public.MQFW.Find("user", map[string]interface{}{"i_appid": 2, "s_unionid": unionid}, `{"_id":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
|
+ users, ok = public.MQFW.Find("user", map[string]interface{}{
|
|
|
+ "i_appid": 2,
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "s_phone": phone,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "s_m_phone": phone,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }, `{"s_phone":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
|
}
|
|
|
nowUnix := gtime.Timestamp()
|
|
|
if !ok {
|
|
@@ -270,12 +285,6 @@ func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source
|
|
|
miniprogramCode + "_source": source,
|
|
|
})
|
|
|
if _id != "" {
|
|
|
- nsqPath, _ := config.Sysconfig["nsq"].(string)
|
|
|
- nsq_topic, _ := config.Sysconfig["nsq_topic"].(string)
|
|
|
- err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, jy.Jyapp_phone_register, _id, jy.Jyapp_node1, nil)
|
|
|
- if err != nil {
|
|
|
- log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, _id)
|
|
|
- }
|
|
|
public.Mgo_Log.Save("register_log", map[string]interface{}{
|
|
|
"userid": _id,
|
|
|
"phone": phone,
|
|
@@ -287,7 +296,7 @@ func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source
|
|
|
"create_time": gtime.Timestamp(),
|
|
|
"code": miniprogramCode,
|
|
|
})
|
|
|
- return true
|
|
|
+ return 1
|
|
|
} else {
|
|
|
log.Println(miniprogramCode, unionid, openid, phone, "mgo库user表用户创建失败")
|
|
|
}
|
|
@@ -308,10 +317,10 @@ func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source
|
|
|
set["s_unionid"] = unionid
|
|
|
}
|
|
|
if public.MQFW.Update("user", map[string]interface{}{"_id": (*users)[0]["_id"]}, map[string]interface{}{"$set": set}, false, false) {
|
|
|
- return true
|
|
|
+ return 2
|
|
|
}
|
|
|
}
|
|
|
- return false
|
|
|
+ return 0
|
|
|
}
|
|
|
|
|
|
func (m *MiniProgram) createSession(unionid, openid, miniprogramCode string) int {
|