user.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. package user
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // QueryUserReferNumReq 获取用户邀请码请求参数
  11. type QueryUserReferNumReq struct {
  12. UserID int `form:"userID" binding:"required"`
  13. }
  14. // QueryUserReferNum 获取用户邀请码
  15. // @Summary 获取用户邀请码
  16. // @Produce json
  17. // @Param userID query int true "用户ID"
  18. // @Success 200 {object} app.Response
  19. // @Failure 500 {object} app.Response
  20. // @Router /User/QueryUserReferNum [get]
  21. // @Tags 用户信息
  22. func QueryUserReferNum(c *gin.Context) {
  23. appG := app.Gin{C: c}
  24. // 获取请求参数
  25. var req QueryUserReferNumReq
  26. if err := appG.C.ShouldBindQuery(&req); err != nil {
  27. logger.GetLogger().Errorf("QueryUserReferNum failed: %s", err.Error())
  28. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  29. return
  30. }
  31. var (
  32. userAccount *models.Useraccount
  33. err error
  34. )
  35. if userAccount, err = models.GetUserAccount(req.UserID); err != nil {
  36. // 查询失败
  37. logger.GetLogger().Errorf("QueryUserReferNum failed: %s", err.Error())
  38. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  39. return
  40. }
  41. // 查询成功
  42. logger.GetLogger().Debugln("QueryUserReferNum successed: %v", userAccount.Refernum)
  43. appG.Response(http.StatusOK, e.SUCCESS, userAccount.Refernum)
  44. }
  45. // QueryUserInfoReq 获取用户信息请求参数
  46. type QueryUserInfoReq struct {
  47. UserID int `form:"userID" binding:"required"`
  48. }
  49. // QueryUserInfo 获取用户信息
  50. // @Summary 获取用户信息
  51. // @Produce json
  52. // @Security ApiKeyAuth
  53. // @Param userID query int true "用户ID"
  54. // @Success 200 {object} models.Userinfo
  55. // @Failure 500 {object} app.Response
  56. // @Router /User/QueryUserInfo [get]
  57. // @Tags 用户信息
  58. func QueryUserInfo(c *gin.Context) {
  59. appG := app.Gin{C: c}
  60. // 获取请求参数
  61. var req QueryUserReferNumReq
  62. if err := appG.C.ShouldBindQuery(&req); err != nil {
  63. logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
  64. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  65. return
  66. }
  67. // 查询数据
  68. var (
  69. data *models.Userinfo
  70. err error
  71. )
  72. if data, err = models.GetUserInfo(req.UserID); err != nil {
  73. // 查询失败
  74. logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
  75. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  76. return
  77. }
  78. // 查询成功
  79. logger.GetLogger().Debugln("QueryUserInfo successed: %v", data)
  80. appG.Response(http.StatusOK, e.SUCCESS, data)
  81. }
  82. // GetUserAuthStatusReq 获取用户实名认证状态请求参数
  83. type GetUserAuthStatusReq struct {
  84. UserID int `form:"userID" binding:"required"` // 用户ID
  85. }
  86. // GetUserAuthStatus 获取用户实名认证状态
  87. // @Summary 获取用户实名认证状态
  88. // @Produce json
  89. // @Security ApiKeyAuth
  90. // @Param userID query int true "用户ID"
  91. // @Success 200 {object} app.Response
  92. // @Failure 500 {object} app.Response
  93. // @Router /User/GetUserAuthStatus [get]
  94. // @Tags 用户信息
  95. func GetUserAuthStatus(c *gin.Context) {
  96. appG := app.Gin{C: c}
  97. // 获取请求参数
  98. var req GetUserAuthStatusReq
  99. if err := appG.C.ShouldBindQuery(&req); err != nil {
  100. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  101. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  102. return
  103. }
  104. isAuth := false
  105. var (
  106. userAccount *models.Useraccount
  107. err error
  108. )
  109. if userAccount, err = models.GetUserAccount(req.UserID); err != nil {
  110. // 查询失败
  111. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  112. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  113. return
  114. }
  115. if userAccount != nil {
  116. if userAccount.Hasauth == 1 {
  117. isAuth = true
  118. }
  119. }
  120. // 查询成功
  121. logger.GetLogger().Debugln("GetUserAuthStatus successed: %v", isAuth)
  122. appG.Response(http.StatusOK, e.SUCCESS, isAuth)
  123. }
  124. // GetUserAccountReq 获取用户账号信息请求参数
  125. type GetUserAccountReq struct {
  126. UserID int `form:"userID" binding:"required"` // 用户ID
  127. }
  128. // GetUserAccount 获取用户账号信息
  129. // @Summary 获取用户账号信息
  130. // @Produce json
  131. // @Security ApiKeyAuth
  132. // @Param userID query int true "用户ID"
  133. // @Success 200 {object} models.Useraccount
  134. // @Failure 500 {object} app.Response
  135. // @Router /User/GetUserAccount [get]
  136. // @Tags 用户信息
  137. func GetUserAccount(c *gin.Context) {
  138. appG := app.Gin{C: c}
  139. // 获取请求参数
  140. var req GetUserAccountReq
  141. if err := appG.C.ShouldBindQuery(&req); err != nil {
  142. logger.GetLogger().Errorf("GetUserAccount failed: %s", err.Error())
  143. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  144. return
  145. }
  146. var (
  147. userAccount *models.Useraccount
  148. err error
  149. )
  150. if userAccount, err = models.GetUserAccount(req.UserID); err != nil {
  151. // 查询失败
  152. logger.GetLogger().Errorf("GetUserAccount failed: %s", err.Error())
  153. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  154. return
  155. }
  156. // 查询成功
  157. logger.GetLogger().Debugln("GetUserAccount successed: %v", userAccount)
  158. appG.Response(http.StatusOK, e.SUCCESS, userAccount)
  159. }
  160. // LoginQueryReq 账户登录后信息查询请求参数
  161. type LoginQueryReq struct {
  162. LoginID int `form:"loginID" binding:"required"`
  163. }
  164. // LoginQueryRsp 账户登录后信息查询返回模型
  165. type LoginQueryRsp struct {
  166. UserName string `json:"username"` // 用户姓名
  167. LoginAccount models.Loginaccount `json:"loginAccount"` // 登录账号
  168. UserAccount models.Useraccount `json:"userAccount"` // 用户账号
  169. UserInfo models.Userinfo `json:"userInfo"` // 用户信息
  170. Markets []models.Market `json:"markets"` // 市场
  171. Goodsgroups []models.Goodsgroup `json:"goodsgroups"` // 商品组
  172. ExternalExchanges []models.Externalexchange `json:"externalExchanges"` // 外部交易所
  173. SystemParams []models.Systemparam `json:"SystemParams"` // 系统参数
  174. }
  175. // LoginQuery 账户登录后信息查询
  176. // @Summary 账户登录后信息查询
  177. // @Produce json
  178. // @Security ApiKeyAuth
  179. // @Param loginID query int true "登录账号"
  180. // @Success 200 {object} LoginQueryRsp
  181. // @Failure 500 {object} app.Response
  182. // @Router /User/LoginQuery [get]
  183. // @Tags 用户信息
  184. func LoginQuery(c *gin.Context) {
  185. appG := app.Gin{C: c}
  186. // 获取请求参数
  187. var req LoginQueryReq
  188. if err := appG.C.ShouldBindQuery(&req); err != nil {
  189. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  190. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  191. return
  192. }
  193. var rsp LoginQueryRsp
  194. // 登录账号
  195. loginAccount, err := models.GetLoginAccount(req.LoginID)
  196. if err != nil {
  197. // 查询失败
  198. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  199. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  200. return
  201. }
  202. rsp.LoginAccount = *loginAccount
  203. // 用户账号
  204. userAccount, err := models.GetUserAccount(int(loginAccount.Userid))
  205. if err != nil {
  206. // 查询失败
  207. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  208. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  209. return
  210. }
  211. rsp.UserAccount = *userAccount
  212. // 用户信息
  213. userInfo, err := models.GetUserInfo(int(loginAccount.Userid))
  214. if err != nil {
  215. // 查询失败
  216. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  217. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  218. return
  219. }
  220. rsp.UserInfo = *userInfo
  221. // 有权限的市场
  222. markets, err := models.GetMarketsByLoginID(req.LoginID)
  223. if err != nil {
  224. // 查询失败
  225. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  226. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  227. return
  228. }
  229. rsp.Markets = markets
  230. // 商品组
  231. if len(rsp.Markets) > 0 {
  232. marketIDs := make([]int, 0)
  233. for _, v := range rsp.Markets {
  234. marketIDs = append(marketIDs, int(v.Marketid))
  235. }
  236. goodsgroups, err := models.GetGoodsgroupInMarketIDs(marketIDs)
  237. if err != nil {
  238. // 查询失败
  239. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  240. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  241. return
  242. }
  243. rsp.Goodsgroups = goodsgroups
  244. }
  245. // 外部交易所
  246. if len(rsp.Goodsgroups) > 0 {
  247. exchangeIDs := make([]int, 0)
  248. for _, v := range rsp.Goodsgroups {
  249. exchangeIDs = append(exchangeIDs, int(v.Exexchangeid))
  250. }
  251. exExchanges, err := models.GetExExchangeByIDs(exchangeIDs)
  252. if err != nil {
  253. // 查询失败
  254. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  255. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  256. return
  257. }
  258. rsp.ExternalExchanges = exExchanges
  259. }
  260. // 系统参数
  261. systemParams, err := models.GetSystemParams()
  262. if err != nil {
  263. // 查询失败
  264. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  265. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  266. return
  267. }
  268. rsp.SystemParams = systemParams
  269. // 用户姓名
  270. if len(rsp.LoginAccount.Logincode) > 0 {
  271. systemManager, _ := models.GetSysteMmanagerByLoginCode(rsp.LoginAccount.Logincode)
  272. if systemManager != nil {
  273. rsp.UserName = systemManager.Username
  274. }
  275. }
  276. // 查询成功
  277. logger.GetLogger().Debugln("LoginQuery successed: %v", rsp)
  278. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  279. }
  280. // QueryUserFavoriteGoodsesReq 获取用户商品收藏信息请求参数
  281. type QueryUserFavoriteGoodsesReq struct {
  282. UserID int `form:"userID" binding:"required"`
  283. }
  284. // QueryUserFavoriteGoodses 获取用户商品收藏信息
  285. // @Summary 获取用户商品收藏信息
  286. // @Produce json
  287. // @Security ApiKeyAuth
  288. // @Param userID query int true "用户ID"
  289. // @Success 200 {object} models.Userfavoritegoods
  290. // @Failure 500 {object} app.Response
  291. // @Router /User/QueryUserFavoriteGoodses [get]
  292. // @Tags 用户信息
  293. func QueryUserFavoriteGoodses(c *gin.Context) {
  294. appG := app.Gin{C: c}
  295. // 获取请求参数
  296. var req QueryUserFavoriteGoodsesReq
  297. if err := appG.C.ShouldBindQuery(&req); err != nil {
  298. logger.GetLogger().Errorf("QueryUserFavoriteGoodses failed: %s", err.Error())
  299. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  300. return
  301. }
  302. userFavoriteGoodses, err := models.GetUserFavoriteGoodses(req.UserID)
  303. if err != nil {
  304. // 查询失败
  305. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  306. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  307. return
  308. }
  309. // 查询成功
  310. logger.GetLogger().Debugln("QueryUserFavoriteGoodses successed: %v", userFavoriteGoodses)
  311. appG.Response(http.StatusOK, e.SUCCESS, userFavoriteGoodses)
  312. }
  313. // UpdateUserFavoriteGoodsReq 更新用户商品收藏信息请求参数
  314. type UpdateUserFavoriteGoodsReq struct {
  315. UserID int `form:"userID" binding:"required"`
  316. GoodsID int `form:"goodsID" binding:"required"`
  317. }
  318. // AddUserFavoriteGoods 添加用户商品收藏信息
  319. // @Summary 添加用户商品收藏信息
  320. // @Produce json
  321. // @Security ApiKeyAuth
  322. // @Param userID query int true "用户ID"
  323. // @Param goodsID query int true "商品ID"
  324. // @Success 200 {object} app.Response
  325. // @Failure 500 {object} app.Response
  326. // @Router /User/AddUserFavoriteGoods [post]
  327. // @Tags 用户信息
  328. func AddUserFavoriteGoods(c *gin.Context) {
  329. appG := app.Gin{C: c}
  330. // 获取请求参数
  331. var req UpdateUserFavoriteGoodsReq
  332. if err := appG.C.ShouldBind(&req); err != nil {
  333. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  334. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  335. return
  336. }
  337. if err := models.InsertUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  338. // 执行失败
  339. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  340. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  341. return
  342. }
  343. // 执行成功
  344. logger.GetLogger().Debugln("AddUserFavoriteGoods successed: %v", "ok")
  345. appG.Response(http.StatusOK, e.SUCCESS, "")
  346. }
  347. // RemoveUserFavoriteGoods 移除用户商品收藏信息
  348. // @Summary 移除用户商品收藏信息
  349. // @Produce json
  350. // @Security ApiKeyAuth
  351. // @Param userID query int true "用户ID"
  352. // @Param goodsID query int true "商品ID"
  353. // @Success 200 {object} app.Response
  354. // @Failure 500 {object} app.Response
  355. // @Router /User/RemoveUserFavoriteGoods [post]
  356. // @Tags 用户信息
  357. func RemoveUserFavoriteGoods(c *gin.Context) {
  358. appG := app.Gin{C: c}
  359. // 获取请求参数
  360. var req UpdateUserFavoriteGoodsReq
  361. if err := appG.C.ShouldBind(&req); err != nil {
  362. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  363. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  364. return
  365. }
  366. if err := models.DelUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  367. // 执行失败
  368. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  369. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  370. return
  371. }
  372. // 执行成功
  373. logger.GetLogger().Debugln("RemoveUserFavoriteGoods successed: %v", "ok")
  374. appG.Response(http.StatusOK, e.SUCCESS, "")
  375. }
  376. // QueryMessageBoardReq 获取用户留言板信息请求参数
  377. type QueryMessageBoardReq struct {
  378. UserID int `form:"userID" binding:"required"`
  379. }
  380. // QueryMessageBoard 获取用户留言板信息
  381. // @Summary 获取用户留言板信息
  382. // @Produce json
  383. // @Security ApiKeyAuth
  384. // @Param userID query int true "用户ID"
  385. // @Success 200 {object} models.Messageboard
  386. // @Failure 500 {object} app.Response
  387. // @Router /User/QueryMessageBoard [get]
  388. // @Tags 用户信息
  389. func QueryMessageBoard(c *gin.Context) {
  390. appG := app.Gin{C: c}
  391. // 获取请求参数
  392. var req QueryMessageBoardReq
  393. if err := appG.C.ShouldBindQuery(&req); err != nil {
  394. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  395. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  396. return
  397. }
  398. messageBoards, err := models.GetMessageBoard(req.UserID)
  399. if err != nil {
  400. // 查询失败
  401. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  402. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  403. return
  404. }
  405. // 查询成功
  406. logger.GetLogger().Debugln("QueryMessageBoard successed: %v", messageBoards)
  407. appG.Response(http.StatusOK, e.SUCCESS, messageBoards)
  408. }
  409. // AddMessageBoardReq 添加用户留言板信息请求参数
  410. type AddMessageBoardReq struct {
  411. UserID int `form:"userID" binding:"required"`
  412. Message string `form:"message" binding:"required"`
  413. ContactNum string `form:"contactNum" binding:"required"`
  414. }
  415. // AddMessageBoard 添加用户留言板信息
  416. // @Summary 添加用户留言板信息
  417. // @Produce json
  418. // @Security ApiKeyAuth
  419. // @Param userID query int true "用户ID"
  420. // @Param message query string true "留言信息"
  421. // @Param contactNum query string true "联系电话"
  422. // @Success 200 {object} app.Response
  423. // @Failure 500 {object} app.Response
  424. // @Router /User/AddMessageBoard [post]
  425. // @Tags 用户信息
  426. func AddMessageBoard(c *gin.Context) {
  427. appG := app.Gin{C: c}
  428. // 获取请求参数
  429. var req AddMessageBoardReq
  430. if err := appG.C.ShouldBind(&req); err != nil {
  431. logger.GetLogger().Errorf("AddMessageBoard failed: %s", err.Error())
  432. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  433. return
  434. }
  435. if errCode := models.InsertMessageBoard(req.UserID, req.Message, req.ContactNum); errCode != 0 {
  436. // 执行失败
  437. logger.GetLogger().Errorf("AddMessageBoard failed: %s", e.GetMsg(errCode))
  438. appG.Response(http.StatusBadRequest, errCode, nil)
  439. return
  440. }
  441. // 执行成功
  442. logger.GetLogger().Debugln("AddMessageBoard successed: %v", "ok")
  443. appG.Response(http.StatusOK, e.SUCCESS, "")
  444. }
  445. // UpdateUserAccountStatusReq 更新用户状态请求参数
  446. type UpdateUserAccountStatusReq struct {
  447. UserID int `form:"userID" binding:"required"`
  448. AccountStatus int `form:"accountStatus" binding:"required"`
  449. }
  450. // UpdateUserAccountStatus 更新用户状态
  451. // @Summary 更新用户状态
  452. // @Produce json
  453. // @Security ApiKeyAuth
  454. // @Param userID query int true "用户ID"
  455. // @Param accountStatus query int true "账户状态 - 4:正常 6:注销(停用)"
  456. // @Success 200 {object} app.Response
  457. // @Failure 500 {object} app.Response
  458. // @Router /User/UpdateUserAccountStatus [post]
  459. // @Tags 用户信息
  460. func UpdateUserAccountStatus(c *gin.Context) {
  461. appG := app.Gin{C: c}
  462. // 获取请求参数
  463. var req UpdateUserAccountStatusReq
  464. if err := appG.C.ShouldBind(&req); err != nil {
  465. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  466. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  467. return
  468. }
  469. if err := models.UpdateUserAccountStatus(req.UserID, req.AccountStatus); err != nil {
  470. // 执行失败
  471. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  472. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  473. return
  474. }
  475. // 执行成功
  476. logger.GetLogger().Debugln("UpdateUserAccountStatus successed: %v", "ok")
  477. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  478. }