|
@@ -0,0 +1,182 @@
|
|
|
+package manage
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "qfw/jgpush"
|
|
|
+ "qfw/util"
|
|
|
+ . "qfw/util/mongodb"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+ uc "ucbsutil"
|
|
|
+ ca "ucbsutil/cassandra"
|
|
|
+
|
|
|
+ "github.com/go-xweb/xweb"
|
|
|
+ "gopkg.in/mgo.v2/bson"
|
|
|
+)
|
|
|
+
|
|
|
+type Message struct {
|
|
|
+ *xweb.Action
|
|
|
+ //消息管理
|
|
|
+ index xweb.Mapper `xweb:"/manage/message/(\\w+)"`
|
|
|
+ sendIndex xweb.Mapper `xweb:"/manage/message/sendIndex"`
|
|
|
+ detail xweb.Mapper `xweb:"/manage/message/detail"`
|
|
|
+ sase xweb.Mapper `xweb:"/manage/message/send"`
|
|
|
+ list xweb.Mapper `xweb:"/manage/message/list"`
|
|
|
+ content xweb.Mapper `xweb:"/manage/message/content/(\\w+)"`
|
|
|
+ receive xweb.Mapper `xweb:"/front/message/receive"`
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (m *Message) Content(id string) error {
|
|
|
+ defer util.Catch()
|
|
|
+ if m.GetSession("loginName") == nil {
|
|
|
+ return m.Redirect("/")
|
|
|
+ } else {
|
|
|
+ r := FindById("message_app", id, nil)
|
|
|
+ if nil != r {
|
|
|
+ (*r)["_id"] = strings.Split(fmt.Sprintf("%s", (*r)["_id"]), `"`)[1]
|
|
|
+ data_3 := (*r)["l_submitdate"]
|
|
|
+ (*r)["l_submitdate"] = util.FormatDateWithObj(&data_3, util.Date_Full_Layout)
|
|
|
+ }
|
|
|
+ m.T = *r
|
|
|
+ return m.Render("/manage/message/detail.html")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (m *Message) List() error {
|
|
|
+ defer util.Catch()
|
|
|
+ if m.GetSession("loginName") == nil {
|
|
|
+ return m.Redirect("/")
|
|
|
+ } else {
|
|
|
+ if m.Method() == "POST" {
|
|
|
+ size, _ := m.GetInteger("perPage")
|
|
|
+ if size > 100 {
|
|
|
+ m.ServeJson(&map[string]interface{}{
|
|
|
+ "msg": "soory,size too many!",
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ currentPage, _ := m.GetInteger("currentPage")
|
|
|
+ search := m.GetString("query")
|
|
|
+ res := map[string]interface{}{}
|
|
|
+ query := `{`
|
|
|
+ if len(search) > 0 {
|
|
|
+ query = query + `"s_title":{"$regex":"` + search + `"}`
|
|
|
+ }
|
|
|
+ query = query + "}"
|
|
|
+ res["totalRows"] = Count("message_app", query)
|
|
|
+ data := *Find("message_app", query, `{"l_submitdate": -1}`, nil, false, (currentPage-1)*size, size)
|
|
|
+ for _, v := range data {
|
|
|
+ data_1 := v["l_submitdate"]
|
|
|
+ v["l_submitdate"] = util.FormatDateWithObj(&data_1, util.Date_Short_Layout)
|
|
|
+ }
|
|
|
+ res["data"] = data
|
|
|
+ res["currentPage"] = currentPage
|
|
|
+ m.ServeJson(&res)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (m *Message) Sase() error {
|
|
|
+ defer util.Catch()
|
|
|
+ flag := "F"
|
|
|
+ if m.GetSession("loginName") == nil {
|
|
|
+ return m.Redirect("/")
|
|
|
+ } else {
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["s_title"] = m.GetString("title")
|
|
|
+ data["s_subtitle"] = m.GetString("subtitle")
|
|
|
+ data["s_url"] = m.GetString("url")
|
|
|
+ data["i_total"], _ = m.GetInteger("total")
|
|
|
+ data["i_delivery"], _ = m.GetInteger("delivery")
|
|
|
+ data["i_click"], _ = m.GetInteger("click")
|
|
|
+ data["s_sender"] = m.GetSession("loginName")
|
|
|
+ data["l_submitdate"] = time.Now().Unix()
|
|
|
+ id := Save("message_app", data)
|
|
|
+ if len(id) > 0 {
|
|
|
+ flag = "T"
|
|
|
+ jgpush.JPush()
|
|
|
+ title := m.GetString("title")
|
|
|
+ subtitle := m.GetString("subtitle")
|
|
|
+ if len([]rune(subtitle)) > 80 {
|
|
|
+ subtitle = string([]rune(subtitle)[:80]) + "..."
|
|
|
+ }
|
|
|
+ go sendMes(id, title, subtitle, m.GetString("url"))
|
|
|
+ // jpushid := "18171adc035c24ee76e"
|
|
|
+ // openid := "ocXeA0juxw7b7A_bjXVy0NSJF5f0"
|
|
|
+ // jgpush.JgpushD_Nc(subtitle, "message", []string{jpushid}, map[string]interface{}{
|
|
|
+ // "url": m.GetString("url") + "==" + id,
|
|
|
+ // "openid": openid,
|
|
|
+ // "title": title,
|
|
|
+ // "type": "message",
|
|
|
+ // "extend": map[string]interface{}{"linkType": "external"},
|
|
|
+ // }, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m.ServeJson(map[string]interface{}{
|
|
|
+ "flag": flag,
|
|
|
+ })
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func sendMes(id, title, subtitle, url string) error {
|
|
|
+ defer util.Catch()
|
|
|
+ userData := Find("user", `{"i_ispush": 1, "i_type":{"$in": [1,2]}}`, `{"l_registedate":-1}`, `{"s_m_openid":1,"s_jpushid":1,"s_province":1,"s_city":1,"s_nickname":1}`, false, -1, -1)
|
|
|
+ var total = 0
|
|
|
+ for _, v := range *userData {
|
|
|
+ jpushid := util.ObjToString(v["s_jpushid"])
|
|
|
+ openid := util.ObjToString(v["s_m_openid"])
|
|
|
+ province := util.ObjToString(v["s_province"])
|
|
|
+ city := util.ObjToString(v["s_city"])
|
|
|
+ nickname := util.ObjToString(v["s_nickname"])
|
|
|
+ if jpushid != "" && openid != "" && id != "" {
|
|
|
+ total = total + 1
|
|
|
+ go ca.SaveCache("jy_message", map[string]interface{}{
|
|
|
+ "id": uc.DayShortTime(),
|
|
|
+ "openid": openid,
|
|
|
+ "mid": id,
|
|
|
+ "title": title,
|
|
|
+ "subtitle": subtitle,
|
|
|
+ "province": province,
|
|
|
+ "city": city,
|
|
|
+ "nickname": nickname,
|
|
|
+ "action": "S", //S:发送 D:送达 C:打开
|
|
|
+ "date": time.Now().Unix(),
|
|
|
+ "url": url,
|
|
|
+ })
|
|
|
+ jgpush.Jgconfig.Title["message"] = title
|
|
|
+ jgpush.JgpushNc(subtitle, "message", []string{jpushid}, map[string]interface{}{
|
|
|
+ "url": url + "==" + id,
|
|
|
+ "openid": openid,
|
|
|
+ "title": title,
|
|
|
+ "type": "message",
|
|
|
+ }, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ go Update("message_app", map[string]interface{}{"_id": bson.ObjectIdHex(id)}, map[string]interface{}{"$set": map[string]interface{}{"i_total": total}}, false, false)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (m *Message) Index(pageType string) error {
|
|
|
+ defer util.Catch()
|
|
|
+ if m.GetSession("loginName") == nil {
|
|
|
+ return m.Redirect("/")
|
|
|
+ } else {
|
|
|
+ var userid = m.GetSession("userId").(string)
|
|
|
+ u := FindOne("user", "{'_id':'"+userid+"'}")
|
|
|
+ u_type := (*u)["i_type"]
|
|
|
+ if u_type == 0 {
|
|
|
+ return m.Render("/manage/message/" + pageType + ".html")
|
|
|
+ } else {
|
|
|
+ return m.Redirect("/")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//
|