service.go 20 KB

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