123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package utility
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/usercenter"
- "context"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/util/gconv"
- "net/http"
- "time"
- )
- var (
- ctx = context.Background()
- )
- // GetCreateUserData 查询用户 不存在注册用户 isEntSign 是否需要注册企业信息(避免校验调用) 如entId不为0代办已注册企业信息
- func GetCreateUserData(phone, companyName, orderCode string, entId int, isEntSign bool) map[string]interface{} {
- data := make(map[string]interface{})
- userData, ok := MG.DB().FindOne("user", map[string]interface{}{
- "$or": []map[string]interface{}{
- {"s_phone": phone},
- {"s_m_phone": phone},
- },
- })
- if ok && userData != nil && len(*userData) > 0 {
- data = *userData
- } else {
- id := MG.DB().Save("user", map[string]interface{}{
- "i_appid": 2,
- "s_phone": phone,
- "s_password": "",
- "l_registedate": time.Now().Unix(),
- "i_ts_guide": 2,
- "o_jy": map[string]interface{}{
- "i_wxpush": 1,
- "i_apppush": 1,
- "i_ratemode": 2,
- "l_modifydate": time.Now().Unix(),
- },
- "s_regsource": "qmx_admin",
- })
- if id != "" {
- formdata := map[string]interface{}{
- "appid": 10000,
- "phone": phone,
- "password": "",
- }
- ck := &http.Cookie{}
- usercenter.AddBaseUser(*MG.DB(), g.Cfg().MustGet(ctx, "userCenterUrl").String(), id, formdata, ck)
- SaveUserLog(id, phone)
- uData, _ := MG.DB().FindById("user", id, "")
- data = *uData
- }
- }
- var userPositionId string
- //查找baseUserId
- baseUserId := common.Int64All(data["base_user_id"])
- positionData, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf(`SELECT s_name FROM base_position WHERE type=1 and user_id='%d' and ent_id=%d`, baseUserId, entId))
- if !positionData.IsEmpty() {
- userPositionId = gconv.String(positionData.Map()["id"])
- }
- //校验企业用户是否创建
- if entId == 0 && isEntSign {
- entId, _, userPositionId = AutomaticallyCreatingEnt(companyName, phone, orderCode, common.InterfaceToStr(data["_id"]))
- }
- data["entId"] = entId
- data["userPositionId"] = userPositionId
- return data
- }
- // 用户注册日志保存
- func SaveUserLog(userid, phone string) {
- data := map[string]interface{}{
- "userid": userid,
- "phone": phone,
- "way": "phone",
- "system": "pc",
- "source": "background",
- "create_time": date.NowFormat(date.Date_Full_Layout),
- }
- MG.DB().Save("register_log", data)
- }
- var getPositionIdByMongoUserId = func(mgoUserId string) int64 {
- userData, ok := MG.DB().FindById("user", mgoUserId, `"base_user_id":1`)
- if userData != nil && len(*userData) > 0 && ok {
- baseUserId := common.Int64All((*userData)["base_user_id"])
- positionData, _ := g.DB("base").GetOne(ctx, "SELECT id FROM base_position WHERE type=0 and ent_id=0 and user_id=?", baseUserId)
- if !positionData.IsEmpty() {
- return gconv.Int64(positionData.Map()["id"])
- }
- }
- return -1
- }
- func ClearBigVipUserPower(ctx context.Context, userId string) {
- var (
- powerChacheKey = g.Cfg().MustGet(ctx, "bigmemberKey", "bigmember_power_3_").String()
- IsGetUserBaseInfoRedisKey = "baseinfo_%s"
- RedisMenuKeyPC = "jy_workdesktopmenu_10000_PC_menu1_%s" //剑鱼appid:10000
- RedisMenuKeyWX = "jy_workdesktopmenu_10000_WX_menu1_%s" //剑鱼appid:10000
- RedisMenuKeyAPP = "jy_workdesktopmenu_10000_APP_menu1_%s" //剑鱼appid:10000
- UserPowerRedisKey = "jy_userpowerredis_10000_%d_%s" //工作桌面 用户功能缓存(类似bigmember_power_3_%s)
- )
- if mongodb.IsObjectIdHex(userId) {
- user_id := userId
- //大会员主账号清理
- userDatas, ok := MG.DB().Find("user", map[string]interface{}{"s_member_mainid": user_id, "i_member_sub_status": 1}, nil, nil, false, -1, -1)
- if ok && userDatas != nil && len(*userDatas) > 0 {
- for _, v := range *userDatas {
- if pId := getPositionIdByMongoUserId(mongodb.BsonIdToSId(v["_id"])); pId > 0 {
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("%s%d", powerChacheKey, pId))
- }
- }
- }
- //通过mongo查找职位标识
- if pId := getPositionIdByMongoUserId(userId); pId > 0 {
- userId = fmt.Sprint(pId)
- }
- }
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(powerChacheKey, userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_workdesktopmenu_10000_menu1_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_userpowerredis_10000_17_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_workdesktopmenu_10000_menu2_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_workdesktopmenu_10000_PC_menu2_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_workdesktopmenu_10000_WX_menu2_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("jy_workdesktopmenu_10000_APP_menu2_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf("user_power_info_%s", userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(IsGetUserBaseInfoRedisKey, userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(RedisMenuKeyPC, userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(RedisMenuKeyWX, userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(RedisMenuKeyAPP, userId))
- _, _ = g.Redis("newother").Del(ctx, fmt.Sprintf(UserPowerRedisKey, time.Now().Day(), userId))
- _, _ = g.Redis("newother").Del(ctx, "pl_indexMessage_"+userId)
- }
- func PayUserIdentitySwitchRedis(mgoUserId string, data map[string]interface{}) {
- key := fmt.Sprintf("jy_identitySwitch_%s", mgoUserId)
- _ = g.Redis("newother").SetEX(ctx, key, data, -1)
- }
|