service.go 20 KB

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