service.go 22 KB

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