|
@@ -47,31 +47,38 @@ func (m *Mobile) Wxrssset() error {
|
|
|
if m.Session().Get("userId") != nil {
|
|
|
m.T["signature"] = GetSignature(m.Url())
|
|
|
userInfo := mongodb.FindById("user", m.GetSession("userId").(string), nil)
|
|
|
- if i_m_guide := (*userInfo)["i_m_guide"]; util.IntAll(i_m_guide) == 0 {
|
|
|
- mongodb.Update("user", `{"_id":"`+m.GetSession("userId").(string)+`"}`, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_m_guide": 1,
|
|
|
- },
|
|
|
- }, false, false)
|
|
|
- return m.Redirect("/swordfish/guide")
|
|
|
- }
|
|
|
- for _, v := range (*userInfo)["o_msgset"].(map[string]interface{}) {
|
|
|
- if vobj, ok := v.(map[string]interface{}); ok {
|
|
|
- if vobj["l_enddate"] != nil && vobj["i_status"] != nil {
|
|
|
- if util.IntAll(vobj["i_status"]) == 1 {
|
|
|
- sub := vobj["l_enddate"].(int64) - time.Now().Unix()
|
|
|
- if sub >= 0 {
|
|
|
- if sub%86400 == 0 {
|
|
|
- vobj["days"] = sub / 86400
|
|
|
- } else {
|
|
|
- vobj["days"] = sub/86400 + 1
|
|
|
+ if *userInfo != nil {
|
|
|
+ if i_m_guide := (*userInfo)["i_m_guide"]; util.IntAll(i_m_guide) == 0 {
|
|
|
+ mongodb.Update("user", `{"_id":"`+m.GetSession("userId").(string)+`"}`, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_m_guide": 1,
|
|
|
+ },
|
|
|
+ }, false, false)
|
|
|
+ return m.Redirect("/swordfish/guide")
|
|
|
+ }
|
|
|
+ if (*userInfo)["o_msgset"] != nil {
|
|
|
+ for _, v := range (*userInfo)["o_msgset"].(map[string]interface{}) {
|
|
|
+ if vobj, ok := v.(map[string]interface{}); ok {
|
|
|
+ if vobj["l_enddate"] != nil && vobj["i_status"] != nil {
|
|
|
+ if util.IntAll(vobj["i_status"]) == 1 {
|
|
|
+ sub := vobj["l_enddate"].(int64) - time.Now().Unix()
|
|
|
+ if sub >= 0 {
|
|
|
+ if sub%86400 == 0 {
|
|
|
+ vobj["days"] = sub / 86400
|
|
|
+ } else {
|
|
|
+ vobj["days"] = sub/86400 + 1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ vobj["days"] = 0
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ m.T["msgset"] = (*userInfo)["o_msgset"]
|
|
|
}
|
|
|
- m.T["msgset"] = (*userInfo)["o_msgset"]
|
|
|
+
|
|
|
return m.Render("/swordfish/wxrssset.html", &m.T)
|
|
|
} else {
|
|
|
return m.Render("_err.html")
|
|
@@ -117,55 +124,70 @@ func (m *Mobile) SwordfishPay() error {
|
|
|
types := m.GetSlice("types")
|
|
|
res["flag"] = true
|
|
|
if len(types) > 0 {
|
|
|
- //获取积分
|
|
|
- user := getMsgSetById(userId.(string))
|
|
|
- if user == nil {
|
|
|
- res["flag"] = false
|
|
|
- } else {
|
|
|
- i_credit := util.IntAll(user["i_credit"])
|
|
|
- if i_credit > 0 {
|
|
|
- isPay := map[string]interface{}{}
|
|
|
- for _, v := range types {
|
|
|
- util.Try(func() {
|
|
|
- obj_typei := user["o_msgset"].(map[string]interface{})[v]
|
|
|
- b_newopen := false
|
|
|
- if obj_typei == nil {
|
|
|
- b_newopen = true
|
|
|
- } else {
|
|
|
- obj_type := obj_typei.(map[string]interface{})
|
|
|
- st := obj_type["i_status"]
|
|
|
- objt := obj_type["l_enddate"]
|
|
|
- if st == nil || objt == nil {
|
|
|
+ no, _ := m.GetInteger("no")
|
|
|
+ if no == 0 {
|
|
|
+ //获取积分
|
|
|
+ user := getMsgSetById(userId.(string))
|
|
|
+ if user == nil {
|
|
|
+ res["flag"] = false
|
|
|
+ } else {
|
|
|
+ i_credit := util.IntAll(user["i_credit"])
|
|
|
+ if i_credit > 0 {
|
|
|
+ isPay := map[string]interface{}{}
|
|
|
+ for _, v := range types {
|
|
|
+ util.Try(func() {
|
|
|
+ obj_typei := user["o_msgset"].(map[string]interface{})[v]
|
|
|
+ b_newopen := false
|
|
|
+ if obj_typei == nil {
|
|
|
b_newopen = true
|
|
|
} else {
|
|
|
- //判断是否开启
|
|
|
- i_st := st.(int)
|
|
|
- l_objt := objt.(int64)
|
|
|
- if !(i_st == 1 && l_objt > util.GetDayStartSecond(0)) {
|
|
|
+ obj_type := obj_typei.(map[string]interface{})
|
|
|
+ st := obj_type["i_status"]
|
|
|
+ objt := obj_type["l_enddate"]
|
|
|
+ if st == nil || objt == nil {
|
|
|
b_newopen = true
|
|
|
+ } else {
|
|
|
+ //判断是否开启
|
|
|
+ i_st := st.(int)
|
|
|
+ l_objt := objt.(int64)
|
|
|
+ if !(i_st == 1 && l_objt > util.GetDayStartSecond(0)) {
|
|
|
+ b_newopen = true
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if b_newopen { //进行扣费操作
|
|
|
+ isPay[v] = v
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println(e)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //i_credit -= len(isPay) * 1000
|
|
|
+ if i_credit >= 0 {
|
|
|
+ if b, _ := credit.OutCreditB(userId.(string), credit.V_JY, util.ObjToString(m.GetSession("s_m_openid")), 0, isPay); b {
|
|
|
+ //先扣分,然后更新,然后返回结果
|
|
|
+ res["credit"] = i_credit
|
|
|
+ res["oprstatus"] = true
|
|
|
}
|
|
|
- if b_newopen { //进行扣费操作
|
|
|
- isPay[v] = v
|
|
|
- }
|
|
|
- }, func(e interface{}) {
|
|
|
- log.Println(e)
|
|
|
- })
|
|
|
- }
|
|
|
- i_credit -= len(isPay) * 1000
|
|
|
- if i_credit >= 0 {
|
|
|
- if b, _ := credit.OutCreditB(userId.(string), credit.V_JY, -len(isPay)*1000, isPay); b {
|
|
|
- //先扣分,然后更新,然后返回结果
|
|
|
+ } else {
|
|
|
res["credit"] = i_credit
|
|
|
- res["oprstatus"] = true
|
|
|
}
|
|
|
+
|
|
|
} else {
|
|
|
res["credit"] = i_credit
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- res["credit"] = i_credit
|
|
|
+ } else if no == 1 {
|
|
|
+ //取消操作
|
|
|
+ set := map[string]interface{}{}
|
|
|
+ for _, v := range types {
|
|
|
+ set["o_msgset."+v+".i_switchstatus"] = 0
|
|
|
+ }
|
|
|
+ if mongodb.Update("user", `{"_id":"`+userId.(string)+`"}`, &map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ }, false, false) {
|
|
|
+ res["oprstatus"] = true
|
|
|
}
|
|
|
}
|
|
|
}
|