123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- package controllers
- import (
- "fmt"
- "github.com/aliyun/aliyun-oss-go-sdk/oss"
- "github.com/gin-gonic/gin"
- "lzyd-user-api/common"
- "lzyd-user-api/models"
- "lzyd-user-api/services"
- "os"
- "strings"
- )
- // @tags Customer
- // @Description 获取用户详细信息
- // @Summary 获取用户详细信息
- // @Produce json
- // @Param user_id query string true "用户ID"
- // @Param other_id query string false "另一个用户id"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"user_id":"","mobile_phone":"","user_name":"","avatar":"https://","gender":2,"birthday":"","area":"江苏省-南京市-鼓楼区","email":"","customer_level":0,"user_point":0,"user_money":0.00,"register_time":""}}}"
- // @Router /customer/getInfo [get]
- func GetCustomerInfo(c *gin.Context) {
- userCode := c.Query("user_id")
- if len(userCode) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model models.UserInfo
- code = common.Success
- )
- otherCode := c.Query("other_id")
- model = services.QueryUserByCode(userCode)
- if model.Id == 0 {
- code = common.SystemHasNoUser
- }
- if len(otherCode) != 0 {
- relation := services.UserRelation(userCode,otherCode)
- fmt.Println(relation)
- if len(relation) > 0 {
- model.AttentionUserId = relation
- }
- }
- if common.Success == code {
- // 修改上一次登录时间
- //_ = model.UpdateLoginTime()
- common.GenResp(c, code, "SUCCESS", model)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
- // @tags Customer
- // @Description 修改用户资料
- // @Summary 修改用户资料
- // @Produce json
- // @Param body body models.UpdateProfileReq true "修改用户资料请求内容"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{}}"
- // @Router /customer/updateProfile [post]
- func UpdateProfile(c *gin.Context) {
- var req models.UpdateProfileReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- panic(err)
- }
- if len(req.UserId) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model models.UserInfo
- code = common.Success
- )
- model = services.QueryUserByCode(req.UserId)
- if model.Id == 0 {
- code = common.SystemHasNoUser
- common.GenResp(c, code, "系统不存在该用户", nil)
- return
- }
- fmt.Println(req)
- if len(req.UserName) > 0 {
- model.UserName = req.UserName
- }
- if len(req.Birthday) > 0 {
- model.Birthday = req.Birthday
- }
- if len(req.Area) > 0 {
- model.Area = req.Area
- }
- if req.Gender > 0 {
- model.Gender = req.Gender
- }
- if req.Height > 0 {
- model.Height = req.Height
- }
- if req.Weight > 0 {
- model.Weight = req.Weight
- }
- if len(req.UserAvatar) > 0 {
- model.UserAvatar = req.UserAvatar
- }
- if err := model.UpdateProfile(common.DB); err != nil {
- code = common.DbUpdateErr
- }
- if common.Success == code {
- if len(model.UserAvatar) == 0 {
- model.UserAvatar = common.SystemInfo.Avatar
- }
- // 修改成功后的处理
- var ret = models.UserResp{
- Id: model.Id,
- UserId: model.UserId,
- UserName: model.UserName,
- RealName: model.RealName,
- UserAvatar: model.UserAvatar,
- Gender: model.Gender,
- Birthday: model.Birthday,
- Area: model.Area,
- Weight: model.Weight,
- Height: model.Height,
- AppId: model.AppId,
- }
- common.GenResp(c, code, "SUCCESS", ret)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
- // @tags Customer
- // @Description 获取用户黑白名单列表
- // @Summary 获取用户黑白名单列表
- // @Produce json
- // @Param body body models.GetBlackListReq true "获取黑白名单列表"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"user_id":"","username":"","user_avatar":"https://"}}}"
- // @Router /customer/getBlacklist [post]
- func GetBlacklist(c *gin.Context) {
- var req models.GetBlackListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- panic(err)
- }
- if len(req.UserId) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model []models.BlackListReq
- code = common.Success
- )
- model = services.QueryBlackByCode(req.UserId,req.Type)
- if common.Success == code {
- // 修改上一次登录时间
- //_ = model.UpdateLoginTime()
- common.GenResp(c, code, "SUCCESS", model)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
- // @tags Customer
- // @Description 获取赛事订单
- // @Summary 获取赛事订单
- // @Produce json
- // @Param user_id query string true "用户ID"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"user_id":"","mobile_phone":"","user_name":"","avatar":"https://","gender":2,"birthday":"","area":"江苏省-南京市-鼓楼区","email":"","customer_level":0,"user_point":0,"user_money":0.00,"register_time":""}}}"
- // @Router /customer/order [get]
- func GetCompetitionOrder(c *gin.Context) {
- userCode := c.Query("user_id")
- if len(userCode) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model []models.Competition
- code = common.Success
- )
- model = services.QueryCompetitionOrder(userCode)
- //if len(model.DealSn) == 0 {
- // code = common.SystemHasNoUser
- //}
- if common.Success == code {
- // 修改上一次登录时间
- //_ = model.UpdateLoginTime()
- common.GenResp(c, code, "SUCCESS", model)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
- // @tags Customer
- // @Description 获取排位赛列表
- // @Summary 获取排位赛列表
- // @Produce json
- // @Param user_id query string true "用户ID"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"user_id":"","mobile_phone":"","user_name":"","avatar":"https://","gender":2,"birthday":"","area":"江苏省-南京市-鼓楼区","email":"","customer_level":0,"user_point":0,"user_money":0.00,"register_time":""}}}"
- // @Router /customer/qualifying [get]
- func GetQualifying(c *gin.Context) {
- userCode := c.Query("user_id")
- if len(userCode) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model models.QualifyingList
- code = common.Success
- )
- model = services.QueryQualifyingList(userCode)
- //if len(model.DealSn) == 0 {
- // code = common.SystemHasNoUser
- //}
- if common.Success == code {
- // 修改上一次登录时间
- //_ = model.UpdateLoginTime()
- common.GenResp(c, code, "SUCCESS", model)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
- // @tags Customer
- // @Description 上传base64图片
- // @Summary 上传base64图片
- // @Produce json
- // @Param body body models.UploadBaseReq true "修改用户资料请求内容"
- // @Success 200 {string} json "{"code":200,"message":"success","data":{}}"
- // @Router /customer/uploadBase64 [post]
- func UploadBase64(c *gin.Context) {
- var req models.UploadBaseReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- panic(err)
- }
- if len(req.Base64) == 0 {
- common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
- return
- }
- var (
- model models.UploadBaseErr
- code = common.Success
- )
- model.TaskId = req.TaskId
- model.UserId = req.UserId
- dir,_ := os.Getwd() //获取文件绝对路径
- //fmt.Println("当前路径:",dir)
- //fmt.Println(req.Base64)
- var urls = services.WriteFile(dir+"/images",req.Base64)
- var urls1 = services.WriteFile(dir+"/maps",req.MapBase)
- //if len(model.DealSn) == 0 {
- // code = common.SystemHasNoUser
- //}
- // 创建OSSClient实例。
- client, err := oss.New("oss-cn-hangzhou.aliyuncs.com", "LTAI4FySYnBk5ME5AvbcgGmx", "AsYT0SPtPXPe1YYAmHFi1Tfcq1Pww5")
- client1, err1 := oss.New("oss-cn-hangzhou.aliyuncs.com", "LTAI4FySYnBk5ME5AvbcgGmx", "AsYT0SPtPXPe1YYAmHFi1Tfcq1Pww5")
- if err != nil && err1 != nil {
- fmt.Println("Error:", err)
- os.Exit(-1)
- }
- // 获取存储空间。
- bucket, err := client.Bucket("lzyd-sport-img")
- bucket1, err1 := client1.Bucket("lzyd-sport-img")
- if err != nil && err1 != nil {
- fmt.Println("Error:", err)
- os.Exit(-1)
- }
- urlsName := strings.Split(urls,"images/")
- urlsName1 := strings.Split(urls1,"maps/")
- fmt.Println(urlsName[1])
- fmt.Println(urlsName1[1])
- // 上传本地文件。
- err = bucket.PutObjectFromFile(urlsName[1], urls)
- err1 = bucket1.PutObjectFromFile(urlsName1[1], urls1)
- if err != nil && err1 != nil {
- fmt.Println("Error:", err)
- os.Exit(-1)
- }else {
- err := os.Remove(urls)
- err1 := os.Remove(urls1)
- if err != nil && err1 != nil {
- // 删除失败
- } else {
- // 删除成功
- }
- }
- urls = "https://lzyd-sport-img.oss-cn-hangzhou.aliyuncs.com/" + urlsName[1]
- urls1 = "https://lzyd-sport-img.oss-cn-hangzhou.aliyuncs.com/" + urlsName1[1]
- model.MapUrl = urls
- model.MapBase = urls1
- if err := model.InsetMaps(common.DB,req.TaskId); err != nil {
- code = common.DbInsertErr
- }
- if common.Success == code {
- common.GenResp(c, code, "SUCCESS", model)
- } else {
- common.GenResp(c, code, "内部错误", nil)
- }
- }
|