package service import ( "encoding/json" "fmt" "github.com/gogf/gf/v2/util/gconv" "log" "math" "strconv" "strings" "time" "bp.jydev.jianyu360.cn/BaseService/entManageApplication/entity" "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient" "context" . "app.yhyue.com/moapp/jybase/date" "app.yhyue.com/moapp/jybase/mongodb" . "bp.jydev.jianyu360.cn/BaseService/entManageApplication/entity" "bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/entmanageapplication" "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck" "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb" "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter" // "github.com/zeromicro/go-zero/core/logx" "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" ) const ( YYSZSYY = "运营商专属应用" ) func AddUsePerson(this *entmanageapplication.AddUsePersonReq) *entmanageapplication.AddUsePersonResp { timeStr, ok, id, msg, code := time.Now().Format("2006-01-02 15:04:05"), false, int64(0), "", int64(0) if this.EntUserId == "" { return &entmanageapplication.AddUsePersonResp{ ErrorCode: -1, ErrorMsg: "添加失败", Data: &entmanageapplication.AddUsePerson{Status: int64(-1)}, } } UserArr := strings.Split(this.EntUserId, ",") sourceData := JyMysql.FindOne(EntnicheWaitEmpower, map[string]interface{}{"id": this.WaitEmpowerId}, "", "") if sourceData != nil && len(*sourceData) > 0 { empower_count := common.IntAll((*sourceData)["empower_count"]) use_count := int(JyMysql.CountBySql(`select count(1) as count from entniche_power where wait_empower_id=? and status=1`, this.WaitEmpowerId)) if empower_count-use_count < len(UserArr) { msg = "购买数量不足" code = int64(-1) } else { for _, v := range UserArr { //过滤空值2023-01-04 if v == "" { continue } // var ( entUserId, _ = strconv.Atoi(v) product_type = common.ObjToString((*sourceData)["product_type"]) isYyszsyy = product_type == YYSZSYY ) if !isYyszsyy { datas := JyMysql.SelectBySql(`select a.end_time from `+EntnicheWaitEmpower+` a inner join `+EntnichePower+` b on (a.product_type<>? and b.ent_user_id=? and b.status=1 and a.id=b.wait_empower_id)`, YYSZSYY, entUserId) if datas != nil && len(*datas) > 0 { end_time := common.ObjToString((*datas)[0]["end_time"]) res, _ := time.ParseInLocation("2006-01-02 15:04:05", end_time, time.Local) if res.Unix() > time.Now().Unix() { msg = "人员已经拥有权限,请先删除原有权限" code = int64(-1) break } } } if JyMysql.CountBySql(`select count(1) as count from `+EntnichePower+` where wait_empower_id=? and ent_id=? and ent_user_id=? and status=?`, this.WaitEmpowerId, this.EntId, entUserId, 1) == 0 { id = JyMysql.Insert(EntnichePower, map[string]interface{}{ "wait_empower_id": this.WaitEmpowerId, "ent_id": this.EntId, "ent_user_id": entUserId, "status": 1, "create_time": timeStr, "update_time": timeStr, }) identity := getPositionId(entUserId) if isYyszsyy { ResourcePowerHandle(identity, 1, common.ObjToString((*sourceData)["start_time"]), common.ObjToString((*sourceData)["end_time"])) } addPower(this.WaitEmpowerId, identity) if identity.UserId != 0 { if dbRes, _ := entity.Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": identity.UserId}, `{"_id":1}`); dbRes != nil && len(*dbRes) > 0 { if mgoUserId := mongodb.BsonIdToSId((*dbRes)["_id"]); mgoUserId != "" { redis.Put(NewOther, fmt.Sprintf("jy_identitySwitch_%s", mgoUserId), map[string]interface{}{ "entId": identity.EntId, "entName": identity.Name, "productType": product_type, }, -1) } } } } } } } status := 0 if ok || id > 0 { status = 1 } return &entmanageapplication.AddUsePersonResp{ ErrorCode: code, ErrorMsg: msg, Data: &entmanageapplication.AddUsePerson{Status: int64(status)}, } } func DelUsePerson(this *entmanageapplication.DelUsePersonReq) *entmanageapplication.AddUsePersonResp { timeStr := time.Now().Format("2006-01-02 15:04:05") ok := JyMysql.Update(EntnichePower, map[string]interface{}{"id": this.EntnichePowerId}, map[string]interface{}{"status": -1, "update_time": timeStr}) delPower(this.EntnichePowerId) status := 0 if ok { status = 1 } return &entmanageapplication.AddUsePersonResp{ ErrorCode: 0, Data: &entmanageapplication.AddUsePerson{Status: int64(status)}, } } func UsePersonList(this *entmanageapplication.UsePersonListReq) *entmanageapplication.UsePersonListResp { sourceData := JyMysql.FindOne(EntnicheWaitEmpower, map[string]interface{}{"id": this.WaitEmpowerId}, "", "") nowTime := time.Now().Format("2006-01-02 15:04:05") q := `select h.product_type,a.id,a.wait_empower_id,c.name,c.phone,c.mail,g.name as department,e.name as role from entniche_power a INNER JOIN entniche_user c on (a.ent_user_id=c.id and a.ent_id = c.ent_id) LEFT JOIN entniche_user_role d on (c.id=d.user_id) LEFT JOIN entniche_role e on (d.role_id=e.id) LEFT JOIN entniche_department_user f on (a.ent_user_id=f.user_id) LEFT JOIN entniche_department g on (g.id=f.dept_id) LEFT JOIN entniche_wait_empower h on (h.id=a.wait_empower_id) where a.status = 1 and a.ent_id = ? and h.end_time >= ?` if common.ObjToString((*sourceData)["product_type"]) == YYSZSYY { q += ` and h.product_type='` + YYSZSYY + `'` } else { q += ` and h.product_type<>'` + YYSZSYY + `'` } q += ` order by a.update_time,a.id desc` data := JyMysql.SelectBySql(q, this.EntId, nowTime) arr := []*entmanageapplication.UsePersonList{} if data != nil && len(*data) > 0 { for _, v := range *data { wait_empower_id := common.Int64All(v["wait_empower_id"]) obj := &entmanageapplication.UsePersonList{ EntnichePowerId: common.Int64All(v["id"]), Name: common.ObjToString(v["name"]), Phone: common.ObjToString(v["phone"]), Email: common.ObjToString(v["mail"]), Department: common.ObjToString(v["department"]), Role: common.ObjToString(v["role"]), } if wait_empower_id == this.WaitEmpowerId { obj.Status = 1 } else { obj.Status = 2 } arr = append(arr, obj) } } return &entmanageapplication.UsePersonListResp{ ErrorCode: 0, Data: arr, } } func BuyProductList(this *entmanageapplication.BuyProductListReq) *entmanageapplication.BuyProductListResp { nowTime := time.Now().Format("2006-01-02 15:04:05") data := JyMysql.SelectBySql(`SELECT a.id,SUM(IF(c.id IS NULL || b.status IS NULL || b.status<0,0,1)) AS use_count,a.empower_count,a.province_count,a.end_time,a.product_type,a.product_key FROM entniche_wait_empower a LEFT JOIN entniche_power b ON (a.ent_id=? AND a.end_time>=? AND a.id=b.wait_empower_id AND b.status=1) LEFT JOIN entniche_user c ON (b.ent_user_id=c.id) WHERE a.ent_id=? AND a.end_time>=? GROUP BY a.id ORDER BY a.create_time DESC`, this.EntId, nowTime, this.EntId, nowTime) arr := []*entmanageapplication.BuyProductList{} if data != nil && len(*data) > 0 { for _, v := range *data { product_type := common.ObjToString(v["product_type"]) if product_type == "VIP订阅" { product_type = "超级订阅" } productTypeSuffix := "" if provinceCount := common.IntAllDef(v["province_count"], -1); provinceCount > 0 { switch provinceCount { case 1: productTypeSuffix = "单省版" default: productTypeSuffix = "省份版" } } var empowerNolimit int64 if product_type == YYSZSYY { empowerNolimit = 1 } obj := &entmanageapplication.BuyProductList{ WaitEmpowerId: common.Int64All(v["id"]), ProductType: fmt.Sprintf("%s%s", product_type, productTypeSuffix), UseCount: common.Int64All(v["use_count"]), EmpowerCount: common.Int64All(v["empower_count"]), ProvinceCount: common.Int64All(v["province_count"]), EndTime: common.ObjToString(v["end_time"]), EmpowerNolimit: empowerNolimit, Key: common.ObjToString(v["product_key"]), } arr = append(arr, obj) } } return &entmanageapplication.BuyProductListResp{ ErrorCode: 0, Data: arr, } } func addPower(waitEmpowerId int64, identity *usercenter.Identity) { data := JyMysql.FindOne(EntnicheOrder, map[string]interface{}{"wait_empower_id": waitEmpowerId}, "", "") if data != nil && len(*data) > 0 { orderId := common.Int64All((*data)["order_detail_id"]) orderData := JyMysql.FindOne(JyOrderDetail, map[string]interface{}{"id": orderId}, "", "") if orderData != nil && len(*orderData) > 0 { productType := common.ObjToString((*orderData)["product_type"]) if productType == "VIP订阅" { log.Println("开通超级订阅", identity.PositionId) set, setEntUser := vipSetMap(*orderData) setRule(identity, set, setEntUser) now1 := time.Now() currentYear, currentMonth, _ := now1.Date() currentLocation := now1.Location() firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation) lastOfMonth := firstOfMonth.AddDate(0, 1, -1) endTime := lastOfMonth.Format("2006-01-02") vipTime := time.Unix(common.Int64All(setEntUser["l_vip_endtime"]), 0).Format("2006-01-02") ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) ResourceCenterRpc.PurchaseUserBalance(ctx, &resourcesCenterclient.Resources{ AppId: "10000", UserId: fmt.Sprint(identity.PositionId), ResourceType: "附件下载包", AccountId: fmt.Sprint(identity.PositionId), Name: "附件下载包", Number: 10, Spec: "个", EndTime: endTime, VipTime: vipTime, Model: 3, }) } else if productType == "大会员" { log.Println("开通大会员", identity.PositionId) set, setEntUser := memberSetMap(identity.PositionId, waitEmpowerId, *orderData) setRule(identity, set, setEntUser) } } } } func GetServerPid() map[int]int { pidMap := map[int]int{} datas := JyMysql.Find("bigmember_service", map[string]interface{}{"i_status": 0}, "id,i_pid", "", 0, 0) if datas != nil && len(*datas) > 0 { for _, v := range *datas { if v["i_pid"] != nil { pidMap[common.IntAll(v["id"])] = common.IntAll(v["i_pid"]) } } } return pidMap } func RedisDel(userId string) { redis.Del(NewOther, "pl_indexMessage_"+userId) delRedisMenuByUserCenter(userId) delRedisByPowerCheck(userId) } // 初始化vip订阅关键词 func MergeKws(entId, entUserId int64) { if entUserId == 0 || entId == 0 { //11-11 取消此操作 return } data, ok := Mgo.FindOneByField("entniche_rule", map[string]interface{}{"i_entid": entId, "i_userid": entUserId}, `{"o_entniche":1,"_id":1}`) var o_entniche map[string]interface{} if ok && data != nil && len(*data) > 0 { o_entniche, _ = (*data)["o_entniche"].(map[string]interface{}) a_items, _ := o_entniche["a_items"].([]interface{}) if a_items == nil { //首次 _id := mongodb.BsonIdToSId((*data)["_id"]) Mgo.UpdateById("entniche_rule", _id, 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()}, }) } } } func delPower(id int64) { datas := JyMysql.SelectBySql(`select b.id,b.product_type,a.ent_user_id,a.ent_id from entniche_power a inner join entniche_wait_empower b on (a.id=? and a.wait_empower_id=b.id)`, id) if datas != nil && len(*datas) > 0 { entUserId := common.IntAll((*datas)[0]["ent_user_id"]) productType := common.ObjToString((*datas)[0]["product_type"]) entId := common.Int64All((*datas)[0]["ent_id"]) identity := getPositionId(entUserId) if productType == YYSZSYY { ResourcePowerHandle(identity, -1, "", "") } set := map[string]interface{}{} if strings.Contains(productType, "VIP订阅") { set["l_vip_endtime"] = time.Now().Unix() set["i_vip_status"] = 0 } else if strings.Contains(productType, "大会员") || productType == YYSZSYY { go DelPdfPack(common.InterfaceToStr(identity.PositionId), entId) set["i_member_endtime"] = time.Now().Unix() set["i_member_status"] = 0 JyMysql.Update(BigServiceUser, map[string]interface{}{"s_userid": common.InterfaceToStr(identity.PositionId)}, map[string]interface{}{"i_status": -1, "l_endtime": NowFormat(Date_Full_Layout)}) } if len(set) > 0 { Mgo.Update("ent_user", map[string]interface{}{ "i_entid": entId, "i_userid": entUserId, }, map[string]interface{}{ "$set": set, }, true, false) RedisDel(strconv.Itoa(int(identity.PositionId))) } } } // 获取用户信息 // return 职位id func getPositionId(entUserId int) *usercenter.Identity { ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) res, _ := UserCenterRpc.IdentityByEntUserId(ctx, &usercenter.IdentityReq{ Id: int64(entUserId), }) return res } // 订阅设置 // types:1超级订阅 2大会员 func setRule(identity *usercenter.Identity, set, setEntUser map[string]interface{}) bool { //订阅设置 query := map[string]interface{}{ "i_entid": identity.EntId, "i_userid": identity.EntUserId, } //orderData相关权益 ok1 := Mgo.Update("entniche_rule", query, map[string]interface{}{ "$set": set, }, true, false) ok2 := Mgo.Update("ent_user", query, map[string]interface{}{ "$set": setEntUser, }, true, false) go func() { MergeKws(identity.EntId, identity.EntUserId) RedisDel(strconv.Itoa(int(identity.PositionId))) }() return ok1 && ok2 } func vipSetMap(orderData map[string]interface{}) (set map[string]interface{}, setEntUser map[string]interface{}) { set, setEntUser = map[string]interface{}{}, map[string]interface{}{} startTime := common.ObjToString(orderData["service_starttime"]) endTime := common.ObjToString(orderData["service_endtime"]) Date_Full_Layout := "2006-01-02 15:04:05" startdate, _ := time.ParseInLocation(Date_Full_Layout, startTime, time.Local) enddate, _ := time.ParseInLocation(Date_Full_Layout, endTime, time.Local) dataType := 1 if startdate.Unix() > time.Now().Unix() { dataType = 2 } //为用户开通超级订阅权限 //是否开通超级订阅 -1 试用到期 -2 正式到期 1 试用 2 开通 isTrial := false if dataType == 2 { isTrial = true } setEntUser["l_createtime"] = time.Now().Unix() setEntUser["l_vip_starttime"] = startdate.Unix() setEntUser["l_vip_endtime"] = enddate.Unix() setEntUser["i_vip_status"] = common.If(isTrial, -2, 2) //1试用 2正式 -2 试用到期 vms := VipCycleFilter{} json.Unmarshal([]byte(common.ObjToString(orderData["filter"])), &vms) set = map[string]interface{}{ "o_entniche": map[string]interface{}{ "i_trial": -1, //已激活试用 "o_area": map[string]interface{}{"北京": []interface{}{}}, //设置地区 "o_buyset": map[string]interface{}{ "upgrade": 1, "areacount": vms.FinalAreaCount, "newcitys": []int{}, "buyerclasscount": -1, }, //购买内容 城市、省份、行业数量, //购买内容 城市、省份、行业数量 "a_buyerclass": []interface{}{}, //设置行业 }, "i_vip_expire_tip": 0, //消息提示初始化 "i_type": 1, } return } func month(num, ty int) int { //BuyType int `json:"buy_type"` //购买周期 类型 1天 2月 3年 4季度 switch ty { case 2: return num case 1: return gconv.Int(math.Ceil(float64(num) / 30)) case 3: return num * 12 case 4: return num * 3 } return 0 } func memberSetMap(userId, waitEmpowerId int64, orderData map[string]interface{}) (set map[string]interface{}, setEntUser map[string]interface{}) { set, setEntUser = map[string]interface{}{}, map[string]interface{}{} filterMap := common.ObjToMap(orderData["filter"]) comboId := common.IntAll((*filterMap)["comboId"]) level := common.If(comboId == 0, 5, comboId).(int) payCycle := month(common.IntAll((*filterMap)["buy_cycle"]), common.IntAll((*filterMap)["buy_type"])) + month(common.IntAll((*filterMap)["give_cycle"]), common.IntAll((*filterMap)["give_type"])) //payCycle := common.IntAll((*filterMap)["cycle"]) serversId := common.ObjToString((*filterMap)["serversId"]) startTime := common.ObjToString(orderData["service_starttime"]) endTime := common.ObjToString(orderData["service_endtime"]) tmp := "2006-01-02 15:04:05" startdate, _ := time.ParseInLocation(tmp, startTime, time.Local) enddate, _ := time.ParseInLocation(tmp, endTime, time.Local) serverMap := GetServerPid() dataType := 1 if startdate.Unix() > time.Now().Unix() { dataType = 2 } var ( areaCount = common.IntAllDef((*filterMap)["areaCount"], -1) area = common.If(areaCount > 0, map[string]interface{}{"北京": []string{}}, map[string]interface{}{}).(map[string]interface{}) ) areaCount = common.IntAllDef((*filterMap)["areaCount"], -1) set = map[string]interface{}{ "i_type": 1, "o_member_jy": map[string]interface{}{ "i_wxpush": 1, }, "o_entniche.i_areacount": areaCount, "o_entniche.o_area": area, //默认北京 } setEntUser = map[string]interface{}{ "i_member_status": common.If(dataType == 1, level, -level), "i_member_starttime": startdate.Unix(), "i_member_endtime": enddate.Unix(), "i_mainaccount": 1, "l_createtime": time.Now().Unix(), } if comboId != 0 { datas := JyMysql.FindOne("bigmember_combo", map[string]interface{}{"id": comboId}, "", "") if datas == nil || len(*datas) == 0 { log.Println("未找到此套餐") return } s_servers := common.ObjToString((*datas)["s_servers"]) for _, s := range strings.Split(s_servers, ",") { serverId, _ := strconv.Atoi(s) mainId := serverId if serverMap[serverId] != 0 { serverId = serverMap[serverId] } serverData := JyMysql.FindOne("bigmember_service", map[string]interface{}{"id": mainId}, "", "") frequency := 0 if serverData != nil && len(*serverData) > 0 { var ( resourceType string ) if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "市场分析定制报告pdf下载") { resourceType = "市场分析定制报告下载包" } else if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "业主采购分析报告pdf下载") { resourceType = "业主采购分析报告下载包" } else if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "企业中标分析报告pdf下载") { resourceType = "企业中标分析报告下载包" } if resourceType != "" { number := common.IntAll((*serverData)["s_count_year"]) cycle := common.IntAll((*filterMap)["cycle"]) //购买时长 cycleType := common.IntAll((*filterMap)["cycleType"]) //时间类型 cycleFmt := common.If(cycleType == 0, 12, 366).(int) number = number * (cycle / cycleFmt) frequency = number if number > 0 { if err := AddPdfPack(common.InterfaceToStr(userId), resourceType, common.Int64All(orderData["ent_id"]), waitEmpowerId); err != nil { log.Println("AddPdfPack err ", err) } } } if frequency == 0 { if serverId == 11 || serverId == 15 { if serverId == 15 { if payCycle >= 12 { frequency = (payCycle / 12 * common.IntAll((*serverData)["s_count_year"])) + (payCycle % 12 * common.IntAll((*serverData)["s_count_month"])) } else { frequency = payCycle * common.IntAll((*serverData)["s_count_month"]) } } else { frequency = payCycle * common.IntAll((*serverData)["s_count_month"]) } } else { frequency = common.IntAll((*serverData)["s_count_month"]) } } } sqls := "select * from bigmember_service_user where s_serviceid = ? and s_userid = ? and i_status = -1" serverDatas := JyMysql.SelectBySql(sqls, serverId, fmt.Sprint(userId)) if serverDatas != nil && len(*serverDatas) > 0 { i_status := common.If(dataType == 1, 0, 1) sql := "update bigmember_service_user set i_frequency = ?,l_updatetime = ?,l_starttime = ?,l_endtime = ?,i_status = ? where s_serviceid = ? and s_userid = ?" status1 := JyMysql.UpdateOrDeleteBySql(sql, fmt.Sprint(frequency), time.Now().Format(tmp), startdate.Format(tmp), enddate.Format(tmp), fmt.Sprint(i_status), serverId, common.InterfaceToStr(userId)) if status1 < 0 { log.Println("新建服务-更新服务表出错", userId) return } } else { insert := map[string]interface{}{ "s_smainid": mainId, "s_userid": userId, "s_serviceid": serverId, "i_frequency": frequency, "l_starttime": startdate.Format(tmp), "l_endtime": enddate.Format(tmp), "i_status": common.If(dataType == 1, 0, 1), "l_createtime": time.Now().Format(tmp), "l_updatetime": time.Now().Format(tmp), } order_id := JyMysql.Insert(BigServiceUser, insert) if order_id > 0 { log.Println("用户服务表插入成功", userId) } else { log.Println("用户服务表插入失败", userId) return } } } } else { for _, s := range strings.Split(serversId, ",") { serverId, _ := strconv.Atoi(s) mainId := serverId if serverMap[serverId] != 0 { serverId = serverMap[serverId] } serverData := JyMysql.FindOne("bigmember_service", map[string]interface{}{"id": mainId}, "", "") frequency := 0 if serverData != nil && len(*serverData) > 0 { var ( resourceType string ) if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "市场分析定制报告pdf下载") { resourceType = "市场分析定制报告下载包" } else if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "业主采购分析报告pdf下载") { resourceType = "业主采购分析报告下载包" } else if strings.Contains(common.InterfaceToStr((*serverData)["s_name"]), "企业中标分析报告pdf下载") { resourceType = "企业中标分析报告下载包" } if resourceType != "" { frequency = common.IntAll((*serverData)["s_count_year"]) if err := AddPdfPack(common.InterfaceToStr(userId), resourceType, common.Int64All(orderData["ent_id"]), waitEmpowerId); err != nil { log.Println("AddPdfPack err ", err) } } if frequency == 0 { if serverId == 11 || serverId == 15 { if serverId == 15 { if payCycle >= 12 { frequency = (payCycle / 12 * common.IntAll((*serverData)["s_count_year"])) + (payCycle % 12 * common.IntAll((*serverData)["s_count_month"])) } else { frequency = payCycle * common.IntAll((*serverData)["s_count_month"]) } } else { frequency = payCycle * common.IntAll((*serverData)["s_count_month"]) } } else { frequency = common.IntAll((*serverData)["s_count_month"]) } } } sqls := "select * from bigmember_service_user where s_serviceid = ? and s_userid = ? and i_status = -1" serverDatas := JyMysql.SelectBySql(sqls, serverId, common.InterfaceToStr(userId)) if serverDatas != nil && len(*serverDatas) > 0 { i_status := common.If(dataType == 1, 0, 1) sql := "update bigmember_service_user set i_frequency = ?,l_updatetime = ?,l_starttime = ?,l_endtime = ?,i_status = ? where s_serviceid = ? and s_userid = ?" status1 := JyMysql.UpdateOrDeleteBySql(sql, fmt.Sprint(frequency), time.Now().Format(tmp), startdate.Format(tmp), enddate.Format(tmp), fmt.Sprint(i_status), serverId, common.InterfaceToStr(userId)) if status1 < 0 { log.Println("新建服务-更新服务表出错") return } } else { insert := map[string]interface{}{ "s_userid": userId, "s_smainid": mainId, "s_serviceid": serverId, "i_frequency": frequency, "l_starttime": startdate.Format(tmp), "l_endtime": enddate.Format(tmp), "i_status": common.If(dataType == 1, 0, 1), "l_createtime": time.Now().Format(tmp), "l_updatetime": time.Now().Format(tmp), } order_id := JyMysql.Insert(BigServiceUser, insert) if order_id > 0 { log.Println("用户服务表插入成功", userId) } else { log.Println("用户服务表插入失败") return } } } } return } // AddPdfPack 增加pdf下载包权限 // resourceType "企业中标分析报告下载包","业主采购分析报告下载包","市场分析定制报告下载包" func AddPdfPack(userId, resourceType string, entId, waitEmpowerId int64) error { log.Println("AddPdfPack==", userId, resourceType, entId, waitEmpowerId) ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) _, err := ResourceCenterRpc.EntAccountGiven(ctx, &resourcesCenterclient.EntOperateReq{ OperateAccountId: userId, EmpowerId: waitEmpowerId, CompanyId: entId, ResourceType: resourceType, }) return err } // DelPdfPack 增加pdf下载包权限 // resourceType "企业中标分析报告下载包","业主采购分析报告下载包","市场分析定制报告下载包" func DelPdfPack(userId string, entId int64) { log.Println("DelPdfPack===", userId, entId) ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) res, err := ResourceCenterRpc.FindAccountBalance(ctx, &resourcesCenterclient.ResourcesReq{ AccountId: userId, ResourceName: "pdf下载包", }) if err != nil { log.Println("FindAccountBalance err", err.Error()) return } for _, datum := range res.Data { if datum.Number > 0 { _, err = ResourceCenterRpc.EntAccountRecovery(ctx, &resourcesCenterclient.EntOperateReq{ OperateAccountId: userId, CompanyId: entId, ResourceType: datum.ResourceType, }) if err != nil { log.Println("EntAccountRecovery err", err.Error()) } } } } func EmpowerUserIds(ids []int64) *entmanageapplication.EmpowerUserIds { result := &entmanageapplication.EmpowerUserIds{} array := []string{} for _, v := range ids { array = append(array, fmt.Sprint(v)) } list := JyMysql.SelectBySql(`SELECT a.ent_user_id from entniche_power a inner join entniche_wait_empower b on (a.ent_user_id in (`+strings.Join(array, ",")+`) and a.status=1 and b.end_time>? and a.wait_empower_id=b.id) ORDER BY a.create_time desc`, NowFormat(Date_Full_Layout)) if list != nil { for _, v := range *list { result.Ids = append(result.Ids, common.Int64All(v["ent_user_id"])) } } return result } // 调用用户中台清除菜单缓存 func delRedisMenuByUserCenter(positionId string) bool { ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) res, err := UserCenterRpc.WorkDesktopClearUserInfo(ctx, &usercenter.WorkDesktopClearUserInfoReq{ AppId: "10000", PositionId: positionId, }) if err != nil || res == nil { log.Println("delRedisMenuByUserCenter err", err) } return true } // 清除权益中台缓存 func delRedisByPowerCheck(positionId string) bool { ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) i_positionId, _ := strconv.Atoi(positionId) res, err := PowerCheckCenterRpc.DelCheckRedis(ctx, &powercheck.CheckReq{ PositionId: int64(i_positionId), Appid: "10000", }) if err != nil || res == nil { log.Println("delRedisByPowerCheck err", err) } return true } func ResourcePowerHandle(identity *usercenter.Identity, t int64, startTime, endTime string) { if t == 1 { resp, err := entity.ResourceRpc.Empower(context.Background(), &pb.EmpowerReq{ Appid: "10000", FunctionCode: "bi_sj_yyszs", EntId: identity.EntId, EntUserId: []int64{identity.EntUserId}, }) if err == nil || resp.Status == 1 { nowFormat := NowFormat(Date_Full_Layout) positionId := fmt.Sprint(identity.PositionId) r1, r2 := JyMysql.InsertBatch("jianyu.bigmember_service_user", []string{"s_userid", "s_serviceid", "i_frequency", "l_starttime", "l_endtime", "i_status", "l_createtime", "l_updatetime"}, []interface{}{ positionId, 1, 0, startTime, endTime, 0, nowFormat, nowFormat, positionId, 3, 0, startTime, endTime, 0, nowFormat, nowFormat, positionId, 4, 500, startTime, endTime, 0, nowFormat, nowFormat, positionId, 5, 0, startTime, endTime, 0, nowFormat, nowFormat, positionId, 10, 0, startTime, endTime, 0, nowFormat, nowFormat, positionId, 12, 500, startTime, endTime, 0, nowFormat, nowFormat, positionId, 13, 500, startTime, endTime, 0, nowFormat, nowFormat, positionId, 14, 500, startTime, endTime, 0, nowFormat, nowFormat, }) if r1 > 0 && r2 > 0 { start, err1 := time.ParseInLocation(Date_Full_Layout, startTime, time.Local) end, err2 := time.ParseInLocation(Date_Full_Layout, endTime, time.Local) if err1 == nil && err2 == nil { setRule(identity, map[string]interface{}{"i_type": 1}, map[string]interface{}{ "i_member_status": 5, "i_member_starttime": start.Unix(), "i_member_endtime": end.Unix(), "l_createtime": time.Now().Unix(), }) } } } } else { entity.ResourceRpc.CancelEmpower(context.Background(), &pb.EmpowerReq{ Appid: "10000", FunctionCode: "bi_sj_yyszs", EntId: identity.EntId, EntUserId: []int64{identity.EntUserId}, }) } }