public.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. package p
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "reflect"
  7. "sort"
  8. "strconv"
  9. "strings"
  10. "sync"
  11. "time"
  12. . "app.yhyue.com/moapp/jybase/common"
  13. util "app.yhyue.com/moapp/jybase/common"
  14. . "app.yhyue.com/moapp/jybase/date"
  15. "app.yhyue.com/moapp/jybase/logger"
  16. . "app.yhyue.com/moapp/jybase/mongodb"
  17. . "app.yhyue.com/moapp/jybase/mysql"
  18. "app.yhyue.com/moapp/jybase/redis"
  19. rcDb "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
  20. rcService "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
  21. . "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
  22. )
  23. //金额转化 金额:0-万元以下单位为元 ,万元以上至亿元以下单位为万元 ,亿元以上单位为亿元。保留 小数点后 2 位,不进行四舍五入。
  24. func ConversionMoney(i_money interface{}) string {
  25. m := ""
  26. if reflect.TypeOf(i_money).Name() == "float64" {
  27. m = strconv.FormatFloat(Float64All(i_money), 'f', -1, 64)
  28. } else {
  29. m = ObjToString(i_money)
  30. }
  31. if m == "" {
  32. return m
  33. }
  34. m_arr := strings.Split(m, ".")
  35. m_1 := m_arr[0]
  36. len_m1 := len([]rune(m_1))
  37. if len_m1 >= 9 {
  38. m = m_1[0:len_m1-8] + "." + m_1[len_m1-8:len_m1-6] + "亿元"
  39. } else if len_m1 >= 5 {
  40. m = m_1[0:len_m1-4] + "." + m_1[len_m1-4:len_m1-2] + "万元"
  41. } else {
  42. if len(m_arr) == 1 {
  43. return m + ".00元"
  44. }
  45. m_2 := m_arr[1]
  46. if len([]rune(m_2)) > 1 {
  47. m_2 = m_2[0:2]
  48. } else {
  49. m_2 = m_2[0:1] + "0"
  50. }
  51. m = m_1 + "." + m_2 + "元"
  52. }
  53. return m
  54. }
  55. //微信模板消息 remark
  56. func WxTplRemark(titles []string, lastTime int64, hasLen int) string {
  57. tip := ""
  58. second := time.Now().Unix() - lastTime
  59. if second > 0 {
  60. if second < 61 {
  61. tip = fmt.Sprintf("%d秒前发布的:\n", second)
  62. } else {
  63. second = second / 60
  64. if second < 121 {
  65. if second < 1 {
  66. second = 1
  67. }
  68. tip = fmt.Sprintf("%d分钟前发布的:\n", second)
  69. }
  70. }
  71. }
  72. lastTip := ""
  73. if len(titles) > 1 {
  74. lastTip = fmt.Sprintf("...(共%d条)", len(titles))
  75. }
  76. reLen := 199 - hasLen - len([]rune(tip))
  77. lastTipLen := len([]rune(lastTip))
  78. wxTplMsgTitle := ""
  79. bshow := false
  80. for n := 1; n < len(titles)+1; n++ {
  81. curTitle := titles[n-1]
  82. tmptitle := wxTplMsgTitle + fmt.Sprintf("%d %s\n", n, curTitle)
  83. ch := reLen - len([]rune(tmptitle))
  84. if ch < lastTipLen { //加上后大于后辍,则没有完全显示
  85. if ch == 0 && n == len(titles) {
  86. wxTplMsgTitle = tmptitle
  87. bshow = true
  88. } else {
  89. ch_1 := reLen - len([]rune(wxTplMsgTitle)) - lastTipLen
  90. if ch_1 > 8 {
  91. curLen := len([]rune(curTitle))
  92. if ch_1 > curLen {
  93. ch_1 = curLen
  94. }
  95. wxTplMsgTitle += fmt.Sprintf("%d %s\n", n, string([]rune(curTitle)[:ch_1-3]))
  96. }
  97. }
  98. } else {
  99. wxTplMsgTitle = tmptitle
  100. if n == len(titles) {
  101. bshow = true
  102. }
  103. }
  104. }
  105. if bshow {
  106. lastTip = ""
  107. }
  108. return tip + wxTplMsgTitle + lastTip
  109. }
  110. //获取信息行业
  111. func GetSubScopeClass(subscopeclass interface{}) string {
  112. industry := ""
  113. if subscopeclass != nil {
  114. k2sub := strings.Split(ObjToString(subscopeclass), ",")
  115. if len(k2sub) > 0 {
  116. industry = k2sub[0]
  117. if industry != "" {
  118. ss := strings.Split(industry, "_")
  119. if len(ss) > 1 {
  120. industry = ss[0]
  121. }
  122. }
  123. }
  124. }
  125. return industry
  126. }
  127. //控制一分钟最大推送数,均匀调度
  128. func LimitMaxOneMinutePush(pushPoll *chan bool, maxOneMinute int) {
  129. max := int(maxOneMinute / 60)
  130. *pushPoll = make(chan bool, max)
  131. go func() {
  132. for {
  133. time.Sleep(time.Second)
  134. for i := 0; i < max; i++ {
  135. select {
  136. case *pushPoll <- true:
  137. default:
  138. continue
  139. }
  140. }
  141. }
  142. }()
  143. }
  144. //
  145. func UpdateUserIsPush(Mgo *MongodbSim, userId string, err error) {
  146. if err == nil {
  147. return
  148. }
  149. if strings.Contains(err.Error(), "[43004]") {
  150. Mgo.UpdateById("user", userId, map[string]interface{}{
  151. "$set": map[string]interface{}{
  152. "i_ispush": 0,
  153. },
  154. })
  155. }
  156. }
  157. //查找我的子账号
  158. func MySonAccounts(Mgo *MongodbSim, coll, userId string, field map[string]interface{}) *[]map[string]interface{} {
  159. users, _ := Mgo.Find(coll, map[string]interface{}{
  160. "i_member_sub_status": 1,
  161. "s_member_mainid": userId,
  162. "i_member_status": map[string]interface{}{"$gt": 0},
  163. }, nil, field, false, -1, -1)
  164. if users == nil {
  165. users = &[]map[string]interface{}{}
  166. }
  167. return users
  168. }
  169. //是否购买此服务
  170. func HasService(msl *Mysql, userId string, params ...int) *MemberService {
  171. args := []interface{}{}
  172. ws := []string{}
  173. for _, v := range params {
  174. args = append(args, v)
  175. ws = append(ws, "?")
  176. }
  177. args = append(args, args...)
  178. args = append(args, userId, NowFormat(Date_Full_Layout))
  179. list := msl.SelectBySql(`SELECT a.l_starttime,b.id from jianyu.bigmember_service_user a
  180. INNER JOIN jianyu.bigmember_service b on (((b.id in (`+strings.Join(ws, ",")+`) and a.s_serviceid=b.id) or (b.i_pid in (`+strings.Join(ws, ",")+`) and a.s_serviceid=b.i_pid)) and b.i_status=0 and a.s_userid=? and a.i_status=0 and a.l_endtime>?)`, args...)
  181. ms := &MemberService{
  182. Services: map[int]*memberService{},
  183. }
  184. if list != nil {
  185. for _, v := range *list {
  186. ms.IsBuy = true
  187. id := util.IntAll(v["id"])
  188. ms.Services[id] = &memberService{
  189. Id: id,
  190. StartTime: util.ObjToString(v["l_starttime"]),
  191. }
  192. }
  193. }
  194. return ms
  195. }
  196. //
  197. func GetInfoTitle(info map[string]interface{}) string {
  198. title, _ := info["title"].(string)
  199. jsondata, _ := info["jsondata"].(map[string]interface{})
  200. if jsondata != nil {
  201. goods, _ := jsondata["goods"].(string)
  202. title += goods
  203. }
  204. title = strings.ToUpper(title)
  205. return title
  206. }
  207. //加载数据到内存中
  208. func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCache bool, query map[string]interface{}, fields map[string]interface{}) (*[]map[string]interface{}, int64) {
  209. defer util.Catch()
  210. endTime := time.Now().Unix()
  211. if query == nil || len(query) == 0 {
  212. query = map[string]interface{}{
  213. "pici": map[string]interface{}{
  214. "$gte": startTime,
  215. "$lt": endTime,
  216. },
  217. }
  218. }
  219. logger.Info("开始加载", coll, "数据", query)
  220. queryField := map[string]interface{}{
  221. "title": 1,
  222. "detail": 1,
  223. "projectname": 1,
  224. "projectcode": 1,
  225. "buyer": 1,
  226. "buyerperson": 1,
  227. "buyertel": 1,
  228. "s_winner": 1,
  229. "agency": 1,
  230. "bidopentime": 1,
  231. "projectscope": 1,
  232. "publishtime": 1,
  233. "toptype": 1,
  234. "subtype": 1,
  235. "area": 1,
  236. "s_subscopeclass": 1,
  237. "city": 1,
  238. "district": 1,
  239. "buyerclass": 1,
  240. "jsondata": 1,
  241. "budget": 1,
  242. "bidamount": 1,
  243. "isValidFile": 1,
  244. "site": 1,
  245. "agencyperson": 1,
  246. "agencytel": 1,
  247. "winnerperson": 1,
  248. "winnertel": 1,
  249. "signendtime": 1,
  250. "bidendtime": 1,
  251. "entidlist": 1,
  252. "autoid": 1,
  253. "filetext": 1,
  254. }
  255. if fields == nil {
  256. for k, v := range fields {
  257. queryField[k] = v
  258. }
  259. }
  260. var res []map[string]interface{}
  261. sess := mgo.GetMgoConn()
  262. defer mgo.DestoryMongoConn(sess)
  263. it := sess.DB(dbName).C(coll).Find(query).Select(queryField).Iter()
  264. index := 0
  265. for temp := make(map[string]interface{}); it.Next(&temp); {
  266. _id := BsonIdToSId(temp["_id"])
  267. if publishtime := util.Int64All(temp["publishtime"]); startTime-publishtime > 7*86400 {
  268. logger.Info(_id, "发布时间大于7天,不参与匹配", startTime, publishtime)
  269. continue
  270. }
  271. temp["_id"] = _id
  272. title, _ := temp["title"].(string)
  273. title = strings.ReplaceAll(title, "\n", "")
  274. temp["title"] = title
  275. if util.ObjToString(temp["area"]) == "A" {
  276. temp["area"] = "全国"
  277. }
  278. temp["attachment_count"] = GetAttachmentCount(temp)
  279. res = append(res, temp)
  280. if redisCache {
  281. //信息缓存3天
  282. info := map[string]interface{}{}
  283. for _, v := range SaveBiddingField {
  284. if v == "_id" || temp[v] == nil {
  285. continue
  286. }
  287. info[v] = temp[v]
  288. }
  289. info["detail"] = temp["detail"]
  290. redis.Put(Pushcache_1, "info_"+_id, info, OneDaySecond)
  291. }
  292. temp = make(map[string]interface{})
  293. index++
  294. if index%500 == 0 {
  295. logger.Info("加载", coll, "数据:", index)
  296. }
  297. }
  298. logger.Info(coll, "数据已经加载结束。。。", index)
  299. return &res, endTime
  300. }
  301. //
  302. func ToSortList(list interface{}) *SortList {
  303. sl := make(SortList, 0)
  304. if list == nil {
  305. return &sl
  306. }
  307. b, err := json.Marshal(list)
  308. if err != nil {
  309. return &sl
  310. }
  311. err = json.Unmarshal(b, &sl)
  312. if err != nil {
  313. return &sl
  314. }
  315. sort.Sort(sl)
  316. return &sl
  317. }
  318. //第一个参数是老数据,第二个参数是新进数据
  319. func MergeSortList(o, n interface{}, maxPushSize int) *SortList {
  320. of, oo := o.(*SortList)
  321. if !oo {
  322. of = ToSortList(o)
  323. }
  324. nf, no := n.(*SortList)
  325. if !no {
  326. nf = ToSortList(n)
  327. }
  328. idMap := map[string]bool{}
  329. for _, v := range *nf {
  330. idMap[util.ObjToString(v.Info["_id"])] = true
  331. }
  332. for _, v := range *of {
  333. if idMap[util.ObjToString(v.Info["_id"])] {
  334. continue
  335. }
  336. *nf = append(*nf, v)
  337. }
  338. sort.Sort(nf)
  339. if maxPushSize > 0 && len(*nf) > maxPushSize {
  340. *nf = (*nf)[:maxPushSize]
  341. }
  342. return nf
  343. }
  344. //获取招标信息附件数量
  345. func GetAttachmentCount(temp map[string]interface{}) int {
  346. isValidFile, _ := temp["isValidFile"].(bool)
  347. if isValidFile {
  348. return 1
  349. }
  350. return 0
  351. }
  352. //获取招标信息附件数量
  353. func GetAttachmentCountById(mgo *MongodbSim, dbName, coll, _id string) int {
  354. sess := mgo.GetMgoConn()
  355. defer mgo.DestoryMongoConn(sess)
  356. temp := map[string]interface{}{}
  357. sess.DB(dbName).C(coll).Find(map[string]interface{}{
  358. "_id": StringTOBsonId(_id),
  359. }).Select(map[string]interface{}{
  360. "isValidFile": 1,
  361. }).One(&temp)
  362. if temp != nil {
  363. return GetAttachmentCount(temp)
  364. }
  365. return -1
  366. }
  367. //
  368. func NewBiddingInfo(info map[string]interface{}, keys []string) *BiddingInfo {
  369. bi := &BiddingInfo{}
  370. bi.Title, _ = info["title"].(string)
  371. bi.ClearTitle = TitleClearRe.ReplaceAllString(strings.Replace(bi.Title, "\n", "", -1), "$1")
  372. bi.Area, _ = info["area"].(string)
  373. if bi.Area == "A" {
  374. bi.Area = "全国"
  375. }
  376. bi.AreaTitle = fmt.Sprintf("[%s]%s", bi.Area, bi.ClearTitle)
  377. bi.Publishtime = util.Int64All(info["publishtime"])
  378. bi.PublishtimeYMD = FormatDateByInt64(&bi.Publishtime, Date_Short_Layout)
  379. bi.PublishtimeDiff = util.TimeDiff(time.Unix(bi.Publishtime, 0))
  380. bi.Buyerclass, _ = info["buyerclass"].(string)
  381. bi.Subscopeclass = GetSubScopeClass(info["s_subscopeclass"])
  382. bi.Bidamount = info["bidamount"]
  383. bi.Budget = info["budget"]
  384. if bi.Bidamount != nil {
  385. bi.Acount = ConversionMoney(bi.Bidamount)
  386. } else if bi.Budget != nil {
  387. bi.Acount = ConversionMoney(bi.Budget)
  388. }
  389. bi.Id, _ = info["_id"].(string)
  390. bi.Subtype, _ = info["subtype"].(string)
  391. bi.Toptype, _ = info["toptype"].(string)
  392. bi.Infotype = bi.Subtype
  393. if bi.Infotype == "" {
  394. bi.Infotype = bi.Toptype
  395. }
  396. bi.HighlightTitle = bi.ClearTitle
  397. for _, kw := range keys {
  398. kws := strings.Split(kw, "+")
  399. n := 0
  400. otitle := bi.HighlightTitle
  401. for _, kwn := range kws {
  402. ot := strings.Replace(otitle, kwn, "<span class='keys'>"+kwn+"</span>", 1)
  403. if ot != bi.HighlightTitle {
  404. n++
  405. otitle = ot
  406. } else {
  407. break
  408. }
  409. }
  410. if n == len(kws) {
  411. bi.HighlightTitle = otitle
  412. break
  413. }
  414. }
  415. return bi
  416. }
  417. //
  418. func SortListSplit(list *SortList, f func(v interface{})) {
  419. l := len(*list)
  420. if l == 0 {
  421. return
  422. }
  423. i := Mgo_ListSize
  424. for {
  425. if l > i {
  426. arr := (*list)[i-Mgo_ListSize : i]
  427. f(&arr)
  428. } else if l > i-Mgo_ListSize {
  429. arr := (*list)[i-Mgo_ListSize:]
  430. f(&arr)
  431. break
  432. }
  433. i += Mgo_ListSize
  434. }
  435. }
  436. //
  437. func CSortListSplit(list *CSortList, f func(v interface{})) {
  438. l := len(*list)
  439. if l == 0 {
  440. return
  441. }
  442. i := Mgo_ListSize
  443. for {
  444. if l > i {
  445. arr := (*list)[i-Mgo_ListSize : i]
  446. f(&arr)
  447. } else if l > i-Mgo_ListSize {
  448. arr := (*list)[i-Mgo_ListSize:]
  449. f(&arr)
  450. break
  451. }
  452. i += Mgo_ListSize
  453. }
  454. }
  455. //获取企业授权超级订阅/大会员的用户
  456. func LoadEntProductUsers(msl *Mysql, testUserIds []int) (map[string]*UserInfo, map[int]*UserInfo, map[int]*UserInfo, []*UserInfo) {
  457. logger.Info("开始加载企业授权用户。。。")
  458. phoneMap := map[string]*UserInfo{}
  459. userMap := map[int]*UserInfo{}
  460. entMap := map[int]*UserInfo{}
  461. all := []*UserInfo{}
  462. query := `SELECT DISTINCT a.ent_id,IF(instr(a.product_type,'` + Ent_EmpowerMember + `')>0,'` + Ent_EmpowerMember + `','` + Ent_EmpowerVip + `') as product_type,c.phone,b.ent_user_id,d.name as ent_name,d.power_source,d.isNew from jianyu.entniche_wait_empower a
  463. inner join jianyu.entniche_power b on (a.end_time>? and b.status=1 and (a.product_type like '%` + Ent_EmpowerVip + `%' or a.product_type like '%` + Ent_EmpowerMember + `%') and a.id=b.wait_empower_id)
  464. inner join jianyu.entniche_user c on (`
  465. if len(testUserIds) > 0 {
  466. array := []string{}
  467. for _, v := range testUserIds {
  468. array = append(array, fmt.Sprint(v))
  469. }
  470. query += `c.id in (` + strings.Join(array, ",") + `) and `
  471. }
  472. query += `b.ent_user_id=c.id)
  473. inner join jianyu.entniche_info d on (d.id=a.ent_id)`
  474. msl.SelectByBath(200, func(l *[]map[string]interface{}) bool {
  475. for _, v := range *l {
  476. phone, _ := v["phone"].(string)
  477. if phone == "" {
  478. continue
  479. }
  480. u := &UserInfo{
  481. Entniche: &Entniche{
  482. EntId: util.IntAll(v["ent_id"]),
  483. EntName: util.ObjToString(v["ent_name"]),
  484. UserId: util.IntAll(v["ent_user_id"]),
  485. ProductType: util.ObjToString(v["product_type"]),
  486. PowerSource: util.IntAll(v["power_source"]),
  487. IsNew: util.IntAll(v["isNew"]),
  488. },
  489. Phone: phone,
  490. }
  491. if strings.Contains(u.Entniche.ProductType, Ent_EmpowerMember) {
  492. u.MemberStatus = 1
  493. } else if strings.Contains(u.Entniche.ProductType, Ent_EmpowerVip) {
  494. u.VipStatus = 1
  495. } else {
  496. continue
  497. }
  498. phoneMap[phone] = u
  499. userMap[u.Entniche.UserId] = u
  500. all = append(all, u)
  501. entMap[u.Entniche.EntId] = u
  502. logger.Info("加载企业授权用户", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Entniche.ProductType, u.Phone)
  503. }
  504. return true
  505. }, query, NowFormat(Date_Full_Layout))
  506. logger.Info("企业授权用户加载结束。。。", len(phoneMap), len(userMap), len(entMap), len(all))
  507. return phoneMap, userMap, entMap, all
  508. }
  509. //加载商机管理用户
  510. func LoadEntnicheUsers(msl *Mysql) map[string]bool {
  511. logger.Info("开始加载新版商机管理用户。。。")
  512. r := map[string]bool{}
  513. msl.SelectByBath(200, func(l *[]map[string]interface{}) bool {
  514. for _, v := range *l {
  515. phone := util.ObjToString(v["phone"])
  516. if phone != "" {
  517. r[phone] = true
  518. logger.Info("加载商机管理用户", phone)
  519. }
  520. }
  521. return true
  522. }, `SELECT b.phone from jianyu.entniche_info a INNER JOIN jianyu.entniche_user b on (a.status=1 and a.power_source is null and b.power=1 and a.id=b.ent_id)`)
  523. logger.Info("商机管理用户加载结束。。。", len(r))
  524. return r
  525. }
  526. //
  527. func GetWxTplMsg(subSet *SubSet) (string, string) {
  528. keyword := strings.Join(subSet.Keys, " ")
  529. if len([]rune(keyword)) > 100 {
  530. keyword = string([]rune(keyword)[:100]) + "..."
  531. }
  532. area := strings.Join(subSet.Areas, " ")
  533. if len([]rune(area)) > 100 {
  534. area = string([]rune(area)[:100]) + "..."
  535. }
  536. if area == "" {
  537. area = "全国"
  538. }
  539. return keyword, area
  540. }
  541. //
  542. func GetPhone(u map[string]interface{}) string {
  543. phone := util.ObjToString(u["s_phone"])
  544. if phone == "" {
  545. phone = util.ObjToString(u["s_m_phone"])
  546. }
  547. return phone
  548. }
  549. //
  550. func GetAllByEntUserId(mgo *MongodbSim, msl *Mysql, entUserId int) *map[string]interface{} {
  551. entUsers := msl.SelectBySql(`select phone from jianyu.entniche_user where id=?`, entUserId)
  552. if entUsers == nil || len(*entUsers) == 0 {
  553. logger.Info("entniche_user表中没有找到该企业用户", entUserId)
  554. return nil
  555. }
  556. phone, _ := (*entUsers)[0]["phone"].(string)
  557. if phone == "" {
  558. return nil
  559. }
  560. return getEntPushSet(mgo, msl, entUserId, phone)
  561. }
  562. //
  563. func GetAllByEntPositionId(mgo *MongodbSim, msl *Mysql, positionId int) *map[string]interface{} {
  564. position := msl.SelectBySql(`select a.ent_id,b.phone from base_service.base_position a inner join base_service.base_user b on (a.id=? and a.user_id=b.id)`, positionId)
  565. if position == nil || len(*position) == 0 {
  566. logger.Info("无效的职位id", position)
  567. return nil
  568. }
  569. entId := util.Int64All((*position)[0]["ent_id"])
  570. if entId == 0 {
  571. logger.Info("该职位id没有找到对应的企业id", position)
  572. return nil
  573. }
  574. phone, _ := (*position)[0]["phone"].(string)
  575. if phone == "" {
  576. logger.Info("该职位id没有找到对应的手机号", position)
  577. return nil
  578. }
  579. entUsers := msl.SelectBySql(`select id from jianyu.entniche_user where phone=? and ent_id=?`, phone, entId)
  580. if entUsers == nil || len(*entUsers) == 0 {
  581. logger.Info("entniche_user表中没有找到该企业用户", phone, entId)
  582. return nil
  583. }
  584. return getEntPushSet(mgo, msl, util.IntAll((*entUsers)[0]["id"]), phone)
  585. }
  586. //
  587. func getEntPushSet(mgo *MongodbSim, msl *Mysql, entUserId int, phone string) *map[string]interface{} {
  588. users, ok := mgo.Find(Mgo_User, map[string]interface{}{
  589. "$or": []map[string]interface{}{
  590. map[string]interface{}{
  591. "s_phone": phone,
  592. },
  593. map[string]interface{}{
  594. "s_m_phone": phone,
  595. },
  596. },
  597. }, `{"s_phone":-1}`, map[string]interface{}{
  598. "_id": 1,
  599. "s_m_openid": 1,
  600. "a_m_openid": 1,
  601. "s_phone": 1,
  602. "s_m_phone": 1,
  603. "i_ispush": 1,
  604. "s_jpushid": 1,
  605. "s_opushid": 1,
  606. "s_appponetype": 1,
  607. "base_user_id": 1,
  608. }, false, -1, -1)
  609. if !ok || users == nil || len(*users) == 0 {
  610. logger.Info("user表中没有找到该企业用户", entUserId, phone)
  611. return nil
  612. }
  613. user := map[string]interface{}{}
  614. for _, v := range *users {
  615. if user["_id"] == nil {
  616. user["_id"] = v["_id"]
  617. user["base_user_id"] = v["base_user_id"]
  618. }
  619. if user["s_phone"] == nil && util.ObjToString(v["s_phone"]) != "" {
  620. user["s_phone"] = v["s_phone"]
  621. }
  622. if user["s_m_phone"] == nil && util.ObjToString(v["s_m_phone"]) != "" {
  623. user["s_m_phone"] = v["s_m_phone"]
  624. }
  625. if user["a_m_openid"] == nil && util.ObjToString(v["a_m_openid"]) != "" {
  626. user["a_m_openid"] = v["a_m_openid"]
  627. }
  628. s_m_openid := util.ObjToString(v["s_m_openid"])
  629. i_ispush := util.IntAll(v["i_ispush"])
  630. s_jpushid := util.ObjToString(v["s_jpushid"])
  631. s_opushid := util.ObjToString(v["s_opushid"])
  632. s_appponetype := util.ObjToString(v["s_appponetype"])
  633. if user["s_m_openid"] == nil && user["i_ispush"] == nil && s_m_openid != "" && i_ispush == 1 {
  634. user["s_m_openid"] = s_m_openid
  635. user["i_ispush"] = i_ispush
  636. }
  637. if user["s_jpushid"] == nil && user["s_opushid"] == nil && user["s_appponetype"] == nil && s_appponetype != "" && (s_jpushid != "" || s_opushid != "") {
  638. user["s_jpushid"] = s_jpushid
  639. user["s_opushid"] = s_opushid
  640. user["s_appponetype"] = s_appponetype
  641. }
  642. }
  643. entniche_user, ok := mgo.FindOneByField(Mgo_Ent_User, map[string]interface{}{
  644. "i_userid": entUserId,
  645. }, `{"_id":0,"i_member_status":1,"i_vip_status":1,"o_pushset":1}`)
  646. if ok && entniche_user != nil && len(*entniche_user) > 0 {
  647. for k, v := range *entniche_user {
  648. user[k] = v
  649. }
  650. }
  651. entniche_rule, ok := mgo.Find("entniche_rule", map[string]interface{}{
  652. "i_userid": entUserId,
  653. }, nil, `{"_id":0,"o_entniche":1,"i_type":1}`, false, -1, -1)
  654. if ok && entniche_rule != nil {
  655. for _, v := range *entniche_rule {
  656. i_type := util.IntAll(v["i_type"])
  657. if i_type == 0 {
  658. user["o_entniche"] = v["o_entniche"]
  659. } else if i_type == 1 {
  660. user["o_vipjy"] = v["o_entniche"]
  661. user["o_member_jy"] = v["o_entniche"]
  662. } else if i_type == 2 {
  663. user["o_jy"] = v["o_entniche"]
  664. }
  665. }
  666. }
  667. return &user
  668. }
  669. //
  670. func GetEntUserPushset(mgo *MongodbSim, entUserId int) map[string]interface{} {
  671. temp, ok := mgo.FindOneByField(Mgo_Ent_User, map[string]interface{}{
  672. "i_userid": entUserId,
  673. }, `{"o_pushset":1}`)
  674. if ok && temp != nil && len(*temp) > 0 {
  675. o_pushset, _ := (*temp)["o_pushset"].(map[string]interface{})
  676. return o_pushset
  677. }
  678. return nil
  679. }
  680. //
  681. func GetEntUserSubset(mgo *MongodbSim, entUserId, tp int) map[string]interface{} {
  682. temp, ok := mgo.FindOneByField("entniche_rule", map[string]interface{}{
  683. "i_userid": entUserId,
  684. "i_type": tp,
  685. }, `{"o_entniche":1}`)
  686. if ok && temp != nil && len(*temp) > 0 {
  687. o_msgset, _ := (*temp)["o_entniche"].(map[string]interface{})
  688. return o_msgset
  689. }
  690. return nil
  691. }
  692. //格式化小时
  693. func HourFormat(hour int) string {
  694. if hour < 10 {
  695. return fmt.Sprintf("0%d:00", hour)
  696. } else {
  697. return fmt.Sprintf("%d:00", hour)
  698. }
  699. }
  700. //数组中的小时是否结束
  701. func TimesIsOver(times []string, hour int) (bool, time.Time, time.Time) {
  702. now := time.Now()
  703. if len(times) == 0 {
  704. return false, now, now
  705. }
  706. sort.Strings(times)
  707. lastHour := util.IntAll(strings.Split(times[len(times)-1], ":")[0])
  708. //跨天
  709. if lastHour == 23 && hour == 0 {
  710. start := time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local)
  711. end := time.Date(now.Year(), now.Month(), now.Day()-1, 23, 59, 59, 0, time.Local)
  712. return true, start, end
  713. } else {
  714. start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
  715. return hour-1 == lastHour, start, now
  716. }
  717. }
  718. //监听超时
  719. func MonitorTimeOut(pool chan bool, timeout time.Duration, warn string, f func()) bool {
  720. select {
  721. case <-time.After(timeout):
  722. go func() {
  723. f()
  724. if warn != "" {
  725. if _, err := http.Get(warn); err != nil {
  726. logger.Error("发送告警邮件错误", err)
  727. }
  728. }
  729. }()
  730. return false
  731. case pool <- true:
  732. }
  733. return true
  734. }
  735. //根据职位id获取用户信息
  736. func GetUserInfoByPosition(msl *Mysql, mgo *MongodbSim, id int64) *UserInfo {
  737. list := msl.SelectBySql(`select user_id from base_service.base_position where id=?`, id)
  738. if list == nil || len(*list) == 0 {
  739. return nil
  740. }
  741. data, ok := mgo.FindOneByField("user", map[string]interface{}{
  742. "base_user_id": util.Int64All((*list)[0]["user_id"]),
  743. }, `{"_id":1}`)
  744. if !ok || data == nil || len(*data) == 0 {
  745. return nil
  746. }
  747. return &UserInfo{
  748. Id: BsonIdToSId((*data)["_id"]),
  749. }
  750. }
  751. //资源中台权益
  752. var rcpLock = &sync.Mutex{}
  753. func ResourceCenterPowers(msl *Mysql, positionId int64) map[string]bool {
  754. rcpLock.Lock()
  755. if rcDb.Mysql_BaseService == nil {
  756. rcDb.Mysql_BaseService = &Mysql{
  757. Address: msl.Address,
  758. UserName: msl.UserName,
  759. PassWord: msl.PassWord,
  760. DBName: "base_service",
  761. MaxOpenConns: msl.MaxOpenConns,
  762. MaxIdleConns: msl.MaxIdleConns,
  763. }
  764. rcDb.Mysql_BaseService.Init()
  765. }
  766. rcpLock.Unlock()
  767. powers := map[string]bool{}
  768. if identity := IdentityByPositionId(msl, positionId); identity != nil {
  769. list, _ := rcService.HasPowers("10000", identity.AccountId, identity.EntAccountId, identity.EntId, identity.EntUserId)
  770. for _, v := range list {
  771. powers[v] = true
  772. }
  773. }
  774. return powers
  775. }