user.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. for _, v := range rsp.Goodsgroups {
  303. exchangeIDs = append(exchangeIDs, int(v.Exexchangeid))
  304. }
  305. exExchanges, err := models.GetExExchangeByIDs(exchangeIDs)
  306. if err != nil {
  307. // 查询失败
  308. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  309. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  310. return
  311. }
  312. rsp.ExternalExchanges = exExchanges
  313. }
  314. // 系统参数
  315. systemParams, err := models.GetSystemParams()
  316. if err != nil {
  317. // 查询失败
  318. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  319. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  320. return
  321. }
  322. rsp.SystemParams = systemParams
  323. // 用户姓名
  324. if len(rsp.LoginAccount.Logincode) > 0 {
  325. systemManager, _ := models.GetSysteMmanagerByLoginCode(rsp.LoginAccount.Logincode)
  326. if systemManager != nil {
  327. rsp.UserName = systemManager.Username
  328. }
  329. }
  330. // 查询成功
  331. logger.GetLogger().Debugln("LoginQuery successed: %v", rsp)
  332. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  333. }
  334. // QueryUserFavoriteGoodsesReq 获取用户商品收藏信息请求参数
  335. type QueryUserFavoriteGoodsesReq struct {
  336. UserID int `form:"userID" binding:"required"`
  337. }
  338. // QueryUserFavoriteGoodses 获取用户商品收藏信息
  339. // @Summary 获取用户商品收藏信息
  340. // @Produce json
  341. // @Security ApiKeyAuth
  342. // @Param userID query int true "用户ID"
  343. // @Success 200 {object} models.Userfavoritegoods
  344. // @Failure 500 {object} app.Response
  345. // @Router /User/QueryUserFavoriteGoodses [get]
  346. // @Tags 用户信息
  347. func QueryUserFavoriteGoodses(c *gin.Context) {
  348. appG := app.Gin{C: c}
  349. // 获取请求参数
  350. var req QueryUserFavoriteGoodsesReq
  351. if err := appG.C.ShouldBindQuery(&req); err != nil {
  352. logger.GetLogger().Errorf("QueryUserFavoriteGoodses failed: %s", err.Error())
  353. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  354. return
  355. }
  356. userFavoriteGoodses, err := models.GetUserFavoriteGoodses(req.UserID)
  357. if err != nil {
  358. // 查询失败
  359. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  360. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  361. return
  362. }
  363. // 查询成功
  364. logger.GetLogger().Debugln("QueryUserFavoriteGoodses successed: %v", userFavoriteGoodses)
  365. appG.Response(http.StatusOK, e.SUCCESS, userFavoriteGoodses)
  366. }
  367. // UpdateUserFavoriteGoodsReq 更新用户商品收藏信息请求参数
  368. type UpdateUserFavoriteGoodsReq struct {
  369. UserID int `form:"userID" binding:"required"`
  370. GoodsID int `form:"goodsID" binding:"required"`
  371. }
  372. // AddUserFavoriteGoods 添加用户商品收藏信息
  373. // @Summary 添加用户商品收藏信息
  374. // @Produce json
  375. // @Security ApiKeyAuth
  376. // @Param userID query int true "用户ID"
  377. // @Param goodsID query int true "商品ID"
  378. // @Success 200 {object} app.Response
  379. // @Failure 500 {object} app.Response
  380. // @Router /User/AddUserFavoriteGoods [post]
  381. // @Tags 用户信息
  382. func AddUserFavoriteGoods(c *gin.Context) {
  383. appG := app.Gin{C: c}
  384. // 获取请求参数
  385. var req UpdateUserFavoriteGoodsReq
  386. if err := appG.C.ShouldBind(&req); err != nil {
  387. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  388. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  389. return
  390. }
  391. if err := models.InsertUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  392. // 执行失败
  393. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  394. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  395. return
  396. }
  397. // 执行成功
  398. logger.GetLogger().Debugln("AddUserFavoriteGoods successed: %v", "ok")
  399. appG.Response(http.StatusOK, e.SUCCESS, "")
  400. }
  401. // RemoveUserFavoriteGoods 移除用户商品收藏信息
  402. // @Summary 移除用户商品收藏信息
  403. // @Produce json
  404. // @Security ApiKeyAuth
  405. // @Param userID query int true "用户ID"
  406. // @Param goodsID query int true "商品ID"
  407. // @Success 200 {object} app.Response
  408. // @Failure 500 {object} app.Response
  409. // @Router /User/RemoveUserFavoriteGoods [post]
  410. // @Tags 用户信息
  411. func RemoveUserFavoriteGoods(c *gin.Context) {
  412. appG := app.Gin{C: c}
  413. // 获取请求参数
  414. var req UpdateUserFavoriteGoodsReq
  415. if err := appG.C.ShouldBind(&req); err != nil {
  416. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  417. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  418. return
  419. }
  420. if err := models.DelUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  421. // 执行失败
  422. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  423. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  424. return
  425. }
  426. // 执行成功
  427. logger.GetLogger().Debugln("RemoveUserFavoriteGoods successed: %v", "ok")
  428. appG.Response(http.StatusOK, e.SUCCESS, "")
  429. }
  430. // QueryMessageBoardReq 获取用户留言板信息请求参数
  431. type QueryMessageBoardReq struct {
  432. UserID int `form:"userID" binding:"required"`
  433. }
  434. // QueryMessageBoard 获取用户留言板信息
  435. // @Summary 获取用户留言板信息
  436. // @Produce json
  437. // @Security ApiKeyAuth
  438. // @Param userID query int true "用户ID"
  439. // @Success 200 {object} models.Messageboard
  440. // @Failure 500 {object} app.Response
  441. // @Router /User/QueryMessageBoard [get]
  442. // @Tags 用户信息
  443. func QueryMessageBoard(c *gin.Context) {
  444. appG := app.Gin{C: c}
  445. // 获取请求参数
  446. var req QueryMessageBoardReq
  447. if err := appG.C.ShouldBindQuery(&req); err != nil {
  448. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  449. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  450. return
  451. }
  452. messageBoards, err := models.GetMessageBoard(req.UserID)
  453. if err != nil {
  454. // 查询失败
  455. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  456. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  457. return
  458. }
  459. // 查询成功
  460. logger.GetLogger().Debugln("QueryMessageBoard successed: %v", messageBoards)
  461. appG.Response(http.StatusOK, e.SUCCESS, messageBoards)
  462. }
  463. // AddMessageBoardReq 添加用户留言板信息请求参数
  464. type AddMessageBoardReq struct {
  465. UserID int `form:"userID" binding:"required"`
  466. Message string `form:"message" binding:"required"`
  467. ContactNum string `form:"contactNum" binding:"required"`
  468. }
  469. // AddMessageBoard 添加用户留言板信息
  470. // @Summary 添加用户留言板信息
  471. // @Produce json
  472. // @Security ApiKeyAuth
  473. // @Param userID query int true "用户ID"
  474. // @Param message query string true "留言信息"
  475. // @Param contactNum query string true "联系电话"
  476. // @Success 200 {object} app.Response
  477. // @Failure 500 {object} app.Response
  478. // @Router /User/AddMessageBoard [post]
  479. // @Tags 用户信息
  480. func AddMessageBoard(c *gin.Context) {
  481. appG := app.Gin{C: c}
  482. // 获取请求参数
  483. var req AddMessageBoardReq
  484. if err := appG.C.ShouldBind(&req); err != nil {
  485. logger.GetLogger().Errorf("AddMessageBoard failed: %s", err.Error())
  486. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  487. return
  488. }
  489. if errCode := models.InsertMessageBoard(req.UserID, req.Message, req.ContactNum); errCode != 0 {
  490. // 执行失败
  491. logger.GetLogger().Errorf("AddMessageBoard failed: %s", e.GetMsg(errCode))
  492. appG.Response(http.StatusBadRequest, errCode, nil)
  493. return
  494. }
  495. // 执行成功
  496. logger.GetLogger().Debugln("AddMessageBoard successed: %v", "ok")
  497. appG.Response(http.StatusOK, e.SUCCESS, "")
  498. }
  499. // UpdateUserAccountStatusReq 更新用户状态请求参数
  500. type UpdateUserAccountStatusReq struct {
  501. UserID int `form:"userID" binding:"required"`
  502. AccountStatus int `form:"accountStatus" binding:"required"`
  503. }
  504. // UpdateUserAccountStatus 更新用户状态
  505. // @Summary 更新用户状态
  506. // @Produce json
  507. // @Security ApiKeyAuth
  508. // @Param userID query int true "用户ID"
  509. // @Param accountStatus query int true "账户状态 - 4:正常 6:注销(停用)"
  510. // @Success 200 {object} app.Response
  511. // @Failure 500 {object} app.Response
  512. // @Router /User/UpdateUserAccountStatus [post]
  513. // @Tags 用户信息
  514. func UpdateUserAccountStatus(c *gin.Context) {
  515. appG := app.Gin{C: c}
  516. // 获取请求参数
  517. var req UpdateUserAccountStatusReq
  518. if err := appG.C.ShouldBind(&req); err != nil {
  519. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  520. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  521. return
  522. }
  523. if err := models.UpdateUserAccountStatus(req.UserID, req.AccountStatus); err != nil {
  524. // 执行失败
  525. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  526. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  527. return
  528. }
  529. // 执行成功
  530. logger.GetLogger().Debugln("UpdateUserAccountStatus successed: %v", "ok")
  531. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  532. }