user.go 19 KB

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