lianbingjie hace 2 años
padre
commit
d43ec64642

+ 0 - 1
src/customerService/customService.go

@@ -121,7 +121,6 @@ func CustomSendMsgService(param *customMsg, sendStatus int, loginUserName string
 				"update_user":   loginUserName,
 				"menu_name":     param.MenuName,
 			})
-
 			var args []interface{}
 			log.Println("前端传入用户数量:", len(param.UserArr))
 			for _, val := range param.UserArr {

+ 31 - 18
src/order/orderManageController.go

@@ -1424,7 +1424,7 @@ func UpdateBigOrder(context *admin.Context) (interface{}, error) {
 			if strings.HasPrefix(qutil.ObjToString(res["user_phone"]), "9") {
 				util.MQFW.Del("user", map[string]interface{}{"s_phone": qutil.ObjToString(res["user_phone"])})
 				util.JysqlDB.Delete("user", map[string]interface{}{"user_id": qutil.ObjToString(res["user_id"])})
-			} else if param.BuySubject != "2" || entServiceRecycle(qutil.IntAll(res["ent_id"]), qutil.InterfaceToStr(res["user_phone"]), param.OrderCode) {
+			} else if param.BuySubject == "1" {
 				sets := map[string]interface{}{
 					"i_member_status":    qutil.If(dateType == 1, param.Level, -param.Level),
 					"i_member_starttime": time.Now().Unix(),
@@ -1442,10 +1442,12 @@ func UpdateBigOrder(context *admin.Context) (interface{}, error) {
 				util.MQFW.UpdateById("user", res["user_id"], set)
 				sql := "update bigmember_service_user set i_status = -1 where  s_userid = ?"
 				util.JysqlDB.UpdateOrDeleteBySql(sql, res["user_id"])
-				RedisDel(qutil.ObjToString(res["user_id"]))
 				ClearBigVipUserPower(qutil.ObjToString(res["user_id"]))
 			}
 			util.JysqlDB.Update("dataexport_order", map[string]interface{}{"user_phone": qutil.ObjToString(res["user_phone"])}, map[string]interface{}{"user_phone": param.Phone, "user_id": userId})
+			if param.BuySubject == "2" {
+
+			}
 		} else {
 			userId = qutil.ObjToString(res["user_id"])
 		}
@@ -1717,7 +1719,6 @@ func MyUpdateBigOrder(context *admin.Context) (interface{}, error) {
 					util.MQFW.UpdateById("user", res["user_id"], set)
 					sql := "update bigmember_service_user set i_status = -1 where  s_userid = ?"
 					util.JysqlDB.UpdateOrDeleteBySql(sql, res["user_id"])
-					RedisDel(qutil.ObjToString(res["user_id"]))
 					ClearBigVipUserPower(userId)
 				}
 			}
@@ -2109,7 +2110,6 @@ func CreateSubOrder(context *admin.Context) (interface{}, error) {
 		} else {
 			return nil, errors.New("创建子账号订单失败")
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 	}
 
@@ -2309,7 +2309,6 @@ func UpdateSubOrder(context *admin.Context) (interface{}, error) {
 		} else {
 			return nil, errors.New("修改子账号订单失败")
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 		saveData := map[string]interface{}{
 			"operator":      context.User.Username,
@@ -2625,7 +2624,6 @@ func CreateSupplyOrder(context *admin.Context) (interface{}, error) {
 				}
 			}
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 	}
 	return nil, nil
@@ -2821,7 +2819,6 @@ func UpdateSupplyOrder(context *admin.Context) (interface{}, error) {
 				"contract_archive_num":    param.ContractArchiveNum,
 			})
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 		saveData := map[string]interface{}{
 			"operator":      context.User.Username,
@@ -3069,7 +3066,6 @@ func MyUpdateSupplySubOrder(context *admin.Context) (interface{}, error) {
 				"contract_archive_num":    param.ContractArchiveNum,
 			})
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 		// 增加审核轨迹
 		saveData := map[string]interface{}{
@@ -3661,7 +3657,7 @@ func BackOrderAuditList(context *admin.Context) (interface{}, error) {
 }
 
 // AutomaticallyCreatingEnt 审批主体企业订单 已完成订单创建企业信息
-func AutomaticallyCreatingEnt(name, phone, orderCode string, orderStatus int) (int, error) {
+func AutomaticallyCreatingEnt(name, phone, orderCode string, orderStatus int, userId string) (int, error, string) {
 	var (
 		entId int
 	)
@@ -3669,12 +3665,12 @@ func AutomaticallyCreatingEnt(name, phone, orderCode string, orderStatus int) (i
 	reg := regexp.MustCompile(regRuler)
 	//非完成订单/非正常手机号/name空企业 不操作企业信息
 	if orderStatus != 1 || !reg.MatchString(phone) || name == "" {
-		return 0, nil
+		return 0, nil, ""
 	}
 	log.Println("config.SysConfigs.CreatEntRpc", config.SysConfigs.CreatEntRpc)
 	r, err := rpc.DialHTTP("tcp", config.SysConfigs.CreatEntRpc)
 	if err != nil {
-		return entId, err
+		return entId, err, ""
 	}
 	defer r.Close()
 	param := frpc.CreateEntReq{
@@ -3685,14 +3681,32 @@ func AutomaticallyCreatingEnt(name, phone, orderCode string, orderStatus int) (i
 	res := new(frpc.CreateEntRes)
 	err = r.Call("CreateEnt.AutomaticallyCreateEnt", param, &res)
 	if err != nil {
-		return entId, err
+		return entId, err, ""
 	}
 	log.Println("config.SysConfigs.CreatEntRpc", config.SysConfigs.CreatEntRpc, res)
 	if res == nil || res.Status == 1 { //出错
 		log.Println("调用rpc出错")
-		return entId, errors.New("调用rpc出错")
+		return entId, errors.New("调用rpc出错"), ""
 	}
-	return res.Id, nil
+	//职位标识获取
+	userPositionId := ""
+	if res.Id != 0 {
+		//查找baseUserId
+		userData, ok := util.MQFW.FindById("user", userId, `"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":    1,
+				"user_id": baseUserId,
+			}, "id", "")
+			if positionData != nil && len(*positionData) > 0 {
+				userPositionId = fmt.Sprint(qutil.Int64All((*positionData)["id"]))
+			}
+
+		}
+
+	}
+	return res.Id, nil, userPositionId
 }
 
 // EntLicense 订单企业授权信息记录
@@ -3742,10 +3756,9 @@ func EntLicense(entId, empowerCount, provinceCount, orderId, userCount int, prod
 			util.JysqlDB.Insert("entniche_order", inData)
 			if userCount > 0 {
 				if user != nil && len(*user) > 0 {
-					if util.JysqlDB.Count("entniche_power", map[string]interface{}{"ent_id": entId, "ent_user_id": (*user)["id"], "status": -1}) > 0 {
-						util.JysqlDB.Update("entniche_power", map[string]interface{}{"ent_id": entId, "ent_user_id": (*user)["id"]},
-							map[string]interface{}{"status": 1, "update_time": time.Now(), "wait_empower_id": id})
-					} else {
+					sql := "SELECT  COUNT(1)  FROM  entniche_power a  INNER JOIN entniche_wait_empower b ON a.wait_empower_id = b.id  where  a.ent_id=" + fmt.Sprint(qutil.Int64All(entId)) + " and a.ent_user_id=" + qutil.InterfaceToStr((*user)["id"]) + " and  a.`status`=1 and  b.product_type='" + productType + "'"
+					number := util.JysqlDB.CountBySql(sql)
+					if number == 0 {
 						util.JysqlDB.Insert("entniche_power", map[string]interface{}{"wait_empower_id": id,
 							"ent_id": entId, "ent_user_id": (*user)["id"], "status": 1, "update_time": time.Now(), "create_time": time.Now()})
 					}

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 483 - 473
src/order/orderManageService.go


+ 0 - 3
src/order/otherOrderController.go

@@ -1059,7 +1059,6 @@ func UpdateSalesperson(context *admin.Context) (interface{}, error) {
 		} else {
 			log.Println("订单表修改用户手机号失败", param.OrderCode, param.Phone)
 		}
-		RedisDel(userId)
 		ClearBigVipUserPower(userId)
 		return map[string]interface{}{"status": ok}, nil
 	}
@@ -1144,9 +1143,7 @@ func UpdateSalesperson(context *admin.Context) (interface{}, error) {
 			log.Println("未找到与之关联的订单", param.OrderCode, param.UserPhone, qutil.FormatDateByInt64(&createMin, qutil.Date_Full_Layout), qutil.FormatDateByInt64(&createMax, qutil.Date_Short_Layout))
 
 		}
-
 		util.MQFW.UpdateById("user", param.UserId, set)
-		RedisDel(param.UserId)
 		ClearBigVipUserPower(param.UserId)
 	}
 

+ 224 - 45
src/order/otherOrderService.go

@@ -6,9 +6,11 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"go.mongodb.org/mongo-driver/bson"
 	"log"
 	"math"
 	"mongodb"
+	m "mongodb"
 	"net/http"
 	qutil "qfw/util"
 	"qfw/util/redis"
@@ -17,8 +19,6 @@ import (
 	"strings"
 	"time"
 	"util"
-
-	"go.mongodb.org/mongo-driver/bson"
 )
 
 const (
@@ -30,6 +30,7 @@ const (
 	RedisMenuKeyWX            = "jy_workdesktopmenu_10000_WX_%s"  //剑鱼appid:10000
 	RedisMenuKeyAPP           = "jy_workdesktopmenu_10000_APP_%s" //剑鱼appid:10000
 	UserPowerRedisKey         = "jy_userpowerredis_10000_%d_%s"   //工作桌面 用户功能缓存(类似bigmember_power_3_%s)
+
 )
 
 // 插入合同表信息和订单表信息
@@ -130,12 +131,14 @@ func createOtherOrder(param *CreateOtherOrderParams, code string) bool {
 		}
 		if param.BuySubject == "2" {
 			insertData["buy_subject"] = 2
-			entId, err := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+			entId, err, userPositionId := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, param.UserId)
 			if err != nil {
 				log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 				return false
 			} else {
 				insertData["ent_id"] = entId
+				param.UserId = fmt.Sprint(qutil.Int64All(userPositionId))
+				insertData["user_id"] = userPositionId
 			}
 		} else {
 			insertData["buy_subject"] = 1
@@ -309,12 +312,14 @@ func createEntnicheOrder(param *CreateOtherOrderParams, code string) bool {
 		}
 		if param.BuySubject == "2" {
 			insertData["buySubject"] = 2
-			entId, err := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+			entId, err, userPositionId := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, param.UserId)
 			if err != nil {
 				log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 				return false
 			} else {
 				insertData["entId"] = entId
+				insertData["user_id"] = userPositionId
+				param.UserId = userPositionId
 			}
 		} else {
 			insertData["buySubject"] = 1
@@ -407,12 +412,14 @@ func updateOtherOrder(param *CreateOtherOrderParams, code string, returnStatus i
 		}
 		if param.BuySubject == "2" {
 			insertData["buySubject"] = 2
-			entId, err := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+			entId, err, userPositionId := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, param.UserId)
 			if err != nil {
 				log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 				return false
 			} else {
 				insertData["entId"] = entId
+				param.UserId = userPositionId
+				insertData["user_id"] = userPositionId
 			}
 		} else {
 			insertData["buySubject"] = 1
@@ -573,12 +580,14 @@ func updateEntnicheOrder(param *CreateOtherOrderParams, code string, returnStatu
 		}
 		if param.BuySubject == "2" {
 			insertData["buySubject"] = 2
-			entId, err := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+			entId, err, userPositionId := AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, param.UserId)
 			if err != nil {
 				log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 				return false
 			} else {
 				insertData["entId"] = entId
+				param.UserId = userPositionId
+				insertData["user_id"] = userPositionId
 			}
 		} else {
 			insertData["buySubject"] = 1
@@ -769,11 +778,12 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 		payWay = ""
 	}
 	var (
-		entId int
-		err   error
+		entId          int
+		err            error
+		userPositionId string
 	)
 	if param.BuySubject == "2" {
-		entId, err = AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+		entId, err, userPositionId = AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, userId)
 		if err != nil {
 			log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 			return false, "自动创建企业信息失败"
@@ -865,6 +875,7 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 		if param.BuySubject == "2" {
 			insertData["buy_subject"] = 2
 			insertData["ent_id"] = entId
+			insertData["user_id"] = userPositionId
 		} else {
 			insertData["buy_subject"] = 1
 		}
@@ -887,9 +898,9 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 			if strings.Contains(param.VipStartTime, "2099") {
 				ss = 4070880000
 			}
-			entService, userCount = EntServiceOpen(userId, param.BuySubject, ss)
 			_d := util.JysqlDB.FindOne("dataexport_order", map[string]interface{}{"order_code": code}, "id,ent_id", "")
 			if _d != nil && len(*_d) > 0 {
+				entService, userCount = EntServiceOpen(qutil.IntAll((*_d)["ent_id"]), param.Phone, param.ProductType, ss)
 				orderId := qutil.IntAll((*_d)["id"])
 				if qutil.IntAll((*_d)["ent_id"]) != 0 && param.Open && param.VipStartTime != "2099-01-01" && param.BuyCount > 0 {
 					regRuler := "^1[3456789]{1}\\d{9}$"
@@ -921,7 +932,24 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 				isTrial = true
 			}
 			//log.Println(areaCount)
-			isOk := StartSubVip(param.Phone, buyArea, newBuySet, vipStartTime, endTime, isTrial, userId)
+			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(set, userId)
+			} else {
+				isOk = UpdateRule(entId, map[string]interface{}{
+					"$set": set,
+				}, param.Phone)
+			}
 			return isOk, qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
 		}
 		// 续费和升级 我的订单-创建订单只生成订单信息不开通权益
@@ -934,6 +962,13 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 				"i_vip_expire_tip": 0,
 				"i_vip_status":     2,
 			}
+			if param.BuySubject != "2" {
+				if !util.MQFW.UpdateById("user", userId,
+					bson.M{"$set": set}) {
+					log.Printf("%s更新结束%d日期出错\n", userId, endTime.Unix())
+					return false, ""
+				}
+			}
 			if !util.MQFW.UpdateById("user", userId,
 				bson.M{"$set": set}) {
 				log.Printf("%s更新结束%d日期出错\n", userId, endTime.Unix())
@@ -954,7 +989,6 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 			}
 			updata := map[string]interface{}{
 				"o_vipjy.o_buyset": newBuySet,
-				// "l_vip_endtime":    endTime.Unix(),//升级不再续费
 				"i_vip_expire_tip": 0,
 				"i_vip_status":     2,
 			}
@@ -964,9 +998,13 @@ func createVipOrder(param *CreateOtherOrderParams, code string) (bool, string) {
 			if vms.Industry != nil {
 				updata["o_vipjy.a_buyerclass"] = vms.Industry //设置行业
 			}
-			if ok := util.MQFW.UpdateById("user", userId, map[string]interface{}{
-				"$set": updata,
-			}); !ok {
+			isOk := true
+			if param.BuySubject != "2" {
+				isOk = util.MQFW.UpdateById("user", userId, map[string]interface{}{
+					"$set": updata,
+				})
+			}
+			if !isOk {
 				log.Printf("%s更新用户出错 %+v\n", userId, updata)
 				return false, ""
 			} else {
@@ -1053,6 +1091,8 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 	if param.Badge != "" {
 		vms.Badge = param.Badge
 	}
+	var vst, vet string
+	userId := ""
 	userData := &map[string]interface{}{}
 	ok := false
 	if param.UserId == "" {
@@ -1060,8 +1100,6 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 	} else {
 		userData, ok = util.MQFW.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(param.UserId)})
 	}
-	userId := ""
-	var vet string
 	if ok && userData != nil && len(*userData) > 0 {
 		userId = mongodb.BsonIdToSId((*userData)["_id"])
 		// st := qutil.Int64All((*userData)["l_vip_starttime"])
@@ -1099,15 +1137,17 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 		}
 	}
 	var (
-		entId int
-		err   error
+		entId          int
+		err            error
+		userPositionId string
 	)
 	if param.BuySubject == "2" {
-		entId, err = AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus)
+		entId, err, userPositionId = AutomaticallyCreatingEnt(param.CompanyName, param.Phone, code, param.OrderStatus, userId)
 		if err != nil {
 			log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", code, err.Error())
 			return false, "自动创建企业信息失败"
 		}
+		userId = userPositionId
 	}
 
 	b := util.JysqlDB.ExecTx("修改订单信息和合同信息", func(tx *sql.Tx) bool {
@@ -1188,6 +1228,7 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 		if param.BuySubject == "2" {
 			insertData["ent_id"] = entId
 			insertData["buy_subject"] = 2
+			insertData["user_id"] = userPositionId
 		} else {
 			insertData["buy_subject"] = 1
 		}
@@ -1215,9 +1256,9 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 			if strings.Contains(param.StartTime, "2099") {
 				ss = 4070880000
 			}
-			entService, userCount = EntServiceOpen(userId, param.BuySubject, ss)
 			_d := util.JysqlDB.FindOne("dataexport_order", map[string]interface{}{"order_code": code}, "id,ent_id", "")
 			if _d != nil && len(*_d) > 0 {
+				entService, userCount = EntServiceOpen(qutil.IntAll((*_d)["ent_id"]), param.Phone, param.ProductType, ss)
 				orderId := qutil.IntAll((*_d)["id"])
 				if qutil.IntAll((*_d)["ent_id"]) != 0 && param.VipStartTime != "2099-01-01" && param.BuyCount > 0 {
 					regRuler := "^1[3456789]{1}\\d{9}$"
@@ -1234,7 +1275,6 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 				ClearBigVipUserPower(userId)
 				return true, ""
 			}
-
 		}
 		//0 购买  1 续费  2 升级
 		if param.VipType == 0 {
@@ -1249,16 +1289,20 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 					"i_vip_expire_tip":     0,                 //消息提示初始化
 					"o_vipjy.a_buyerclass": []interface{}{},   //设置行业
 				}
-				util.MQFW.UpdateById("user", userId, bson.M{
-					"$set": set,
-				})
-				jyRedis := config.SysConfigs.JyRedis
-				redis.Del("newother", jyRedis+userId)
-				//log.Println("err",err)
-				redis.Del("newother", "pl_indexMessage_"+userId)
-				return true, ""
+				if param.BuySubject == "1" {
+					util.MQFW.UpdateById("user", userId, bson.M{
+						"$set": set,
+					})
+					ClearBigVipUserPower(userId)
+					return true, ""
+				} else {
+					UpdateRule(entId, map[string]interface{}{
+						"$set": set,
+					}, param.Phone)
+					ClearBigVipUserPower(userId)
+					return true, ""
+				}
 			}
-
 			//为用户开通超级订阅权限
 			//是否开通超级订阅 -1 试用到期 -2 正式到期 1 试用 2 开通
 			isTrial := false
@@ -1266,7 +1310,24 @@ func updateVipOrder(param *CreateOtherOrderParams, code string, returnStatus int
 				isTrial = true
 			}
 			if param.UpdateType == 0 {
-				isOk := StartSubVip(param.Phone, buyArea, newBuySet, vipStartTime, endTime, isTrial, userId)
+				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(set, userId)
+				} else {
+					isOk = UpdateRule(entId, map[string]interface{}{
+						"$set": set,
+					}, param.Phone)
+				}
 				return isOk, qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
 			} else {
 				return true, ""
@@ -1286,6 +1347,43 @@ 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 = fmt.Sprint(qutil.Int64All((*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 {
+			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 {
+				userId = fmt.Sprint(qutil.Int64All((*positionData)["id"]))
+			}
+		}
+	}
 	cacheKey := fmt.Sprintf(PowerCacheKey, userId)
 	baseInfoCacheKey := fmt.Sprintf(IsGetUserBaseInfoRedisKey, userId)
 	redisMenuKeyPC := fmt.Sprintf(RedisMenuKeyPC, userId)
@@ -1293,32 +1391,27 @@ 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("jy_workdesktopmenu_10000_menu1_%s", userId))
+	redis.Del(NewOther, fmt.Sprintf("jy_userpowerredis_10000_17_%s", userId))
+	redis.Del(NewOther, fmt.Sprintf("jy_workdesktopmenu_10000_menu2_%s", 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
@@ -1343,6 +1436,7 @@ func MergeKws(userId string) {
 				"$set": bson.M{"o_vipjy.i_matchway": 1, "o_vipjy.i_ratemode": 1, "o_vipjy.i_wxpush": 1, "o_vipjy.i_apppush": 1, "o_vipjy.i_projectmatch": 0, "o_vipjy.a_infotype": []string{}, "o_vipjy.a_items": []string{}, "o_vipjy.l_modifydate": time.Now().Unix()},
 			})
 			log.Println(a)
+
 		}
 	}
 }
@@ -1389,7 +1483,6 @@ func UpdateReturnInfo(param *UpdateReturnParams, orderData map[string]interface{
 		invoiceStatus = 3
 	}
 	return util.JysqlDB.ExecTx("编辑回款信息", func(tx *sql.Tx) bool {
-
 		insertData := map[string]interface{}{
 			"order_code":            param.OrderCode,
 			"return_time":           param.ReturnTime,
@@ -1813,6 +1906,92 @@ func GetNameList(name string) (rs *[]map[string]interface{}) {
 
 }
 
+// 企业订阅时间修改
+func UpdateRule(entId int, update map[string]interface{}, phone string) bool {
+	ok := false
+	if entId > 0 && phone != "" {
+		//查找之前数据是否存在
+		userData := util.JysqlDB.FindOne("entniche_user", map[string]interface{}{
+			"ent_id": entId,
+			"phone":  phone,
+		}, `id`, "")
+		if userData == nil {
+			return false
+		}
+		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
+			}
+			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
+			}
+		}
+		ok1, ok2 := false, false
+		//查看之前是否有数据
+		data, ok := util.MQFW.Find("entniche_rule", map[string]interface{}{
+			"i_entid":  entId,
+			"i_userid": (*userData)["id"],
+			"i_type":   tp,
+		}, `{"i_time":-1}`, nil, false, -1, -1)
+		if ok && len(*data) == 0 {
+			up3 := map[string]interface{}{
+				"$set": map[string]interface{}{"o_entniche.i_matchway": 1, "o_entniche.i_ratemode": 1, "o_entniche.i_wxpush": 1, "o_entniche.i_apppush": 1, "o_entniche.i_projectmatch": 0, "o_entniche.a_infotype": []string{}, "o_entniche.a_items": []string{}, "o_entniche.l_modifydate": time.Now().Unix()},
+			}
+			util.MQFW.Update("entniche_rule", map[string]interface{}{
+				"i_entid":  entId,
+				"i_userid": (*userData)["id"],
+				"i_type":   tp,
+			}, up3, true, false)
+		}
+		if len(up1) > 0 {
+			ok1 = util.MQFW.Update("ent_user", map[string]interface{}{
+				"i_entid":  entId,
+				"i_userid": (*userData)["id"],
+			}, up1, true, false)
+		}
+		if len(up2) > 0 {
+			ok2 = util.MQFW.Update("entniche_rule", map[string]interface{}{
+				"i_entid":  entId,
+				"i_userid": (*userData)["id"],
+				"i_type":   tp,
+			}, up2, true, false)
+		}
+		//默认数据处理
+
+		return ok1 || ok2
+	}
+	return ok
+}
+
 var productMap = map[string]interface{}{
 	"1":  "广告",
 	"2":  "结构化数据",

+ 8 - 8
src/order/smallShopTask.go

@@ -123,8 +123,8 @@ func OrderHandle() {
 	}
 	//拉取核销人数据
 	//获取最后一次拉数据时间 ,如果没有,以当天时间凌晨0点为准
-	//start_update_time := "2022-06-10 06:22:44"
-	start_update_time := ""
+	start_update_time := "2022-09-21 10:22:44"
+	/*start_update_time := ""
 	data := util.JysqlDB.SelectBySql("select  update_time from  wxxd_order  ORDER BY update_time  desc LIMIT 1")
 	if len((*data)) > 0 {
 		start_update_time = qutil.ObjToString((*data)[0]["update_time"])
@@ -132,7 +132,7 @@ func OrderHandle() {
 		t := time.Now()
 		addTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
 		start_update_time = addTime.Format(qutil.Date_Full_Layout)
-	}
+	}*/
 	client := &http.Client{}
 	log.Println(start_update_time)
 	var jsonData = strings.NewReader(`{ "start_update_time": "` + start_update_time + `", "end_update_time": "` + time.Now().Format(qutil.Date_Full_Layout) + `", "status":"100", "page": 1, "page_size": 50, "source": 1 //选填,默认1 } `)
@@ -160,14 +160,14 @@ func OrderHandle() {
 	if res.Total_num > 0 {
 		for _, value := range res.Orders {
 			//先判断订单是否创建过
-			data := util.JysqlDB.CountBySql("select  count(id) from  wxxd_order   where   order_id=?", value.Order_id)
-			if data > 0 {
+			//data := util.JysqlDB.CountBySql("select  count(id) from  wxxd_order   where   order_id=?", value.Order_id)
+			/*if data > 0 {
 				log.Println("此", value.Order_id, "订单核销创建过")
 				continue
-			}
-			/*if  value.Order_id!=3202692702381539840{
-				continue
 			}*/
+			if value.Order_id != 3206247405545850880 {
+				continue
+			}
 			orderStatus := false
 			code := fmt.Sprintf("%s%s", time.Now().Format("150405"), qutil.GetRandom(6))
 			param := &CreateOtherOrderParams{}

+ 18 - 18
src/order/suppleSalePerson.go

@@ -353,6 +353,9 @@ func OrdersExamine(context *admin.Context) (interface{}, error) {
 		oldState := cm.IntAll((*order)["audit_status"])
 		newState := 1
 		operatorType := 2
+		if oldState == 3 {
+			return nil, errors.New("订单审核已完成,无需审批")
+		}
 		if param.State == 1 { //审核通过
 			param.Reason = ""
 			if oldState == 1 { //记录为待审核状态
@@ -370,23 +373,22 @@ func OrdersExamine(context *admin.Context) (interface{}, error) {
 			}
 		}
 		var productType string
-		if newState == 3 { //审核通过,开通权益
-			productType = cm.ObjToString((*order)["product_type"])
-			var (
-				userId   string
-				userData *map[string]interface{}
-				ok1      bool
-			)
-			userData, ok1 = util.MQFW.FindOne("user", map[string]interface{}{"s_phone": (*order)["user_phone"]})
+		var (
+			userId   string
+			userData *map[string]interface{}
+			ok1      bool
+		)
+		userData, ok1 = util.MQFW.FindOne("user", map[string]interface{}{"s_phone": (*order)["user_phone"]})
+		if ok1 && userData != nil && len(*userData) > 0 {
+			userId = mongodb.BsonIdToSId((*userData)["_id"])
+		} else {
+			userData, ok1 = util.MQFW.FindOne("user", map[string]interface{}{"s_m_phone": (*order)["user_phone"]})
 			if ok1 && userData != nil && len(*userData) > 0 {
 				userId = mongodb.BsonIdToSId((*userData)["_id"])
-			} else {
-				userData, ok1 = util.MQFW.FindOne("user", map[string]interface{}{"s_m_phone": (*order)["user_phone"]})
-				if ok1 && userData != nil && len(*userData) > 0 {
-					userId = mongodb.BsonIdToSId((*userData)["_id"])
-				}
 			}
-
+		}
+		if newState == 3 { //审核通过,开通权益
+			productType = cm.ObjToString((*order)["product_type"])
 			if productType == "VIP订阅" {
 				vipType := cm.IntAll((*order)["vip_type"])
 				if vipType != 0 {
@@ -586,12 +588,13 @@ func OrdersExamine(context *admin.Context) (interface{}, error) {
 				}
 				if cm.IntAll((*order)["buy_subject"]) == 2 {
 					orderStatus := cm.IntAll(cm.If(cm.IntAll((*order)["order_status"]) == 1, 1, upData["order_status"]))
-					entId, err := AutomaticallyCreatingEnt(cm.InterfaceToStr((*order)["company_name"]), cm.InterfaceToStr((*order)["user_phone"]), param.OrderCode, orderStatus)
+					entId, err, userPositionId := AutomaticallyCreatingEnt(cm.InterfaceToStr((*order)["company_name"]), cm.InterfaceToStr((*order)["user_phone"]), param.OrderCode, orderStatus, userId)
 					if err != nil {
 						log.Printf("AutomaticallyCreatingEnt 自动创建企业信息失败:code:%s,err:%s", param.OrderCode, err.Error())
 						return false
 					} else {
 						upData["ent_id"] = entId
+						upData["user_id"] = userPositionId
 					}
 				}
 				filterMap := map[string]interface{}{}
@@ -694,7 +697,6 @@ func BigMemberSupple(freeSubNum, paySubNum int, startTime, endTime time.Time, us
 			}
 		}
 	}
-	RedisDel(userId)
 	ClearBigVipUserPower(userId)
 	//子账号
 	if newPaySubNum > 0 || newFreeSubNum > 0 {
@@ -1013,7 +1015,6 @@ func SupplePackage(userId string, serverArr []map[string]interface{}) (bool, err
 			return false, errors.New("更新补充包数量失败")
 		}
 	}
-	RedisDel(userId)
 	ClearBigVipUserPower(userId)
 	return true, nil
 }
@@ -1052,7 +1053,6 @@ func SubAccount(userId string, filterMap map[string]interface{}, paySubNum, free
 			}
 		}
 	}
-	RedisDel(userId)
 	ClearBigVipUserPower(userId)
 	return true, nil
 }

+ 1 - 8
src/task/vipTask.go

@@ -1,14 +1,11 @@
 package task
 
 import (
-	"config"
-	"fmt"
 	"go.mongodb.org/mongo-driver/bson"
 	"log"
 	"mongodb"
 	"order"
 	cm "qfw/util"
-	"qfw/util/redis"
 	"time"
 	"util"
 )
@@ -52,11 +49,7 @@ func VipStateTask() {
 			if isOk {
 				go func() {
 					order.MergeKws(_id)
-					jyRedis := config.SysConfigs.JyRedis
-					redis.Del(order.NewOther, jyRedis+_id)
-					redis.Del(order.NewOther, "pl_indexMessage_"+_id)
-					baseInfoCacheKey := fmt.Sprintf(order.IsGetUserBaseInfoRedisKey, _id)
-					redis.Del(order.NewOther, baseInfoCacheKey)
+					order.ClearBigVipUserPower(_id)
 				}()
 			}
 		}

+ 1 - 0
src/util/code.go

@@ -73,4 +73,5 @@ const (
 	BsaeInfo        = "global_common_data.dws_f_bid_baseinfo"
 	LeadprojectPush = "leadproject_push"
 	BaseUser        = "base_user"
+	BasePosition    = "base_position"
 )

+ 5 - 6
src/util/common.go

@@ -50,7 +50,7 @@ type Response struct {
 	Data    int64  `form:"data"`    //订单ID
 }
 
-//中台-创建订单
+// 中台-创建订单
 func JyOrder(methodURL string, params map[string]interface{}) int64 {
 	formValue := make(url.Values)
 	for index, val := range params {
@@ -100,7 +100,7 @@ func HttpPost(path string, param url.Values) (map[string]interface{}, error) {
 	return resMap, nil
 }
 
-//剑鱼数据流量包
+// 剑鱼数据流量包
 type dataExportPackStruct struct{}
 
 var JyDataExportPack dataExportPackStruct
@@ -173,13 +173,12 @@ func MultipleSaveMessage(msg map[string]interface{}, userIds, userNames string)
 	}
 	req.Header.Add("Content-Type", "application/json")
 	res, err := client.Do(req)
-	log.Println("调用中台api返回结果")
-	log.Println(res, err)
-	defer res.Body.Close()
-
 	if err != nil {
 		log.Println("调用批量保存消息接口出错:", err)
+		return
 	}
+	log.Println("调用中台api返回结果", res)
+	defer res.Body.Close()
 	body, err := ioutil.ReadAll(res.Body)
 	//log.Println("body", string(body))
 	var dat map[string]interface{}

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio