public.go 21 KB

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