service.go 20 KB

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