浏览代码

feat:渠道合作商

wangshan 1 年之前
父节点
当前提交
d09fca228c
共有 1 个文件被更改,包括 50 次插入0 次删除
  1. 50 0
      common/src/qfw/util/jy/channel.go

+ 50 - 0
common/src/qfw/util/jy/channel.go

@@ -0,0 +1,50 @@
+package jy
+
+import (
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jybase/mysql"
+	"net/http"
+	"time"
+)
+
+var (
+	ChannelCookieName = "channelCode"
+)
+
+// SetCookieValue 更新cookie信息
+func SetCookieValue(rw http.ResponseWriter, name, val string, timeOut int) {
+	http.SetCookie(rw, func() *http.Cookie {
+		maxAge := timeOut //单位秒
+		expires := time.Now().Add(time.Duration(timeOut) * time.Second)
+		cookie := &http.Cookie{
+			Name:     name,
+			Value:    val,
+			Path:     "/",
+			HttpOnly: false,
+			MaxAge:   maxAge,
+			Expires:  expires,
+			Domain:   httpsession.Domain,
+		}
+		return cookie
+	}())
+}
+
+type UserSource struct {
+	UserId           string `json:"user_id"`            //用户id
+	Phone            string `json:"phone"`              //手机号
+	State            int    `json:"state"`              //注册/登录标志 1:登录;2:注册
+	ChannelCode      string `json:"channel_code"`       //渠道代码
+	EncryptionUserId string `json:"encryption_user_id"` //用户加密id
+	CreateTime       string `json:"create_time"`        //创建时间
+	LoginWay         int    `json:"login_way"`          //登录方式;1:手机号密码登录;2:手机号验证码登录;3:微信登录;4:手机号一键登录
+	Platform         int    `json:"platform"`           //登录端;1:PC;2:WX;3:APP;4:H5
+	Ip               string `json:"ip"`                 //登录ip
+}
+
+// SaveUserSource 保存 user_source 表 > 剑鱼用户注册/登录
+func SaveUserSource(tidb *mysql.Mysql, tableName string, insertMap map[string]interface{}) bool {
+	if insertMap != nil && len(insertMap) > 0 {
+		return tidb.Insert(tableName, insertMap) > 0
+	}
+	return false
+}