service.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "bp.jydev.jianyu360.cn/BaseService/entManageApplication/entity"
  10. "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
  11. "context"
  12. . "app.yhyue.com/moapp/jybase/date"
  13. "app.yhyue.com/moapp/jybase/mongodb"
  14. . "bp.jydev.jianyu360.cn/BaseService/entManageApplication/entity"
  15. "bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/entmanageapplication"
  16. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
  17. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
  18. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
  19. // "github.com/zeromicro/go-zero/core/logx"
  20. "app.yhyue.com/moapp/jybase/common"
  21. "app.yhyue.com/moapp/jybase/redis"
  22. )
  23. func AddUsePerson(this *entmanageapplication.AddUsePersonReq) *entmanageapplication.AddUsePersonResp {
  24. timeStr, ok, id, msg, code := time.Now().Format("2006-01-02 15:04:05"), false, int64(0), "", int64(0)
  25. if this.EntUserId == "" {
  26. return &entmanageapplication.AddUsePersonResp{
  27. ErrorCode: -1,
  28. ErrorMsg: "添加失败",
  29. Data: &entmanageapplication.AddUsePerson{Status: int64(-1)},
  30. }
  31. }
  32. UserArr := strings.Split(this.EntUserId, ",")
  33. sourceData := JyMysql.FindOne(EntnicheWaitEmpower, map[string]interface{}{"id": this.WaitEmpowerId}, "", "")
  34. if sourceData != nil && len(*sourceData) > 0 {
  35. empower_count := common.IntAll((*sourceData)["empower_count"])
  36. use_count := common.IntAll((*sourceData)["use_count"])
  37. if empower_count-use_count < len(UserArr) {
  38. msg = "购买数量不足"
  39. code = int64(-1)
  40. } else {
  41. for _, v := range UserArr {
  42. //过滤空值2023-01-04
  43. if v == "" {
  44. continue
  45. }
  46. //
  47. entUserId, _ := strconv.Atoi(v)
  48. data := JyMysql.FindOne(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, "", "")
  49. if data != nil && len(*data) > 0 {
  50. dataStatus := common.IntAll((*data)["status"])
  51. wait_empower_id := common.Int64All((*data)["wait_empower_id"])
  52. if dataStatus == -1 {
  53. ok = JyMysql.Update(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, map[string]interface{}{"wait_empower_id": this.WaitEmpowerId, "status": 1, "update_time": timeStr})
  54. } else {
  55. resdata := JyMysql.FindOne(EntnicheWaitEmpower, map[string]interface{}{"id": wait_empower_id}, "", "")
  56. end_time := common.ObjToString((*resdata)["end_time"])
  57. res, _ := time.ParseInLocation("2006-01-02 15:04:05", end_time, time.Local)
  58. if res.Unix() > time.Now().Unix() {
  59. msg = "人员已经拥有权限,请先删除原有权限"
  60. code = int64(-1)
  61. break
  62. } else {
  63. ok = JyMysql.Update(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, map[string]interface{}{"wait_empower_id": this.WaitEmpowerId, "status": 1, "update_time": timeStr})
  64. }
  65. }
  66. } else {
  67. id = JyMysql.Insert(EntnichePower, map[string]interface{}{
  68. "wait_empower_id": this.WaitEmpowerId,
  69. "ent_id": this.EntId,
  70. "ent_user_id": entUserId,
  71. "status": 1,
  72. "create_time": timeStr,
  73. "update_time": timeStr,
  74. })
  75. }
  76. JyMysql.UpdateOrDeleteBySql(`update `+EntnicheWaitEmpower+` set use_count = use_count + 1 where id = ?`, this.WaitEmpowerId)
  77. addPower(this.WaitEmpowerId, entUserId, this.EntId)
  78. }
  79. }
  80. }
  81. status := 0
  82. if ok || id > 0 {
  83. status = 1
  84. }
  85. return &entmanageapplication.AddUsePersonResp{
  86. ErrorCode: code,
  87. ErrorMsg: msg,
  88. Data: &entmanageapplication.AddUsePerson{Status: int64(status)},
  89. }
  90. }
  91. func DelUsePerson(this *entmanageapplication.DelUsePersonReq) *entmanageapplication.AddUsePersonResp {
  92. timeStr := time.Now().Format("2006-01-02 15:04:05")
  93. ok := JyMysql.Update(EntnichePower, map[string]interface{}{"id": this.EntnichePowerId},
  94. map[string]interface{}{"status": -1, "update_time": timeStr})
  95. delPower(this.EntnichePowerId)
  96. status := 0
  97. if ok {
  98. status = 1
  99. }
  100. return &entmanageapplication.AddUsePersonResp{
  101. ErrorCode: 0,
  102. Data: &entmanageapplication.AddUsePerson{Status: int64(status)},
  103. }
  104. }
  105. func UsePersonList(this *entmanageapplication.UsePersonListReq) *entmanageapplication.UsePersonListResp {
  106. nowTime := time.Now().Format("2006-01-02 15:04:05")
  107. data := JyMysql.SelectBySql(`select a.id,a.wait_empower_id,c.name,c.phone,c.mail,g.name as department,e.name as role from entniche_power a
  108. INNER JOIN entniche_user c on (a.ent_user_id=c.id and a.ent_id = c.ent_id)
  109. LEFT JOIN entniche_user_role d on (c.id=d.user_id)
  110. LEFT JOIN entniche_role e on (d.role_id=e.id)
  111. LEFT JOIN entniche_department_user f on (a.ent_user_id=f.user_id)
  112. LEFT JOIN entniche_department g on (g.id=f.dept_id)
  113. LEFT JOIN entniche_wait_empower h on (h.id=a.wait_empower_id)
  114. where a.status = 1 and a.ent_id = ? and h.product_type<>'运营商数据定制及分析' and h.end_time >= ?
  115. order by a.update_time,a.id desc`, this.EntId, nowTime)
  116. arr := []*entmanageapplication.UsePersonList{}
  117. if data != nil && len(*data) > 0 {
  118. for _, v := range *data {
  119. wait_empower_id := common.Int64All(v["wait_empower_id"])
  120. if wait_empower_id == this.WaitEmpowerId {
  121. obj := &entmanageapplication.UsePersonList{
  122. EntnichePowerId: common.Int64All(v["id"]),
  123. Name: common.ObjToString(v["name"]),
  124. Phone: common.ObjToString(v["phone"]),
  125. Email: common.ObjToString(v["mail"]),
  126. Department: common.ObjToString(v["department"]),
  127. Role: common.ObjToString(v["role"]),
  128. Status: 1,
  129. }
  130. arr = append(arr, obj)
  131. } else {
  132. obj := &entmanageapplication.UsePersonList{
  133. EntnichePowerId: common.Int64All(v["id"]),
  134. Name: common.ObjToString(v["name"]),
  135. Phone: common.ObjToString(v["phone"]),
  136. Email: common.ObjToString(v["mail"]),
  137. Department: common.ObjToString(v["department"]),
  138. Role: common.ObjToString(v["role"]),
  139. Status: 2,
  140. }
  141. arr = append(arr, obj)
  142. }
  143. }
  144. }
  145. return &entmanageapplication.UsePersonListResp{
  146. ErrorCode: 0,
  147. Data: arr,
  148. }
  149. }
  150. func BuyProductList(this *entmanageapplication.BuyProductListReq) *entmanageapplication.BuyProductListResp {
  151. nowTime := time.Now().Format("2006-01-02 15:04:05")
  152. data := JyMysql.SelectBySql(`select * from `+EntnicheWaitEmpower+` where ent_id = ? and end_time >= ? order by create_time desc`, this.EntId, nowTime)
  153. arr := []*entmanageapplication.BuyProductList{}
  154. if data != nil && len(*data) > 0 {
  155. for _, v := range *data {
  156. product_type := common.ObjToString(v["product_type"])
  157. if product_type == "VIP订阅" {
  158. product_type = "超级订阅"
  159. }
  160. productTypeSuffix := ""
  161. if provinceCount := common.IntAllDef(v["province_count"], -1); provinceCount > 0 {
  162. switch provinceCount {
  163. case 1:
  164. productTypeSuffix = "单省版"
  165. default:
  166. productTypeSuffix = "省份版"
  167. }
  168. }
  169. obj := &entmanageapplication.BuyProductList{
  170. WaitEmpowerId: common.Int64All(v["id"]),
  171. ProductType: fmt.Sprintf("%s%s", product_type, productTypeSuffix),
  172. UseCount: common.Int64All(v["use_count"]),
  173. EmpowerCount: common.Int64All(v["empower_count"]),
  174. ProvinceCount: common.Int64All(v["province_count"]),
  175. EndTime: common.ObjToString(v["end_time"]),
  176. }
  177. arr = append(arr, obj)
  178. }
  179. }
  180. return &entmanageapplication.BuyProductListResp{
  181. ErrorCode: 0,
  182. Data: arr,
  183. }
  184. }
  185. func addPower(waitEmpowerId int64, entUserId int, entId int64) {
  186. identity := getPositionId(entUserId)
  187. ResourcePowerHandle(identity, waitEmpowerId, 1)
  188. data := JyMysql.FindOne(EntnicheOrder, map[string]interface{}{"wait_empower_id": waitEmpowerId}, "", "")
  189. if data != nil && len(*data) > 0 {
  190. orderId := common.Int64All((*data)["order_id"])
  191. orderData := JyMysql.FindOne(Order, map[string]interface{}{"id": orderId}, "", "")
  192. if orderData != nil && len(*orderData) > 0 {
  193. productType := common.ObjToString((*orderData)["product_type"])
  194. if productType == "VIP订阅" {
  195. log.Println("开通超级订阅", identity.PositionId)
  196. setRule(1, int64(entUserId), entId, *orderData, identity.PositionId)
  197. } else if productType == "大会员" {
  198. log.Println("开通大会员", identity.PositionId)
  199. setRule(2, int64(entUserId), entId, *orderData, identity.PositionId)
  200. }
  201. }
  202. }
  203. }
  204. func GetServerPid() map[int]int {
  205. pidMap := map[int]int{}
  206. datas := JyMysql.Find("bigmember_service", map[string]interface{}{"i_status": 0}, "id,i_pid", "", 0, 0)
  207. if datas != nil && len(*datas) > 0 {
  208. for _, v := range *datas {
  209. if v["i_pid"] != nil {
  210. pidMap[common.IntAll(v["id"])] = common.IntAll(v["i_pid"])
  211. }
  212. }
  213. }
  214. return pidMap
  215. }
  216. func RedisDel(userId string) {
  217. redis.Del(NewOther, "pl_indexMessage_"+userId)
  218. delRedisMenuByUserCenter(userId)
  219. delRedisByPowerCheck(userId)
  220. }
  221. // 初始化vip订阅关键词
  222. func MergeKws(entId, entUserId int64) {
  223. if entUserId == 0 || entId == 0 { //11-11 取消此操作
  224. return
  225. }
  226. data, ok := Mgo.FindOneByField("entniche_rule", map[string]interface{}{"i_entid": entId, "i_userid": entUserId}, `{"o_entniche":1,"_id":1}`)
  227. var o_entniche map[string]interface{}
  228. if ok && data != nil && len(*data) > 0 {
  229. o_entniche, _ = (*data)["o_entniche"].(map[string]interface{})
  230. a_items, _ := o_entniche["a_items"].([]interface{})
  231. if a_items == nil { //首次
  232. _id := mongodb.BsonIdToSId((*data)["_id"])
  233. Mgo.UpdateById("entniche_rule", _id, map[string]interface{}{
  234. "$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()},
  235. })
  236. }
  237. }
  238. }
  239. func delPower(id int64) {
  240. data := JyMysql.FindOne(EntnichePower, map[string]interface{}{"id": id}, "", "")
  241. if data != nil && len(*data) > 0 {
  242. waitEmpowerId := common.Int64All((*data)["wait_empower_id"])
  243. entUserId := common.IntAll((*data)["ent_user_id"])
  244. identity := getPositionId(entUserId)
  245. ResourcePowerHandle(identity, waitEmpowerId, -1)
  246. JyMysql.UpdateOrDeleteBySql(`update `+EntnicheWaitEmpower+` set use_count = use_count - 1 where id = ? and use_count > 0`, waitEmpowerId)
  247. eOData := JyMysql.FindOne(EntnicheOrder, map[string]interface{}{"wait_empower_id": waitEmpowerId}, "", "")
  248. if eOData != nil && len(*eOData) > 0 {
  249. orderId := common.Int64All((*eOData)["order_id"])
  250. orderData := JyMysql.FindOne(Order, map[string]interface{}{"id": orderId}, "", "")
  251. set := map[string]interface{}{}
  252. if orderData != nil && len(*orderData) > 0 {
  253. productType := common.ObjToString((*orderData)["product_type"])
  254. entId := common.Int64All((*orderData)["ent_id"])
  255. if productType == "VIP订阅" {
  256. set["l_vip_endtime"] = time.Now().Unix()
  257. set["i_vip_status"] = 0
  258. } else if productType == "大会员" {
  259. set["i_member_endtime"] = time.Now().Unix()
  260. set["i_member_status"] = 0
  261. JyMysql.Update(BigServiceUser, map[string]interface{}{"s_userid": common.InterfaceToStr(identity.PositionId)}, map[string]interface{}{"i_status": -1})
  262. }
  263. Mgo.Update("ent_user", map[string]interface{}{
  264. "i_entid": entId,
  265. "i_userid": entUserId,
  266. }, map[string]interface{}{
  267. "$set": set,
  268. }, true, false)
  269. posititonIdStr := strconv.Itoa(int(identity.PositionId))
  270. RedisDel(posititonIdStr)
  271. }
  272. }
  273. }
  274. }
  275. // 获取用户信息
  276. // return 职位id
  277. func getPositionId(entUserId int) *usercenter.Identity {
  278. ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
  279. res, _ := UserCenterRpc.IdentityByEntUserId(ctx, &usercenter.IdentityReq{
  280. Id: int64(entUserId),
  281. })
  282. return res
  283. }
  284. // 订阅设置
  285. // types:1超级订阅 2大会员
  286. func setRule(types int64, entUserId, entId int64, orderData map[string]interface{}, posititonId int64) bool {
  287. //订阅设置
  288. query := map[string]interface{}{
  289. "i_entid": entId,
  290. "i_userid": entUserId,
  291. }
  292. //orderData相关权益
  293. set := map[string]interface{}{}
  294. setEntUser := map[string]interface{}{}
  295. //超级订阅
  296. if types == 1 {
  297. set, setEntUser = vipSetMap(orderData)
  298. } else if types == 2 {
  299. set, setEntUser = memberSetMap(posititonId, orderData)
  300. }
  301. ok1 := Mgo.Update("entniche_rule", query, map[string]interface{}{
  302. "$set": set,
  303. }, true, false)
  304. ok2 := Mgo.Update("ent_user", query, map[string]interface{}{
  305. "$set": setEntUser,
  306. }, true, false)
  307. go func() {
  308. MergeKws(entId, entUserId)
  309. posititonIdStr := strconv.Itoa(int(posititonId))
  310. RedisDel(posititonIdStr)
  311. if types == 1 {
  312. now1 := time.Now()
  313. currentYear, currentMonth, _ := now1.Date()
  314. currentLocation := now1.Location()
  315. firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
  316. lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
  317. endTime := lastOfMonth.Format("2006-01-02")
  318. vipTime := time.Unix(common.Int64All(setEntUser["l_vip_endtime"]), 0).Format("2006-01-02")
  319. ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
  320. ResourceCenterRpc.PurchaseUserBalance(ctx, &resourcesCenterclient.Resources{
  321. AppId: "10000",
  322. UserId: common.InterfaceToStr(posititonId),
  323. ResourceType: "附件下载包",
  324. AccountId: common.InterfaceToStr(posititonId),
  325. Name: "附件下载包",
  326. Number: 10,
  327. Spec: "个",
  328. EndTime: endTime,
  329. VipTime: vipTime,
  330. Model: 3,
  331. })
  332. }
  333. }()
  334. return ok1 && ok2
  335. }
  336. func vipSetMap(orderData map[string]interface{}) (set map[string]interface{}, setEntUser map[string]interface{}) {
  337. set, setEntUser = map[string]interface{}{}, map[string]interface{}{}
  338. startTime := common.ObjToString(orderData["vip_starttime"])
  339. endTime := common.ObjToString(orderData["vip_endtime"])
  340. Date_Full_Layout := "2006-01-02 15:04:05"
  341. startdate, _ := time.ParseInLocation(Date_Full_Layout, startTime, time.Local)
  342. enddate, _ := time.ParseInLocation(Date_Full_Layout, endTime, time.Local)
  343. dataType := 1
  344. if startdate.Unix() > time.Now().Unix() {
  345. dataType = 2
  346. }
  347. //为用户开通超级订阅权限
  348. //是否开通超级订阅 -1 试用到期 -2 正式到期 1 试用 2 开通
  349. isTrial := false
  350. if dataType == 2 {
  351. isTrial = true
  352. }
  353. setEntUser["l_createtime"] = time.Now().Unix()
  354. setEntUser["l_vip_starttime"] = startdate.Unix()
  355. setEntUser["l_vip_endtime"] = enddate.Unix()
  356. setEntUser["i_vip_status"] = common.If(isTrial, -2, 2) //1试用 2正式 -2 试用到期
  357. vms := VipSimpleMsg{}
  358. json.Unmarshal([]byte(common.ObjToString(orderData["filter"])), &vms)
  359. set = map[string]interface{}{
  360. "o_entniche": map[string]interface{}{
  361. "i_trial": -1, //已激活试用
  362. "o_area": *vms.Area, //设置地区
  363. "o_buyset": *vms.NewBuyset, //购买内容 城市、省份、行业数量
  364. "a_buyerclass": []interface{}{}, //设置行业
  365. },
  366. "i_vip_expire_tip": 0, //消息提示初始化
  367. "i_type": 1,
  368. }
  369. return
  370. }
  371. func memberSetMap(userId int64, orderData map[string]interface{}) (set map[string]interface{}, setEntUser map[string]interface{}) {
  372. set, setEntUser = map[string]interface{}{}, map[string]interface{}{}
  373. filterMap := common.ObjToMap(orderData["filter"])
  374. level := common.IntAll((*filterMap)["level"])
  375. comboId := common.IntAll((*filterMap)["comboId"])
  376. payCycle := common.IntAll((*filterMap)["cycle"])
  377. serversId := common.ObjToString((*filterMap)["serversId"])
  378. startTime := common.ObjToString(orderData["vip_starttime"])
  379. endTime := common.ObjToString(orderData["vip_endtime"])
  380. tmp := "2006-01-02 15:04:05"
  381. startdate, _ := time.ParseInLocation(tmp, startTime, time.Local)
  382. enddate, _ := time.ParseInLocation(tmp, endTime, time.Local)
  383. serverMap := GetServerPid()
  384. dataType := 1
  385. if startdate.Unix() > time.Now().Unix() {
  386. dataType = 2
  387. }
  388. var (
  389. areaCount = common.IntAllDef((*filterMap)["areaCount"], -1)
  390. area = common.If(areaCount > 0, map[string]interface{}{"北京": []string{}}, map[string]interface{}{}).(map[string]interface{})
  391. )
  392. areaCount = common.IntAllDef((*filterMap)["areaCount"], -1)
  393. set = map[string]interface{}{
  394. "i_type": 1,
  395. "o_member_jy": map[string]interface{}{
  396. "i_wxpush": 1,
  397. },
  398. "o_entniche.i_areacount": areaCount,
  399. "o_entniche.o_area": area, //默认北京
  400. }
  401. setEntUser = map[string]interface{}{
  402. "i_member_status": common.If(dataType == 1, level, -level),
  403. "i_member_starttime": startdate.Unix(),
  404. "i_member_endtime": enddate.Unix(),
  405. "i_mainaccount": 1,
  406. "l_createtime": time.Now().Unix(),
  407. }
  408. if comboId != 0 {
  409. datas := JyMysql.FindOne("bigmember_combo", map[string]interface{}{"id": comboId}, "", "")
  410. if datas == nil || len(*datas) == 0 {
  411. log.Println("未找到此套餐")
  412. return
  413. }
  414. s_servers := common.ObjToString((*datas)["s_servers"])
  415. for _, s := range strings.Split(s_servers, ",") {
  416. serverId, _ := strconv.Atoi(s)
  417. mainId := serverId
  418. if serverMap[serverId] != 0 {
  419. serverId = serverMap[serverId]
  420. }
  421. serverData := JyMysql.FindOne("bigmember_service", map[string]interface{}{"id": mainId}, "", "")
  422. frequency := 0
  423. if serverData != nil && len(*serverData) > 0 {
  424. if serverId == 11 || serverId == 15 {
  425. if serverId == 15 {
  426. if payCycle >= 12 {
  427. frequency = (payCycle / 12 * common.IntAll((*serverData)["s_count_year"])) + (payCycle % 12 * common.IntAll((*serverData)["s_count_month"]))
  428. } else {
  429. frequency = payCycle * common.IntAll((*serverData)["s_count_month"])
  430. }
  431. } else {
  432. frequency = payCycle * common.IntAll((*serverData)["s_count_month"])
  433. }
  434. } else {
  435. frequency = common.IntAll((*serverData)["s_count_month"])
  436. }
  437. }
  438. sqls := "select * from bigmember_service_user where s_serviceid = ? and s_userid = ? and i_status = -1"
  439. serverDatas := JyMysql.SelectBySql(sqls, serverId, common.InterfaceToStr(userId))
  440. if serverDatas != nil && len(*serverDatas) > 0 {
  441. i_status := common.If(dataType == 1, 0, 1)
  442. sql := "update bigmember_service_user set i_frequency = ?,l_updatetime = ?,l_starttime = ?,l_endtime = ?,i_status = ? where s_serviceid = ? and s_userid = ?"
  443. 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))
  444. if status1 < 0 {
  445. log.Println("新建服务-更新服务表出错", userId)
  446. return
  447. }
  448. } else {
  449. insert := map[string]interface{}{
  450. "s_smainid": mainId,
  451. "s_userid": userId,
  452. "s_serviceid": serverId,
  453. "i_frequency": frequency,
  454. "l_starttime": startdate.Format(tmp),
  455. "l_endtime": enddate.Format(tmp),
  456. "i_status": common.If(dataType == 1, 0, 1),
  457. "l_createtime": time.Now().Format(tmp),
  458. "l_updatetime": time.Now().Format(tmp),
  459. }
  460. order_id := JyMysql.Insert(BigServiceUser, insert)
  461. if order_id > 0 {
  462. log.Println("用户服务表插入成功", userId)
  463. } else {
  464. log.Println("用户服务表插入失败", userId)
  465. return
  466. }
  467. }
  468. }
  469. } else {
  470. for _, s := range strings.Split(serversId, ",") {
  471. serverId, _ := strconv.Atoi(s)
  472. mainId := serverId
  473. if serverMap[serverId] != 0 {
  474. serverId = serverMap[serverId]
  475. }
  476. serverData := JyMysql.FindOne("bigmember_service", map[string]interface{}{"id": mainId}, "", "")
  477. frequency := 0
  478. if serverData != nil && len(*serverData) > 0 {
  479. if serverId == 11 || serverId == 15 {
  480. if serverId == 15 {
  481. if payCycle >= 12 {
  482. frequency = (payCycle / 12 * common.IntAll((*serverData)["s_count_year"])) + (payCycle % 12 * common.IntAll((*serverData)["s_count_month"]))
  483. } else {
  484. frequency = payCycle * common.IntAll((*serverData)["s_count_month"])
  485. }
  486. } else {
  487. frequency = payCycle * common.IntAll((*serverData)["s_count_month"])
  488. }
  489. } else {
  490. frequency = common.IntAll((*serverData)["s_count_month"])
  491. }
  492. }
  493. sqls := "select * from bigmember_service_user where s_serviceid = ? and s_userid = ? and i_status = -1"
  494. serverDatas := JyMysql.SelectBySql(sqls, serverId, common.InterfaceToStr(userId))
  495. if serverDatas != nil && len(*serverDatas) > 0 {
  496. i_status := common.If(dataType == 1, 0, 1)
  497. sql := "update bigmember_service_user set i_frequency = ?,l_updatetime = ?,l_starttime = ?,l_endtime = ?,i_status = ? where s_serviceid = ? and s_userid = ?"
  498. 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))
  499. if status1 < 0 {
  500. log.Println("新建服务-更新服务表出错")
  501. return
  502. }
  503. } else {
  504. insert := map[string]interface{}{
  505. "s_userid": userId,
  506. "s_smainid": mainId,
  507. "s_serviceid": serverId,
  508. "i_frequency": frequency,
  509. "l_starttime": startdate.Format(tmp),
  510. "l_endtime": enddate.Format(tmp),
  511. "i_status": common.If(dataType == 1, 0, 1),
  512. "l_createtime": time.Now().Format(tmp),
  513. "l_updatetime": time.Now().Format(tmp),
  514. }
  515. order_id := JyMysql.Insert(BigServiceUser, insert)
  516. if order_id > 0 {
  517. log.Println("用户服务表插入成功", userId)
  518. } else {
  519. log.Println("用户服务表插入失败")
  520. return
  521. }
  522. }
  523. }
  524. }
  525. return
  526. }
  527. func EmpowerUserIds(ids []int64) *entmanageapplication.EmpowerUserIds {
  528. result := &entmanageapplication.EmpowerUserIds{}
  529. array := []string{}
  530. for _, v := range ids {
  531. array = append(array, fmt.Sprint(v))
  532. }
  533. 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))
  534. if list != nil {
  535. for _, v := range *list {
  536. result.Ids = append(result.Ids, common.Int64All(v["ent_user_id"]))
  537. }
  538. }
  539. return result
  540. }
  541. // 调用用户中台清除菜单缓存
  542. func delRedisMenuByUserCenter(positionId string) bool {
  543. ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
  544. res, err := UserCenterRpc.WorkDesktopClearUserInfo(ctx, &usercenter.WorkDesktopClearUserInfoReq{
  545. AppId: "10000",
  546. PositionId: positionId,
  547. })
  548. if err != nil || res == nil {
  549. log.Println("delRedisMenuByUserCenter err", err)
  550. }
  551. return true
  552. }
  553. // 清除权益中台缓存
  554. func delRedisByPowerCheck(positionId string) bool {
  555. ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
  556. i_positionId, _ := strconv.Atoi(positionId)
  557. res, err := PowerCheckCenterRpc.DelCheckRedis(ctx, &powercheck.CheckReq{
  558. PositionId: int64(i_positionId),
  559. Appid: "10000",
  560. })
  561. if err != nil || res == nil {
  562. log.Println("delRedisByPowerCheck err", err)
  563. }
  564. return true
  565. }
  566. //
  567. func ResourcePowerHandle(identity *usercenter.Identity, waitEmpowerId, t int64) {
  568. //如果是运营商数据定制及分析产品,调用资源中台,取消对应菜单权限
  569. if JyMysql.CountBySql(`select count(1) as count from `+EntnicheWaitEmpower+` where id=? and product_type='运营商数据定制及分析'`, waitEmpowerId) > 0 {
  570. entity.ResourceRpc.PowerHandle(context.Background(), &pb.PowerReq{
  571. Appid: "10000",
  572. GoodsCode: "special_nosale_goods",
  573. GoodsSpecId: 31,
  574. BuyNum: 1,
  575. Type: t,
  576. AccountId: identity.AccountId,
  577. EntAccountId: identity.EntAccountId,
  578. EntId: identity.EntId,
  579. })
  580. }
  581. }