customer.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package action
  2. import (
  3. qu "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  5. "app.yhyue.com/moapp/jybase/redis"
  6. "app.yhyue.com/moapp/jypkg/public"
  7. "commercialService/service/config"
  8. "encoding/json"
  9. "fmt"
  10. "strings"
  11. "time"
  12. )
  13. type Action struct {
  14. *xweb.Action
  15. info xweb.Mapper `xweb:"/customer/info"`
  16. }
  17. func init() {
  18. xweb.AddAction(&Action{})
  19. }
  20. func (a *Action) Info() {
  21. module := a.GetString("module")
  22. rMap := map[string]interface{}{}
  23. switch module {
  24. case "tripartiteAuth":
  25. cacheKey := fmt.Sprintf("ad_%s", module)
  26. obj := redis.Get("other", cacheKey)
  27. var adInfo []AdInfo
  28. if obj != nil {
  29. adInfo = Handle(obj.([]interface{}), a.Request.Host)
  30. } else {
  31. res, ok := public.MQFW.FindOneByField("ad", `{"s_code":"`+module+`"}`, `{"a_son":1,"l_modifydate":1}`)
  32. if ok && res != nil && (*res)["a_son"] != nil {
  33. son := (*res)["a_son"].([]interface{})
  34. if len(son) > 0 {
  35. redis.Put("other", cacheKey, son, int(GetLastTime()))
  36. }
  37. adInfo = Handle(son, a.Request.Host)
  38. }
  39. }
  40. if len(adInfo) > 0 {
  41. rMap = map[string]interface{}{
  42. "phone": adInfo[0].S_remark,
  43. "wxCodeImg": adInfo[0].S_pic,
  44. }
  45. }
  46. default:
  47. if data := config.Sysconfig.Info[module]; data != nil {
  48. if m := qu.ObjToMap(data); m != nil {
  49. rMap = *m
  50. }
  51. }
  52. }
  53. a.ServeJson(map[string]interface{}{
  54. "data": rMap,
  55. "error_msg": "",
  56. "erros_code": 0,
  57. })
  58. }
  59. // 获取当天剩余时间
  60. var (
  61. timeOut int64 = 24 * 60 * 60
  62. )
  63. func GetLastTime() int64 {
  64. t := time.Now()
  65. midnight := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
  66. if midnight.After(t) {
  67. return midnight.Unix() - t.Unix()
  68. }
  69. return timeOut
  70. }
  71. // AdInfo 广告信息
  72. type AdInfo struct {
  73. S_link string `json:"s_link"` //广告位跳转链接
  74. S_pic string `json:"s_pic"` //广告位弹窗
  75. S_remark string `json:"s_remark"` //备注
  76. S_picalt string `json:"s_picalt"` //图片ALT
  77. S_id string `json:"s_id"` //广告标识id
  78. O_extend struct {
  79. Linktype string `json:"linktype"` //是否外部链接
  80. Height string `json:"height"` //高度
  81. Width string `json:"width"` //宽度
  82. StartTime string `json:"startTime"` //开始时间
  83. EndTime string `json:"endTime"` //结束时间
  84. IosHref string `json:"iosHref"` //根据客户端不同 是否访问不同地址
  85. Theme string `json:"theme"` // 主题样式
  86. Title string `json:"title"` //标题
  87. Power string `json:"power"` // 权限判断
  88. Tab string `json:"tab"` // tab切换
  89. } `json:"o_extend"` //拓展属性
  90. S_script string `json:"s_script"` //脚本
  91. }
  92. // Handle 广告位信息处理
  93. func Handle(data []interface{}, host string) []AdInfo {
  94. var res = []AdInfo{}
  95. if len(data) > 0 {
  96. AdInfo_Arr := []AdInfo{}
  97. bytes, err := json.Marshal(data)
  98. if err != nil {
  99. return res
  100. }
  101. json.Unmarshal(bytes, &AdInfo_Arr)
  102. if len(AdInfo_Arr) > 0 {
  103. now := time.Now()
  104. for _, v := range AdInfo_Arr {
  105. //log.Println(v.S_id, "---", host, "----", strings.Contains(host, v.S_id))
  106. if v.S_id != "" && host != "" {
  107. //根据不同环境区分广告位信息 v.S_id 填充内容, 例:app-i2;app-a1
  108. if !strings.Contains(host, v.S_id) {
  109. continue
  110. }
  111. }
  112. if v.O_extend.StartTime != "" && len(strings.Split(v.O_extend.StartTime, "-")) == 6 {
  113. if thisTime, err := time.ParseInLocation("2006-01-02-15-04-05", v.O_extend.StartTime, time.Local); err == nil {
  114. //广告还未开始
  115. if thisTime.Unix() > now.Unix() {
  116. continue
  117. }
  118. }
  119. }
  120. if v.O_extend.EndTime != "" && len(strings.Split(v.O_extend.EndTime, "-")) == 6 {
  121. if thisTime, err := time.ParseInLocation("2006-01-02-15-04-05", v.O_extend.EndTime, time.Local); err == nil {
  122. //广告已经结束
  123. if thisTime.Unix() < now.Unix() {
  124. continue
  125. }
  126. }
  127. }
  128. res = append(res, v)
  129. }
  130. }
  131. }
  132. return res
  133. }