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) } }