123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package award
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/message/db"
- "strings"
- "time"
- )
- //用户redis缓存
- type UserBaseMsg struct {
- Status int `json:"status"` //大会员状态
- VipStatus int `json:"vip_status"` //超级订阅状态
- EntnicheStatus int `json:"entniche_status"` //商机管理状态
- Registedate int64 `json:"registedate"` //用户注册时间
- EntIsNew bool `json:"entIsNew"` //是否是新版商机管理用户
- }
- // GetUserInfo 查看 22年活动 用户是否满足条件
- func GetUserInfo(userId string) *UserBaseMsg {
- userPower := UserBaseMsg{}
- if userId == "" {
- return &userPower
- }
- user, ok := db.Mgo.FindById("user", userId, `{"i_member_status":1,"l_registedate":1,"i_vip_status":1,"s_phone":1,"s_m_phone":1}`)
- if ok && user != nil && len(*user) > 0 {
- userPower.Status = common.IntAllDef((*user)["i_member_status"], 0)
- userPower.VipStatus = common.IntAllDef((*user)["i_vip_status"], 0)
- userPower.Registedate = common.Int64All((*user)["l_registedate"])
- phone, _ := common.If((*user)["s_phone"] != nil, (*user)["s_phone"], (*user)["s_m_phone"]).(string)
- if phone != "" {
- res := db.Mysql.SelectBySql(`SELECT i.isNew,i.name,i.phone,i.status,i.auth_status,u.power FROM entniche_user u LEFT JOIN entniche_info i
- ON u.ent_id=i.id
- WHERE u.phone=?
- ORDER BY i.status DESC,i.auth_status DESC, CASE WHEN i.phone=? THEN 0 ELSE 1 END ASC`, phone, phone)
- if res != nil && len(*res) > 0 {
- //已购买企业未过期-商机管理用户
- for _, v := range *res {
- if common.IntAll(v["status"]) == 1 && common.IntAll(v["power"]) == 1 {
- userPower.EntnicheStatus = 1
- if common.IntAll(v["isNew"]) == 1 {
- userPower.EntIsNew = true
- break
- }
- }
- }
- }
- }
- }
- return &userPower
- }
- // SaveQuestionnaire 保存问卷
- func SaveQuestionnaire(userId, phone, answers string) bool {
- id := db.Mgo.Save("double_eleven_22_q", map[string]interface{}{
- "l_create": time.Now().Unix(),
- "s_userid": userId,
- "s_phone": phone,
- "s_answers": strings.Split(answers, ","),
- })
- return id != ""
- }
- // GetWinnerInfo 查询活动期间内的中奖名单信息
- func GetWinnerInfo(startTime, endTime string) (rs []map[string]interface{}) {
- winnerInfo := db.Mysql.SelectBySql(`SELECT phone,winnerdate,mold FROM winner_info_22_10 WHERE winnerdate>=? and winnerdate<?`, startTime, endTime)
- if winnerInfo != nil && len(*winnerInfo) > 0 {
- for i := 0; i < len(*winnerInfo); i++ {
- data := (*winnerInfo)[i]
- phone := common.ObjToString(data["phone"])
- winnerDate := common.ObjToString(data["winnerdate"])
- if phone != "" && len([]rune(phone)) == 11 {
- data["phone"] = string(phone[0:3]) + "****" + string(phone[(len(phone)-4):])
- }
- switch common.ObjToString(data["mold"]) {
- case "1":
- data["mold"] = "获得小米智能音箱"
- case "2":
- data["mold"] = "获得iPad1台"
- case "3":
- data["mold"] = "免单"
- }
- if winnerDate != "" {
- data["winnerdate"] = string(winnerDate[0:10])
- }
- rs = append(rs, data)
- }
- }
- return rs
- }
|