user.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  5. "github.com/gin-gonic/gin"
  6. "lzyd-user-api/common"
  7. "lzyd-user-api/models"
  8. "lzyd-user-api/services"
  9. "os"
  10. "strings"
  11. )
  12. // @tags Customer
  13. // @Description 获取用户详细信息
  14. // @Summary 获取用户详细信息
  15. // @Produce json
  16. // @Param user_id query string true "用户ID"
  17. // @Param other_id query string false "另一个用户id"
  18. // @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":""}}}"
  19. // @Router /customer/getInfo [get]
  20. func GetCustomerInfo(c *gin.Context) {
  21. userCode := c.Query("user_id")
  22. if len(userCode) == 0 {
  23. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  24. return
  25. }
  26. var (
  27. model models.UserInfo
  28. code = common.Success
  29. )
  30. otherCode := c.Query("other_id")
  31. model = services.QueryUserByCode(userCode)
  32. if model.Id == 0 {
  33. code = common.SystemHasNoUser
  34. }
  35. if len(otherCode) != 0 {
  36. relation := services.UserRelation(userCode,otherCode)
  37. fmt.Println(relation)
  38. if len(relation) > 0 {
  39. model.AttentionUserId = relation
  40. }
  41. }
  42. if common.Success == code {
  43. // 修改上一次登录时间
  44. //_ = model.UpdateLoginTime()
  45. common.GenResp(c, code, "SUCCESS", model)
  46. } else {
  47. common.GenResp(c, code, "内部错误", nil)
  48. }
  49. }
  50. // @tags Customer
  51. // @Description 修改用户资料
  52. // @Summary 修改用户资料
  53. // @Produce json
  54. // @Param body body models.UpdateProfileReq true "修改用户资料请求内容"
  55. // @Success 200 {string} json "{"code":200,"message":"success","data":{}}"
  56. // @Router /customer/updateProfile [post]
  57. func UpdateProfile(c *gin.Context) {
  58. var req models.UpdateProfileReq
  59. err := c.ShouldBindJSON(&req)
  60. if err != nil {
  61. panic(err)
  62. }
  63. if len(req.UserId) == 0 {
  64. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  65. return
  66. }
  67. var (
  68. model models.UserInfo
  69. code = common.Success
  70. )
  71. model = services.QueryUserByCode(req.UserId)
  72. if model.Id == 0 {
  73. code = common.SystemHasNoUser
  74. common.GenResp(c, code, "系统不存在该用户", nil)
  75. return
  76. }
  77. fmt.Println(req)
  78. if len(req.UserName) > 0 {
  79. model.UserName = req.UserName
  80. }
  81. if len(req.Birthday) > 0 {
  82. model.Birthday = req.Birthday
  83. }
  84. if len(req.Area) > 0 {
  85. model.Area = req.Area
  86. }
  87. if req.Gender > 0 {
  88. model.Gender = req.Gender
  89. }
  90. if req.Height > 0 {
  91. model.Height = req.Height
  92. }
  93. if req.Weight > 0 {
  94. model.Weight = req.Weight
  95. }
  96. if len(req.UserAvatar) > 0 {
  97. model.UserAvatar = req.UserAvatar
  98. }
  99. if err := model.UpdateProfile(common.DB); err != nil {
  100. code = common.DbUpdateErr
  101. }
  102. if common.Success == code {
  103. if len(model.UserAvatar) == 0 {
  104. model.UserAvatar = common.SystemInfo.Avatar
  105. }
  106. // 修改成功后的处理
  107. var ret = models.UserResp{
  108. Id: model.Id,
  109. UserId: model.UserId,
  110. UserName: model.UserName,
  111. RealName: model.RealName,
  112. UserAvatar: model.UserAvatar,
  113. Gender: model.Gender,
  114. Birthday: model.Birthday,
  115. Area: model.Area,
  116. Weight: model.Weight,
  117. Height: model.Height,
  118. AppId: model.AppId,
  119. }
  120. common.GenResp(c, code, "SUCCESS", ret)
  121. } else {
  122. common.GenResp(c, code, "内部错误", nil)
  123. }
  124. }
  125. // @tags Customer
  126. // @Description 获取用户黑白名单列表
  127. // @Summary 获取用户黑白名单列表
  128. // @Produce json
  129. // @Param body body models.GetBlackListReq true "获取黑白名单列表"
  130. // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"user_id":"","username":"","user_avatar":"https://"}}}"
  131. // @Router /customer/getBlacklist [post]
  132. func GetBlacklist(c *gin.Context) {
  133. var req models.GetBlackListReq
  134. err := c.ShouldBindJSON(&req)
  135. if err != nil {
  136. panic(err)
  137. }
  138. if len(req.UserId) == 0 {
  139. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  140. return
  141. }
  142. var (
  143. model []models.BlackListReq
  144. code = common.Success
  145. )
  146. model = services.QueryBlackByCode(req.UserId,req.Type)
  147. if common.Success == code {
  148. // 修改上一次登录时间
  149. //_ = model.UpdateLoginTime()
  150. common.GenResp(c, code, "SUCCESS", model)
  151. } else {
  152. common.GenResp(c, code, "内部错误", nil)
  153. }
  154. }
  155. // @tags Customer
  156. // @Description 获取赛事订单
  157. // @Summary 获取赛事订单
  158. // @Produce json
  159. // @Param user_id query string true "用户ID"
  160. // @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":""}}}"
  161. // @Router /customer/order [get]
  162. func GetCompetitionOrder(c *gin.Context) {
  163. userCode := c.Query("user_id")
  164. if len(userCode) == 0 {
  165. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  166. return
  167. }
  168. var (
  169. model []models.Competition
  170. code = common.Success
  171. )
  172. model = services.QueryCompetitionOrder(userCode)
  173. //if len(model.DealSn) == 0 {
  174. // code = common.SystemHasNoUser
  175. //}
  176. if common.Success == code {
  177. // 修改上一次登录时间
  178. //_ = model.UpdateLoginTime()
  179. common.GenResp(c, code, "SUCCESS", model)
  180. } else {
  181. common.GenResp(c, code, "内部错误", nil)
  182. }
  183. }
  184. // @tags Customer
  185. // @Description 获取排位赛列表
  186. // @Summary 获取排位赛列表
  187. // @Produce json
  188. // @Param user_id query string true "用户ID"
  189. // @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":""}}}"
  190. // @Router /customer/qualifying [get]
  191. func GetQualifying(c *gin.Context) {
  192. userCode := c.Query("user_id")
  193. if len(userCode) == 0 {
  194. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  195. return
  196. }
  197. var (
  198. model models.QualifyingList
  199. code = common.Success
  200. )
  201. model = services.QueryQualifyingList(userCode)
  202. //if len(model.DealSn) == 0 {
  203. // code = common.SystemHasNoUser
  204. //}
  205. if common.Success == code {
  206. // 修改上一次登录时间
  207. //_ = model.UpdateLoginTime()
  208. common.GenResp(c, code, "SUCCESS", model)
  209. } else {
  210. common.GenResp(c, code, "内部错误", nil)
  211. }
  212. }
  213. // @tags Customer
  214. // @Description 上传base64图片
  215. // @Summary 上传base64图片
  216. // @Produce json
  217. // @Param body body models.UploadBaseReq true "修改用户资料请求内容"
  218. // @Success 200 {string} json "{"code":200,"message":"success","data":{}}"
  219. // @Router /customer/uploadBase64 [post]
  220. func UploadBase64(c *gin.Context) {
  221. var req models.UploadBaseReq
  222. err := c.ShouldBindJSON(&req)
  223. if err != nil {
  224. panic(err)
  225. }
  226. if len(req.Base64) == 0 {
  227. common.GenResp(c, common.InvalidParametes, "无效的参数", nil)
  228. return
  229. }
  230. var (
  231. model models.UploadBaseErr
  232. code = common.Success
  233. )
  234. model.TaskId = req.TaskId
  235. model.UserId = req.UserId
  236. dir,_ := os.Getwd() //获取文件绝对路径
  237. //fmt.Println("当前路径:",dir)
  238. //fmt.Println(req.Base64)
  239. var urls = services.WriteFile(dir+"/images",req.Base64)
  240. var urls1 = services.WriteFile(dir+"/maps",req.MapBase)
  241. //if len(model.DealSn) == 0 {
  242. // code = common.SystemHasNoUser
  243. //}
  244. // 创建OSSClient实例。
  245. client, err := oss.New("oss-cn-hangzhou.aliyuncs.com", "LTAI4FySYnBk5ME5AvbcgGmx", "AsYT0SPtPXPe1YYAmHFi1Tfcq1Pww5")
  246. client1, err1 := oss.New("oss-cn-hangzhou.aliyuncs.com", "LTAI4FySYnBk5ME5AvbcgGmx", "AsYT0SPtPXPe1YYAmHFi1Tfcq1Pww5")
  247. if err != nil && err1 != nil {
  248. fmt.Println("Error:", err)
  249. os.Exit(-1)
  250. }
  251. // 获取存储空间。
  252. bucket, err := client.Bucket("lzyd-sport-img")
  253. bucket1, err1 := client1.Bucket("lzyd-sport-img")
  254. if err != nil && err1 != nil {
  255. fmt.Println("Error:", err)
  256. os.Exit(-1)
  257. }
  258. urlsName := strings.Split(urls,"images/")
  259. urlsName1 := strings.Split(urls1,"maps/")
  260. fmt.Println(urlsName[1])
  261. fmt.Println(urlsName1[1])
  262. // 上传本地文件。
  263. err = bucket.PutObjectFromFile(urlsName[1], urls)
  264. err1 = bucket1.PutObjectFromFile(urlsName1[1], urls1)
  265. if err != nil && err1 != nil {
  266. fmt.Println("Error:", err)
  267. os.Exit(-1)
  268. }else {
  269. err := os.Remove(urls)
  270. err1 := os.Remove(urls1)
  271. if err != nil && err1 != nil {
  272. // 删除失败
  273. } else {
  274. // 删除成功
  275. }
  276. }
  277. urls = "https://lzyd-sport-img.oss-cn-hangzhou.aliyuncs.com/" + urlsName[1]
  278. urls1 = "https://lzyd-sport-img.oss-cn-hangzhou.aliyuncs.com/" + urlsName1[1]
  279. model.MapUrl = urls
  280. model.MapBase = urls1
  281. if err := model.InsetMaps(common.DB,req.TaskId); err != nil {
  282. code = common.DbInsertErr
  283. }
  284. if common.Success == code {
  285. common.GenResp(c, code, "SUCCESS", model)
  286. } else {
  287. common.GenResp(c, code, "内部错误", nil)
  288. }
  289. }