|
@@ -1,13 +1,123 @@
|
|
|
package share
|
|
|
|
|
|
-import "github.com/gogf/gf/v2/net/ghttp"
|
|
|
+import (
|
|
|
+ qu "app.yhyue.com/moapp/jybase/common"
|
|
|
+ se "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/message/config"
|
|
|
+ "app.yhyue.com/moapp/message/db"
|
|
|
+ "encoding/base64"
|
|
|
+ "fmt"
|
|
|
+ "github.com/SKatiyar/qr"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/net/ghttp"
|
|
|
+ "log"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
|
|
|
type ShareRouter struct{}
|
|
|
|
|
|
-func (c *ShareRouter) Index(r *ghttp.Request) {
|
|
|
- r.Response.Write("index")
|
|
|
+func (c *ShareRouter) Info(r *ghttp.Request) {
|
|
|
+ userid := r.Header.Get("userId")
|
|
|
+ res := map[string]interface{}{}
|
|
|
+ keyUser := fmt.Sprintf("SF_%s", userid)
|
|
|
+ if value := redis.GetStr("other", keyUser); value != "" {
|
|
|
+ varr := strings.Split(value, "#@#@")
|
|
|
+ link := fmt.Sprintf("%s/front/followGift/%s", config.PushConfig.Webdomain, varr[3])
|
|
|
+ r, _ := qr.Encode(link, qr.M)
|
|
|
+ pngdat := r.PNG()
|
|
|
+ res["data"] = map[string]interface{}{
|
|
|
+ "shareId": varr[3], //口令
|
|
|
+ "shareLink": link, //微信分享链接
|
|
|
+ "erUrl": base64.StdEncoding.EncodeToString(pngdat),
|
|
|
+ }
|
|
|
+ res["error_code"] = 0
|
|
|
+ res["error_msg"] = ""
|
|
|
+ } else {
|
|
|
+ nickname, headimageurl := "", ""
|
|
|
+ if data := GetInfo(userid); data != nil {
|
|
|
+ nickname = qu.ObjToString(data["nickname"])
|
|
|
+ headimageurl = qu.ObjToString(data["headimageurl"])
|
|
|
+ }
|
|
|
+ shareId := VarLSCPool.GetJob()
|
|
|
+ shareIdKey := fmt.Sprintf("shareId_%s", shareId)
|
|
|
+ value := fmt.Sprintf("%s#@#@%s#@#@%s#@#@%s", userid, nickname, headimageurl, shareIdKey)
|
|
|
+ redis.Put("other", shareIdKey, userid, -1)
|
|
|
+ redis.Put("other", keyUser, value, -1)
|
|
|
+ link := fmt.Sprintf("%s/front/followGift/%s", config.PushConfig.Webdomain, shareIdKey)
|
|
|
+ r, _ := qr.Encode(link, qr.M)
|
|
|
+ pngdat := r.PNG()
|
|
|
+ res["data"] = map[string]interface{}{
|
|
|
+ "shareId": shareIdKey, //口令
|
|
|
+ "shareLink": link, //微信分享链接
|
|
|
+ "erUrl": base64.StdEncoding.EncodeToString(pngdat),
|
|
|
+ }
|
|
|
+ res["error_code"] = 0
|
|
|
+ res["error_msg"] = ""
|
|
|
+ }
|
|
|
+ r.Response.WriteJson(res)
|
|
|
}
|
|
|
|
|
|
-func (c *ShareRouter) Show(r *ghttp.Request) {
|
|
|
- r.Response.Write("show")
|
|
|
+func (c *ShareRouter) Receive(r *ghttp.Request) {
|
|
|
+ openid := se.SE.DecodeString(r.Get("oid").String()) //被分享者openid
|
|
|
+ if db.Mgo.Count("user", map[string]interface{}{"s_m_openid": openid, "i_appid": 2}) > 0 {
|
|
|
+ r.Response.WriteJson(g.Map{
|
|
|
+ "error_code": -1,
|
|
|
+ "error_msg": "老用户无法领取奖励",
|
|
|
+ "data": map[string]interface{}{
|
|
|
+ "status": false,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ shareId := r.Get("shareId").String()
|
|
|
+ redisKey := fmt.Sprintf("rec_%s", openid)
|
|
|
+ log.Println(openid, shareId, redisKey) //分享者和被分享者对应关系
|
|
|
+ shareUserid := redis.GetStr("other", shareId) //获取分享者
|
|
|
+ if shareUserid == "" {
|
|
|
+ r.Response.WriteJson(g.Map{
|
|
|
+ "error_code": -1,
|
|
|
+ "error_msg": "领取失败",
|
|
|
+ "data": map[string]interface{}{
|
|
|
+ "status": false,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ r.Response.WriteJson(g.Map{
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": "",
|
|
|
+ "data": map[string]interface{}{
|
|
|
+ "status": redis.Put("other", redisKey, shareUserid, timeOut()),
|
|
|
+ },
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ShareRouter) List(r *ghttp.Request) {
|
|
|
+ userid := r.Get("userId").String()
|
|
|
+ pNum := r.Get("pageNum").Int()
|
|
|
+ pSize := r.Get("pagesize").Int()
|
|
|
+ rdata := map[string]interface{}{
|
|
|
+ "count": 0,
|
|
|
+ "haveNextPage": false,
|
|
|
+ "res": []map[string]interface{}{},
|
|
|
+ }
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "share_uid": userid,
|
|
|
+ }
|
|
|
+ count := db.Mgo.Count("user_share", query)
|
|
|
+ if count == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, _ := db.Mgo.Find("user_share", query, `{"createtime":-1}`, `{"shared_uid":1}`, false, pNum*pSize, pSize)
|
|
|
+ haveNextPage := (pNum+1)*pSize < count
|
|
|
+ rdata["count"] = count
|
|
|
+ rdata["haveNextPage"] = haveNextPage
|
|
|
+ rdata["pageSize"] = pSize
|
|
|
+ rdata["res"] = Info(result)
|
|
|
+ r.Response.WriteJson(g.Map{
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": "",
|
|
|
+ "data": rdata,
|
|
|
+ })
|
|
|
}
|