Browse Source

feat:新增获取所有可以申请的品种列表
新增获取上传文件接口

Roc 3 years ago
parent
commit
ee707f1531

+ 21 - 8
config/config.go

@@ -1,18 +1,20 @@
 package config
 
 type Config struct {
-	Log   Log   `mapstructure:"log" json:"log" yaml:"log"`
-	Serve Serve `mapstructure:"serve" json:"serve" yaml:"serve"`
-	Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
-	Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
+	Log    Log    `mapstructure:"log" json:"log" yaml:"log"`
+	Serve  Serve  `mapstructure:"serve" json:"serve" yaml:"serve"`
+	Mysql  Mysql  `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
+	Redis  Redis  `mapstructure:"redis" json:"redis" yaml:"redis"`
+	AliOss AliOss `mapstructure:"ali-oss" json:"ali-oss" yaml:"ali-oss"`
 }
 
 // Serve gin服务配置
 type Serve struct {
-	Port     int    `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
-	RunMode  string `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
-	UseRedis bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
-	AppName  string `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
+	Port      int    `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
+	RunMode   string `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
+	UseRedis  bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
+	AppName   string `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
+	StaticDir string `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
 }
 
 // Log 日志配置
@@ -46,3 +48,14 @@ type Redis struct {
 	Password string `mapstructure:"password" json:"password" yaml:"password" description:"redis服务密码"`
 	Db       int    `mapstructure:"db" json:"db" yaml:"db" description:"默认使用的redis库"`
 }
+
+// AliOss aliOss配置
+type AliOss struct {
+	BucketName      string `mapstructure:"bucket-name" json:"bucket-name" yaml:"bucket-name"`
+	EndPoint        string `mapstructure:"end-point" json:"end-point" yaml:"end-point"`
+	ImgHost         string `mapstructure:"img-host" json:"img-host" yaml:"img-host" description:"阿里oss主机地址"`
+	UploadDir       string `mapstructure:"upload-dir" json:"upload-dir" yaml:"upload-dir" description:"图片上传的文件目录"`
+	UploadAudioDir  string `mapstructure:"upload-audio-dir" json:"upload-audio-dir" yaml:"upload-audio-dir" description:"视频上传的文件目录"`
+	AccessKeyId     string `mapstructure:"access-key-id" json:"access-key-id" yaml:"access-key-id" description:"access-key-id"`
+	AccessKeySecret string `mapstructure:"access-key-secret" json:"access-key-secret" yaml:"access-key-secret" description:"access-key-secret"`
+}

+ 6 - 7
controller/activity/activity.go

@@ -29,7 +29,7 @@ import (
 func GetPageList(c *gin.Context) {
 	where, order := _handleListQuery(c)
 	page, limit := _handlePageParam(c)
-	userInfo := user.GetUserInfoByStruct(c)
+	userInfo := user.GetInfoByClaims(c)
 	listData, err := activity.PageList(where, page, limit, order, userInfo)
 	if err != nil {
 		response.Fail("活动获取失败", c)
@@ -107,7 +107,7 @@ func AddRemind(c *gin.Context) {
 		return
 	}
 	activityId, _ := strconv.Atoi(reqActivityId)
-	userInfo := user.GetUserInfoByStruct(c)
+	userInfo := user.GetInfoByClaims(c)
 	err := activity.CreateRemind(activityId, userInfo)
 	if err != nil {
 		response.Fail(err.Error(), c)
@@ -134,7 +134,7 @@ func CancelRemind(c *gin.Context) {
 		return
 	}
 	activityId, _ := strconv.Atoi(reqActivityId)
-	userInfo := user.GetUserInfoByStruct(c)
+	userInfo := user.GetInfoByClaims(c)
 	err := activity.CancelRemind(activityId, userInfo)
 	if err != nil {
 		response.Fail(err.Error(), c)
@@ -154,14 +154,14 @@ func CancelRemind(c *gin.Context) {
 // @Param activity_id query int true "活动ID"
 // @Success 200 ""
 // @Router /activity/registerActivity [post]
-func RegisterActivity(c *gin.Context)  {
+func RegisterActivity(c *gin.Context) {
 	reqActivityId := c.DefaultPostForm("activity_id", "0")
 	if reqActivityId == "0" {
 		response.Fail("参数异常", c)
 		return
 	}
 	activityId, _ := strconv.Atoi(reqActivityId)
-	userInfo := user.GetUserInfoByStruct(c)
+	userInfo := user.GetInfoByClaims(c)
 	err := activity.CreateRegister(activityId, userInfo)
 	if err != nil {
 		response.Fail(err.Error(), c)
@@ -188,7 +188,7 @@ func CancelRegister(c *gin.Context) {
 		return
 	}
 	activityId, _ := strconv.Atoi(reqActivityId)
-	userInfo := user.GetUserInfoByStruct(c)
+	userInfo := user.GetInfoByClaims(c)
 	err := activity.CancelRegister(activityId, userInfo)
 	if err != nil {
 		response.Fail(err.Error(), c)
@@ -235,4 +235,3 @@ func GetActivityVoices(c *gin.Context)  {
 		return
 	}
 	response.OkData("获取成功", "", c)
-}

+ 85 - 0
controller/public.go

@@ -0,0 +1,85 @@
+package controller
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/response"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/logic"
+	"hongze/hongze_yb/services"
+	"hongze/hongze_yb/utils"
+	"os"
+	"path"
+	"time"
+)
+
+// GetApplyVarietyList
+// @Tags 公共模块
+// @Summary  获取所有可以申请的品种权限列表
+// @Description 获取所有可以申请的品种权限列表
+// @Security ApiKeyAuth
+// @securityDefinitions.basic BasicAuth
+// @Param Authorization	header string true "微信登录后获取到的token"
+// @Accept  json
+// @Product json
+// @Success 200 {object} []logic.ApplyVariety "获取成功"
+// @failure 400 {string} string "获取失败"
+// @Router /public/get_apply_variety_list [get]
+func GetApplyVarietyList(c *gin.Context) {
+	list := logic.GetApplyVarietyList()
+	response.OkData("获取成功", list, c)
+}
+
+// Upload
+// @Tags 公共模块
+// @Summary  文件上传
+// @Description 文件上传
+// @Security ApiKeyAuth
+// @securityDefinitions.basic BasicAuth
+// @Param Authorization	header string true "微信登录后获取到的token"
+// @Param file formData file false "操作描述"
+// @Accept  multipart/form-data
+// @Product json
+// @Success 200 {object} string "上传成功"
+// @failure 400 {string} string "上传失败,存储目录创建失败"
+// @Router /public/upload [post]
+func Upload(c *gin.Context) {
+	// 单文件
+	file, err := c.FormFile("file")
+	fmt.Println("file", file)
+	if err != nil {
+		response.FailData("获取资源失败", "获取资源失败,Err:"+err.Error(), c)
+		return
+	}
+
+	ext := path.Ext(file.Filename)
+	dateDir := time.Now().Format("20060102")
+	uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
+	err = os.MkdirAll(uploadDir, 766)
+	if err != nil {
+		response.FailData("存储目录创建失败", "存储目录创建失败,Err:"+err.Error(), c)
+		return
+	}
+	randStr := utils.GetRandStringNoSpecialChar(28)
+	fileName := randStr + ext
+	fpath := uploadDir + "/" + fileName
+
+	// 上传文件至指定目录
+	err = c.SaveUploadedFile(file, fpath)
+	if err != nil {
+		response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
+		return
+	}
+	defer func() {
+		os.Remove(fpath)
+	}()
+
+	//上传到阿里云
+	resourceUrl, err := services.UploadAliyun(fileName, fpath)
+	if err != nil {
+		response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
+		return
+	}
+	response.OkData("文件上传成功", resourceUrl, c)
+
+}

+ 1 - 0
controller/response/base.go

@@ -20,6 +20,7 @@ func result(code int, resultData ResultData, c *gin.Context) {
 	//jsonByte, _ := json.Marshal(resultData)
 	//global.LOG.Debug("resultData:", string(jsonByte))
 	c.JSON(code, resultData)
+	c.Abort()
 }
 
 // OK 操作成功

+ 7 - 1
controller/user/user.go

@@ -15,6 +15,7 @@ import (
 // @Tags 用户模块
 // @Summary  用户登录
 // @Description 用户手机号/邮箱登录
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Accept  json
@@ -76,6 +77,7 @@ func Login(c *gin.Context) {
 // @Tags 用户模块
 // @Summary  获取短信验证码
 // @Description 获取短信验证码接口
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Param mobile	query string true "手机号"
@@ -112,6 +114,7 @@ func GetSmsCode(c *gin.Context) {
 // @Tags 用户模块
 // @Summary  获取邮箱验证码
 // @Description 获取邮箱验证码
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Param email	query string true "电子邮箱账号"
@@ -154,6 +157,7 @@ func GetEmailCode(c *gin.Context) {
 // @Tags 用户模块
 // @Summary  我的详情
 // @Description 我的详情
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Accept  json
@@ -163,7 +167,7 @@ func GetEmailCode(c *gin.Context) {
 // @Router /user/info [get]
 func Info(c *gin.Context) {
 	userInfo := userService.GetInfoByClaims(c)
-	list, err, errMsg := userLogic.GetUserInfo(*userInfo)
+	list, err, errMsg := userLogic.GetUserInfo(userInfo)
 	if err != nil {
 		if errMsg != "" {
 			errMsg = "获取失败"
@@ -179,6 +183,7 @@ func Info(c *gin.Context) {
 // @Tags 用户模块
 // @Summary  获取最近一条申请单信息
 // @Description 获取最近一条申请单信息
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Accept  json
@@ -206,6 +211,7 @@ func GetLastApplyRecord(c *gin.Context) {
 // @Tags 用户模块
 // @Summary  用户申请
 // @Description 用户申请
+// @Security ApiKeyAuth
 // @securityDefinitions.basic BasicAuth
 // @Param Authorization	header string true "微信登录后获取到的token"
 // @Accept  json

+ 2 - 2
controller/wechat/wechat.go

@@ -53,7 +53,7 @@ func Login(c *gin.Context) {
 		response.Fail("获取失败,Err:"+err.Error(), c)
 		return
 	}
-	token, userId, firstLogin, err := user.WxLogin(wx_app.WxPlatform, wxUserInfo)
+	token, userId, isBind, err := user.WxLogin(wx_app.WxPlatform, wxUserInfo)
 	if err != nil {
 		response.Fail("登录失败,Err:"+err.Error(), c)
 		return
@@ -61,7 +61,7 @@ func Login(c *gin.Context) {
 
 	response.OkData("获取成功", response2.LoginResp{
 		UserId:        userId,
-		FirstLogin:    firstLogin,
+		IsBind:        isBind,
 		Authorization: token,
 	}, c)
 }

+ 1 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.15
 
 require (
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
+	github.com/aliyun/aliyun-oss-go-sdk v1.9.8
 	github.com/fsnotify/fsnotify v1.5.1
 	github.com/gin-gonic/gin v1.7.4
 	github.com/go-playground/validator/v10 v10.9.0 // indirect

+ 2 - 0
init_serve/router.go

@@ -37,5 +37,7 @@ func InitRouter() (r *gin.Engine) {
 	routers.InitActivity(r)
 	//用户接口
 	routers.InitUser(r)
+	//公共接口
+	routers.InitPublic(r)
 	return
 }

+ 30 - 0
logic/public.go

@@ -0,0 +1,30 @@
+package logic
+
+type ApplyVariety struct {
+	Name   string `json:"name" description:"品种名称"`
+	PicUrl string `json:"pic_url" description:"品种图片"`
+}
+
+// GetApplyVarietyList 获取所有可以申请的品种权限
+func GetApplyVarietyList() (list []ApplyVariety) {
+	list = append(list, ApplyVariety{Name: "宏观经济", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/宏观经济.png"})
+	list = append(list, ApplyVariety{Name: "利率债", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/利率债.png"})
+	list = append(list, ApplyVariety{Name: "钢材", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/钢材.png"})
+	list = append(list, ApplyVariety{Name: "铁矿", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/铁矿.png"})
+	list = append(list, ApplyVariety{Name: "双焦(焦煤、焦炭)", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/双焦(焦煤、焦炭).png"})
+	list = append(list, ApplyVariety{Name: "有色(锌、铅)", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/有色(锌、铅).png"})
+	list = append(list, ApplyVariety{Name: "有色(铜、铝)", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/有色(铜、铝).png"})
+	list = append(list, ApplyVariety{Name: "镍+不锈钢", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/镍+不锈钢.png"})
+	list = append(list, ApplyVariety{Name: "原油", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/原油.png"})
+	list = append(list, ApplyVariety{Name: "聚烯烃", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/聚烯烃.png"})
+	list = append(list, ApplyVariety{Name: "苯乙烯", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/苯乙烯.png"})
+	list = append(list, ApplyVariety{Name: "甲醇", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/甲醇.png"})
+	list = append(list, ApplyVariety{Name: "玻璃纯碱", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/玻璃纯碱.png"})
+	list = append(list, ApplyVariety{Name: "橡胶", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/橡胶.png"})
+	list = append(list, ApplyVariety{Name: "聚酯", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/聚酯.png"})
+	list = append(list, ApplyVariety{Name: "PTA", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/PTA.png"})
+	list = append(list, ApplyVariety{Name: "MEG", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/MEG.png"})
+	list = append(list, ApplyVariety{Name: "沥青", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/沥青.png"})
+	list = append(list, ApplyVariety{Name: "织造终端", PicUrl: "http://hongze.oss-cn-shanghai.aliyuncs.com/static/yb_variety/织造终端.png"})
+	return
+}

+ 0 - 2
middleware/cors.go

@@ -1,7 +1,6 @@
 package middleware
 
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"net/http"
 )
@@ -18,7 +17,6 @@ func Cors() gin.HandlerFunc {
 		c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
 		c.Header("Access-Control-Allow-Credentials", "true")
 
-		fmt.Println("method:", method)
 		// 放行所有OPTIONS方法
 		if method == "OPTIONS" {
 			c.AbortWithStatus(http.StatusNoContent)

+ 10 - 0
middleware/recover.go

@@ -15,6 +15,16 @@ import (
 // Recover 异常处理
 func Recover() gin.HandlerFunc {
 	return func(c *gin.Context) {
+		contentType := c.ContentType()
+		// 为 multipart forms 设置较低的内存限制(50M) (默认是 32 MiB)
+		if contentType == "multipart/form-data" {
+			err := c.Request.ParseMultipartForm(-50 << 20)
+			if err != nil {
+				response.Custom(http.StatusRequestEntityTooLarge, "上传文件太大,err:"+err.Error(), c)
+				c.Abort()
+				return
+			}
+		}
 		defer func() {
 			if err := recover(); err != nil {
 				stack := ""

+ 1 - 1
middleware/token_no_login.go

@@ -67,7 +67,7 @@ func TokenNoLogin() gin.HandlerFunc {
 			return
 		}
 
-		c.Set("userInfo", &userInfo)
+		c.Set("userInfo", userInfo)
 		fmt.Println(userInfo)
 		c.Next()
 	}

+ 3 - 3
models/response/wechat.go

@@ -2,7 +2,7 @@ package response
 
 // LoginResp 登录接口返回数据
 type LoginResp struct {
-	UserId        int
-	FirstLogin    int
-	Authorization string
+	UserId        int    `json:"user_id" description:"用户id"`
+	IsBind        bool   `json:"is_bind" description:"是否绑定了账户,false则跳转到注册/绑定页面"`
+	Authorization string `json:"authorization" description:"token"`
 }

+ 16 - 0
routers/public.go

@@ -0,0 +1,16 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller"
+	"hongze/hongze_yb/middleware"
+)
+
+func InitPublic(r *gin.Engine) {
+	rGroup := r.Group("public").Use(middleware.Token())
+
+	{
+		rGroup.GET("/get_apply_variety_list", controller.GetApplyVarietyList)
+		rGroup.POST("/upload", controller.Upload)
+	}
+}

+ 1 - 1
services/activity/activity.go

@@ -7,7 +7,7 @@ import (
 )
 
 // PageList 活动分页列表
-func PageList(where map[string]interface{}, page, limit int, order string, userInfo *user.UserInfo) (data []*yb_activity.ActivityList, err error) {
+func PageList(where map[string]interface{}, page, limit int, order string, userInfo user.UserInfo) (data []*yb_activity.ActivityList, err error) {
 	data, err = yb_activity.GetPageListByWhereMap(where, page, limit, order, int(userInfo.UserID))
 	if err != nil {
 		fmt.Println("err:", err)

+ 2 - 2
services/activity/activity_register.go

@@ -11,7 +11,7 @@ import (
 )
 
 // CreateRegister 活动报名
-func CreateRegister(activityId int, userInfo *user.UserInfo) (err error) {
+func CreateRegister(activityId int, userInfo user.UserInfo) (err error) {
 	userId := int(userInfo.UserID)
 	ok, msg := checkRegisterOk(userId, activityId)
 	if !ok {
@@ -86,4 +86,4 @@ func CancelRegister(activityId int, userInfo *user.UserInfo) (err error) {
 		return
 	}
 	return
-}
+}

+ 2 - 2
services/activity/activity_remind.go

@@ -11,7 +11,7 @@ import (
 )
 
 // CreateRemind 新增提醒
-func CreateRemind(activityId int, userInfo *user.UserInfo) (err error) {
+func CreateRemind(activityId int, userInfo user.UserInfo) (err error) {
 	userId := int(userInfo.UserID)
 	ok, msg := checkRemindOk(userId, activityId)
 	if !ok {
@@ -82,4 +82,4 @@ func CancelRemind(activityId int, userInfo *user.UserInfo) (err error) {
 		err = errors.New("取消提醒失败")
 	}
 	return
-}
+}

+ 90 - 0
services/oss.go

@@ -0,0 +1,90 @@
+package services
+
+import (
+	"github.com/aliyun/aliyun-oss-go-sdk/oss"
+	"hongze/hongze_yb/global"
+	"os"
+	"time"
+)
+
+/*
+上传demo
+func init() {
+	fmt.Println("start")
+	randStr := utils.GetRandStringNoSpecialChar(28)
+	fileName :=  randStr + ".jpg"
+	fmt.Println("fileName:",fileName)
+	fpath:="./1.png"
+	resourceUrl,err:=UploadAliyun(fileName,fpath)
+	if err!=nil {
+		fmt.Println("UploadAliyun Err:",err.Error())
+		return
+	}
+	fmt.Println("resourceUrl:",resourceUrl)
+	fmt.Println("end")
+}
+*/
+
+// UploadAliyun 图片上传到阿里云
+func UploadAliyun(filename, filepath string) (string, error) {
+	client, err := oss.New(global.CONFIG.AliOss.EndPoint, global.CONFIG.AliOss.AccessKeyId, global.CONFIG.AliOss.AccessKeySecret)
+	if err != nil {
+		return "1", err
+	}
+	bucket, err := client.Bucket(global.CONFIG.AliOss.BucketName)
+	if err != nil {
+		return "2", err
+	}
+	path := global.CONFIG.AliOss.UploadDir + time.Now().Format("200601/20060102/")
+	path += filename
+	err = bucket.PutObjectFromFile(path, filepath)
+	if err != nil {
+		return "3", err
+	}
+	path = global.CONFIG.AliOss.ImgHost + path
+	return path, err
+}
+
+// UploadAudioAliyun 音频上传到阿里云
+func UploadAudioAliyun(filename, filepath string) (string, error) {
+	client, err := oss.New(global.CONFIG.AliOss.EndPoint, global.CONFIG.AliOss.AccessKeyId, global.CONFIG.AliOss.AccessKeySecret)
+	if err != nil {
+		return "1", err
+	}
+	bucket, err := client.Bucket(global.CONFIG.AliOss.BucketName)
+	if err != nil {
+		return "2", err
+	}
+	path := global.CONFIG.AliOss.UploadAudioDir + time.Now().Format("200601/20060102/")
+	path += filename
+	err = bucket.PutObjectFromFile(path, filepath)
+	if err != nil {
+		return "3", err
+	}
+	path = global.CONFIG.AliOss.ImgHost + path
+	return path, err
+}
+
+// UploadVideoAliyun 视频上传到阿里云
+func UploadVideoAliyun(filename, filepath, savePath string) error {
+	defer func() {
+		os.Remove(filepath)
+	}()
+	client, err := oss.New(global.CONFIG.AliOss.EndPoint, global.CONFIG.AliOss.AccessKeyId, global.CONFIG.AliOss.AccessKeySecret)
+	if err != nil {
+		return err
+	}
+	bucket, err := client.Bucket(global.CONFIG.AliOss.BucketName)
+	if err != nil {
+		return err
+	}
+	//path := global.CONFIG.AliOss.UploadAudioDir + time.Now().Format("200601/20060102/")
+	//path += filename
+	err = bucket.PutObjectFromFile(savePath, filepath)
+	if err != nil {
+		return err
+	}
+	//path = global.CONFIG.AliOss.ImgHost + path
+	//return path,err
+	return err
+}

+ 6 - 21
services/user/user.go

@@ -167,13 +167,10 @@ func formatWxUser(wxUser *wx_user.WxUser, platform int) (userInfo UserInfo) {
 }
 
 // WxLogin 微信登录
-func WxLogin(wxPlatform int, wxSession auth.ResCode2Session) (token string, userId, firstLogin int, err error) {
+func WxLogin(wxPlatform int, wxSession auth.ResCode2Session) (token string, userId int, isBind bool, err error) {
 	openId := wxSession.OpenID
 	unionId := wxSession.UnionID
 
-	//firstLogin==1,强制绑定手机号或者邮箱
-	firstLogin = 1
-
 QUERY_WX_USER:
 	wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
 	if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
@@ -187,7 +184,6 @@ QUERY_WX_USER:
 		goto QUERY_WX_USER
 	} else if wxUserErr == ERR_USER_NOT_BIND {
 		//没有用户信息
-		//wxUser.FirstLogin = 1
 	} else if wxUserErr != nil {
 		err = wxUserErr
 		return
@@ -195,18 +191,15 @@ QUERY_WX_USER:
 
 	//如果已经登录注册绑定的情况下
 	if wxUserErr == nil {
-		//获取用户权限
-		firstLogin = int(wxUser.FirstLogin)
 		userId = int(wxUser.UserID)
 
 		//if wxUserInfo != nil {
 		//	go models.ModifyUserRecordInfo(openId, wxUserInfo.Nickname, wxUserInfo.Headimgurl, wxUserInfo.City, wxUserInfo.Province, wxUserInfo.Country, wxUserInfo.Sex, userId)
 		//}
 
-		if wxUser.Mobile == "" && wxUser.Email == "" {
-			firstLogin = 1
-		} else {
-			firstLogin = 0
+		// 如果账户有绑定了手机号或者邮箱,那么标记为已绑定
+		if wxUser.Mobile != "" || wxUser.Email != "" {
+			isBind = true
 		}
 	}
 
@@ -299,17 +292,9 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
 }
 
 // GetInfoByClaims 从Claims中获取用户信息
-func GetInfoByClaims(c *gin.Context) (userInfo *UserInfo) {
+func GetInfoByClaims(c *gin.Context) (userInfo UserInfo) {
 	//获取jwt数据失败
 	claims, _ := c.Get("userInfo")
-	userInfo = claims.(*UserInfo)
-	return
-}
-
-// GetUserInfoByStruct 用户信息struct
-func GetUserInfoByStruct(c *gin.Context) (userInfo *UserInfo) {
-	wxUser, _ := c.Get("userInfo")
-	wxUserJson, _ := json.Marshal(wxUser)
-	_ = json.Unmarshal(wxUserJson, &userInfo)
+	userInfo = claims.(UserInfo)
 	return
 }