|
@@ -5,9 +5,11 @@ import (
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
"log"
|
|
|
"math"
|
|
|
"mongodb"
|
|
|
+ m "mongodb"
|
|
|
"net/http"
|
|
|
qutil "qfw/util"
|
|
|
"qfw/util/redis"
|
|
@@ -16,8 +18,6 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
"util"
|
|
|
-
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -935,10 +935,23 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
|
|
|
}
|
|
|
//log.Println(areaCount)
|
|
|
isOk := false
|
|
|
+ set := map[string]interface{}{
|
|
|
+ "o_vipjy.i_trial": -1, //已激活试用
|
|
|
+ "o_vipjy.o_area": buyArea, //设置地区
|
|
|
+ "o_vipjy.o_buyset": newBuySet, //购买内容 城市、省份、行业数量
|
|
|
+ "l_vip_starttime": vipStartTime.Unix(), //开始时间
|
|
|
+ "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
+ "i_vip_status": qutil.If(isTrial, -2, 2), //1试用 2正式 -2 试用到期
|
|
|
+ "i_vip_expire_tip": 0, //消息提示初始化
|
|
|
+ "o_vipjy.a_buyerclass": []interface{}{}, //设置行业
|
|
|
+ }
|
|
|
if param.BuySubject == "1" {
|
|
|
- isOk = StartSubVip(param.Phone, buyArea, newBuySet, vipStartTime, endTime, isTrial, userId)
|
|
|
+ isOk = StartSubVip(set, userId)
|
|
|
} else {
|
|
|
- isOk = UpdateRule(entId, vipStartTime, endTime, qutil.If(isTrial, -2, 2), 1)
|
|
|
+
|
|
|
+ isOk = UpdateRule(entId, map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ })
|
|
|
}
|
|
|
return isOk, qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
|
|
|
}
|
|
@@ -1137,6 +1150,7 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
|
|
|
log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
|
|
|
return false, "自动创建企业信息失败"
|
|
|
}
|
|
|
+ userId = userPositionId
|
|
|
}
|
|
|
|
|
|
b := util.JysqlDB.ExecTx("修改订单信息和合同信息", func(tx *sql.Tx) bool {
|
|
@@ -1263,7 +1277,6 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
|
|
|
ClearBigVipUserPower(userId)
|
|
|
return true, ""
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
//0 购买 1 续费 2 升级
|
|
|
if param.VipType == 0 {
|
|
@@ -1282,12 +1295,13 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
|
|
|
util.MQFW.UpdateById("user", userId, bson.M{
|
|
|
"$set": set,
|
|
|
})
|
|
|
- jyRedis := config.SysConfigs.JyRedis
|
|
|
- redis.Del("newother", jyRedis+userId)
|
|
|
- redis.Del("newother", "pl_indexMessage_"+userId)
|
|
|
+ ClearBigVipUserPower(userId)
|
|
|
return true, ""
|
|
|
} else {
|
|
|
- UpdateRule(entId, time.Now(), time.Now(), 0, 1)
|
|
|
+ UpdateRule(entId, map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ })
|
|
|
+ ClearBigVipUserPower(userId)
|
|
|
return true, ""
|
|
|
}
|
|
|
}
|
|
@@ -1298,9 +1312,23 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
|
|
|
isTrial = true
|
|
|
}
|
|
|
if param.UpdateType == 0 {
|
|
|
+ set := map[string]interface{}{
|
|
|
+ "o_vipjy.i_trial": -1, //已激活试用
|
|
|
+ "o_vipjy.o_area": buyArea, //设置地区
|
|
|
+ "o_vipjy.o_buyset": newBuySet, //购买内容 城市、省份、行业数量
|
|
|
+ "l_vip_starttime": vipStartTime.Unix(), //开始时间
|
|
|
+ "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
+ "i_vip_status": qutil.If(isTrial, -2, 2), //1试用 2正式 -2 试用到期
|
|
|
+ "i_vip_expire_tip": 0, //消息提示初始化
|
|
|
+ "o_vipjy.a_buyerclass": []interface{}{}, //设置行业
|
|
|
+ }
|
|
|
isOk := false
|
|
|
if param.BuySubject == "1" {
|
|
|
- isOk = StartSubVip(param.Phone, buyArea, newBuySet, vipStartTime, endTime, isTrial, userId)
|
|
|
+ isOk = StartSubVip(set, userId)
|
|
|
+ } else {
|
|
|
+ isOk = UpdateRule(entId, map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ })
|
|
|
}
|
|
|
return isOk, qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
|
|
|
} else {
|
|
@@ -1322,6 +1350,27 @@ func ClearBigVipUserPower(userId string) bool {
|
|
|
// 当大会员状态改变时清除此状态
|
|
|
func ClearBigVipUserPower(userId string) {
|
|
|
if mongodb.IsObjectIdHex(userId) {
|
|
|
+ user_id := userId
|
|
|
+ userDatas, ok := util.MQFW.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 {
|
|
|
+ user_id := m.BsonIdToSId(v["_id"])
|
|
|
+ userData, ok := util.MQFW.FindById("user", user_id, `"base_user_id":1`)
|
|
|
+ if userData != nil && len(*userData) > 0 && ok {
|
|
|
+ baseUserId := qutil.Int64All((*userData)["base_user_id"])
|
|
|
+ positionData := util.BaseDB.FindOne(util.BasePosition, map[string]interface{}{
|
|
|
+ "type": 0,
|
|
|
+ "ent_id": 0,
|
|
|
+ "user_id": baseUserId,
|
|
|
+ }, "id", "")
|
|
|
+ if positionData != nil && len(*positionData) > 0 {
|
|
|
+ user_id = qutil.InterfaceToStr((*positionData)["id"])
|
|
|
+ redis.Del("newother", config.SysConfigs.BigmemberKey+user_id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
//通过mongo查找职位标识
|
|
|
userData, ok := util.MQFW.FindById("user", userId, `"base_user_id":1`)
|
|
|
if userData != nil && len(*userData) > 0 && ok {
|
|
@@ -1343,32 +1392,24 @@ func ClearBigVipUserPower(userId string) {
|
|
|
redisMenuKeyAPP := fmt.Sprintf(RedisMenuKeyAPP, userId)
|
|
|
userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, time.Now().Day(), userId)
|
|
|
redis.Del(NewOther, cacheKey)
|
|
|
+ redis.Del("newother", config.SysConfigs.BigmemberKey+userId)
|
|
|
+ redis.Del(NewOther, fmt.Sprintf("user_power_info_%s", userId))
|
|
|
redis.Del(NewOther, baseInfoCacheKey)
|
|
|
redis.Del(NewOther, redisMenuKeyPC)
|
|
|
redis.Del(NewOther, redisMenuKeyWX)
|
|
|
redis.Del(NewOther, redisMenuKeyAPP)
|
|
|
redis.Del(NewOther, userPowerRedisKey)
|
|
|
+ redis.Del(NewOther, "pl_indexMessage_"+userId)
|
|
|
}
|
|
|
|
|
|
// 开始使用超级订阅
|
|
|
-func StartSubVip(phone string, area map[string]interface{}, newBuyset SubvipBuySet, startTime, endTime time.Time, isTrial bool, userId string) bool {
|
|
|
- set := map[string]interface{}{
|
|
|
- "o_vipjy.i_trial": -1, //已激活试用
|
|
|
- "o_vipjy.o_area": area, //设置地区
|
|
|
- "o_vipjy.o_buyset": newBuyset, //购买内容 城市、省份、行业数量
|
|
|
- "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- "i_vip_status": qutil.If(isTrial, -2, 2), //1试用 2正式 -2 试用到期
|
|
|
- "i_vip_expire_tip": 0, //消息提示初始化
|
|
|
- "o_vipjy.a_buyerclass": []interface{}{}, //设置行业
|
|
|
- }
|
|
|
+func StartSubVip(set map[string]interface{}, userId string) bool {
|
|
|
isOk := util.MQFW.UpdateById("user", userId, bson.M{
|
|
|
"$set": set,
|
|
|
})
|
|
|
go func() {
|
|
|
MergeKws(userId)
|
|
|
}()
|
|
|
- redis.Del(NewOther, "pl_indexMessage_"+userId)
|
|
|
ClearBigVipUserPower(userId)
|
|
|
if isOk {
|
|
|
return true
|
|
@@ -1841,28 +1882,66 @@ func GetNameList(name string) (rs *[]map[string]interface{}) {
|
|
|
}
|
|
|
|
|
|
// 企业订阅时间修改
|
|
|
-func UpdateRule(entId int, startTime, endTime time.Time, status interface{}, types int) bool {
|
|
|
+func UpdateRule(entId int, update map[string]interface{}) bool {
|
|
|
ok := false
|
|
|
if entId > 0 {
|
|
|
- set := map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{},
|
|
|
- }
|
|
|
- if types == 1 {
|
|
|
- set["$set"] = map[string]interface{}{
|
|
|
- "l_vip_starttime": startTime.Unix(),
|
|
|
- "l_vip_endtime": endTime.Unix(),
|
|
|
- "i_vip_status": qutil.Int64All(status),
|
|
|
+ up1, up2 := map[string]interface{}{}, map[string]interface{}{}
|
|
|
+ var tp int
|
|
|
+ for k, v := range update {
|
|
|
+ vm, ok := v.(map[string]interface{})
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
}
|
|
|
- } else {
|
|
|
- set["$set"] = map[string]interface{}{
|
|
|
- "l_member_starttime": startTime.Unix(),
|
|
|
- "l_member_endtime": endTime.Unix(),
|
|
|
- "i_member_status": qutil.Int64All(status),
|
|
|
+ up11, up22 := map[string]interface{}{}, map[string]interface{}{}
|
|
|
+ key := ""
|
|
|
+ for kk, vv := range vm {
|
|
|
+ if (key == "" || key == "o_jy") && (kk == "o_jy" || strings.HasPrefix(kk, "o_jy.")) {
|
|
|
+ key = "o_jy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 2
|
|
|
+ } else if (key == "" || key == "o_vipjy") && (kk == "o_vipjy" || strings.HasPrefix(kk, "o_vipjy.")) {
|
|
|
+ key = "o_vipjy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 1
|
|
|
+ } else if (key == "" || key == "o_member_jy") && (kk == "o_member_jy" || strings.HasPrefix(kk, "o_member_jy.")) {
|
|
|
+ key = "o_member_jy"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 1
|
|
|
+ } else if (key == "" || key == "o_entniche") && (kk == "o_entniche" || strings.HasPrefix(kk, "o_entniche.")) {
|
|
|
+ key = "o_entniche"
|
|
|
+ up22[strings.ReplaceAll(kk, key, "o_entniche")] = vv
|
|
|
+ tp = 0
|
|
|
+ } else {
|
|
|
+ up11[kk] = vv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(up11) > 0 {
|
|
|
+ up1[k] = up11
|
|
|
+ }
|
|
|
+ if len(up22) > 0 {
|
|
|
+ up2[k] = up22
|
|
|
}
|
|
|
}
|
|
|
- ok = util.MQFW.Update("ent_user", map[string]interface{}{
|
|
|
- "i_entid": entId,
|
|
|
- }, set, false, true)
|
|
|
+ ok1, ok2 := false, false
|
|
|
+ log.Println(up1)
|
|
|
+ if len(up1) > 0 {
|
|
|
+ ok1 = util.MQFW.Update("ent_user", map[string]interface{}{
|
|
|
+ "i_entid": entId,
|
|
|
+ "i_userid": map[string]interface{}{
|
|
|
+ "$exists": false,
|
|
|
+ },
|
|
|
+ }, up1, true, false)
|
|
|
+ }
|
|
|
+ if len(up2) > 0 {
|
|
|
+ ok2 = util.MQFW.Update("entniche_rule", map[string]interface{}{
|
|
|
+ "i_entid": entId,
|
|
|
+ "i_userid": map[string]interface{}{
|
|
|
+ "$exists": false,
|
|
|
+ },
|
|
|
+ "i_type": tp,
|
|
|
+ }, up2, true, false)
|
|
|
+ }
|
|
|
+ return ok1 || ok2
|
|
|
}
|
|
|
return ok
|
|
|
}
|