public.go 21 KB

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