user.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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. ExchangeRateConfigs []models.Exchangerateconfig `json:"exchangeRateConfigs"` // 汇率信息
  217. }
  218. // LoginQuery 账户登录后信息查询
  219. // @Summary 账户登录后信息查询
  220. // @Produce json
  221. // @Security ApiKeyAuth
  222. // @Param loginID query int true "登录账号"
  223. // @Success 200 {object} LoginQueryRsp
  224. // @Failure 500 {object} app.Response
  225. // @Router /User/LoginQuery [get]
  226. // @Tags 用户信息
  227. func LoginQuery(c *gin.Context) {
  228. appG := app.Gin{C: c}
  229. // 获取请求参数
  230. var req LoginQueryReq
  231. if err := appG.C.ShouldBindQuery(&req); err != nil {
  232. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  233. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  234. return
  235. }
  236. var rsp LoginQueryRsp
  237. // 登录账号
  238. loginAccount, err := models.GetLoginAccount(req.LoginID)
  239. if err != nil {
  240. // 查询失败
  241. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  242. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  243. return
  244. }
  245. rsp.LoginAccount = *loginAccount
  246. // 用户账号
  247. userAccount, err := models.GetUserAccount(int(loginAccount.Userid))
  248. if err != nil {
  249. // 查询失败
  250. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  251. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  252. return
  253. }
  254. rsp.UserAccount = *userAccount
  255. // 用户信息
  256. userInfo, err := models.GetUserInfo(int(loginAccount.Userid))
  257. if err != nil {
  258. // 查询失败
  259. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  260. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  261. return
  262. }
  263. rsp.UserInfo = *userInfo
  264. // 角色信息
  265. var areaRole models.Arearole
  266. areaRoles, err := areaRole.GetAreaRolesByUserID(int(loginAccount.Userid))
  267. if err != nil {
  268. // 查询失败
  269. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  270. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  271. return
  272. }
  273. rsp.AreaRoles = areaRoles
  274. // 有权限的市场
  275. markets, err := models.GetMarketsByLoginID(req.LoginID)
  276. if err != nil {
  277. // 查询失败
  278. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  279. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  280. return
  281. }
  282. rsp.Markets = markets
  283. // 商品组
  284. rsp.Goodsgroups = make([]models.Goodsgroup, 0)
  285. if len(rsp.Markets) > 0 {
  286. marketIDs := make([]int, 0)
  287. for _, v := range rsp.Markets {
  288. marketIDs = append(marketIDs, int(v.MARKETID))
  289. }
  290. goodsgroups, err := models.GetGoodsgroupInMarketIDs(marketIDs)
  291. if err != nil {
  292. // 查询失败
  293. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  294. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  295. return
  296. }
  297. rsp.Goodsgroups = goodsgroups
  298. }
  299. // 外部交易所
  300. rsp.ExternalExchanges = make([]models.Externalexchange, 0)
  301. if len(rsp.Goodsgroups) > 0 {
  302. exchangeIDs := make([]int, 0)
  303. // 过滤掉没有关联商品的交易所
  304. id := models.GetAvalidExchangeId(rsp.UserAccount.Rootuserid)
  305. for _, v := range rsp.Goodsgroups {
  306. for i := range id {
  307. if id[i] == v.Exexchangeid {
  308. exchangeIDs = append(exchangeIDs, int(v.Exexchangeid))
  309. }
  310. }
  311. }
  312. if len(exchangeIDs) > 0 {
  313. exExchanges, err := models.GetExExchangeByIDs(exchangeIDs)
  314. if err != nil {
  315. // 查询失败
  316. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  317. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  318. return
  319. }
  320. rsp.ExternalExchanges = exExchanges
  321. }
  322. }
  323. // 系统参数
  324. systemParams, err := models.GetSystemParams()
  325. if err != nil {
  326. // 查询失败
  327. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  328. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  329. return
  330. }
  331. rsp.SystemParams = systemParams
  332. // 用户姓名
  333. if len(rsp.LoginAccount.Logincode) > 0 {
  334. systemManager, _ := models.GetSysteMmanagerByLoginCode(rsp.LoginAccount.Logincode)
  335. if systemManager != nil {
  336. rsp.UserName = systemManager.Username
  337. }
  338. }
  339. var r models.Exchangerateconfig
  340. if rsp.ExchangeRateConfigs, err = r.GetAll(); err != nil {
  341. // 查询失败
  342. logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
  343. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  344. return
  345. }
  346. // 查询成功
  347. logger.GetLogger().Debugln("LoginQuery successed")
  348. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  349. }
  350. // QueryUserFavoriteGoodsesReq 获取用户商品收藏信息请求参数
  351. type QueryUserFavoriteGoodsesReq struct {
  352. UserID int `form:"userID" binding:"required"`
  353. }
  354. // QueryUserFavoriteGoodses 获取用户商品收藏信息
  355. // @Summary 获取用户商品收藏信息
  356. // @Produce json
  357. // @Security ApiKeyAuth
  358. // @Param userID query int true "用户ID"
  359. // @Success 200 {object} models.Userfavoritegoods
  360. // @Failure 500 {object} app.Response
  361. // @Router /User/QueryUserFavoriteGoodses [get]
  362. // @Tags 用户信息
  363. func QueryUserFavoriteGoodses(c *gin.Context) {
  364. appG := app.Gin{C: c}
  365. // 获取请求参数
  366. var req QueryUserFavoriteGoodsesReq
  367. if err := appG.C.ShouldBindQuery(&req); err != nil {
  368. logger.GetLogger().Errorf("QueryUserFavoriteGoodses failed: %s", err.Error())
  369. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  370. return
  371. }
  372. userFavoriteGoodses, err := models.GetUserFavoriteGoodses(req.UserID)
  373. if err != nil {
  374. // 查询失败
  375. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  376. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  377. return
  378. }
  379. // 查询成功
  380. logger.GetLogger().Debugln("QueryUserFavoriteGoodses successed: %v", userFavoriteGoodses)
  381. appG.Response(http.StatusOK, e.SUCCESS, userFavoriteGoodses)
  382. }
  383. // UpdateUserFavoriteGoodsReq 更新用户商品收藏信息请求参数
  384. type UpdateUserFavoriteGoodsReq struct {
  385. UserID int `form:"userID" binding:"required"`
  386. GoodsID int `form:"goodsID" binding:"required"`
  387. }
  388. // AddUserFavoriteGoods 添加用户商品收藏信息
  389. // @Summary 添加用户商品收藏信息
  390. // @Produce json
  391. // @Security ApiKeyAuth
  392. // @Param userID query int true "用户ID"
  393. // @Param goodsID query int true "商品ID"
  394. // @Success 200 {object} app.Response
  395. // @Failure 500 {object} app.Response
  396. // @Router /User/AddUserFavoriteGoods [post]
  397. // @Tags 用户信息
  398. func AddUserFavoriteGoods(c *gin.Context) {
  399. appG := app.Gin{C: c}
  400. // 获取请求参数
  401. var req UpdateUserFavoriteGoodsReq
  402. if err := appG.C.ShouldBind(&req); err != nil {
  403. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  404. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  405. return
  406. }
  407. if err := models.InsertUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  408. // 执行失败
  409. logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
  410. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  411. return
  412. }
  413. // 执行成功
  414. logger.GetLogger().Debugln("AddUserFavoriteGoods successed: %v", "ok")
  415. appG.Response(http.StatusOK, e.SUCCESS, "")
  416. }
  417. // RemoveUserFavoriteGoods 移除用户商品收藏信息
  418. // @Summary 移除用户商品收藏信息
  419. // @Produce json
  420. // @Security ApiKeyAuth
  421. // @Param userID query int true "用户ID"
  422. // @Param goodsID query int true "商品ID"
  423. // @Success 200 {object} app.Response
  424. // @Failure 500 {object} app.Response
  425. // @Router /User/RemoveUserFavoriteGoods [post]
  426. // @Tags 用户信息
  427. func RemoveUserFavoriteGoods(c *gin.Context) {
  428. appG := app.Gin{C: c}
  429. // 获取请求参数
  430. var req UpdateUserFavoriteGoodsReq
  431. if err := appG.C.ShouldBind(&req); err != nil {
  432. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  433. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  434. return
  435. }
  436. if err := models.DelUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
  437. // 执行失败
  438. logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
  439. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  440. return
  441. }
  442. // 执行成功
  443. logger.GetLogger().Debugln("RemoveUserFavoriteGoods successed: %v", "ok")
  444. appG.Response(http.StatusOK, e.SUCCESS, "")
  445. }
  446. // QueryMessageBoardReq 获取用户留言板信息请求参数
  447. type QueryMessageBoardReq struct {
  448. UserID int `form:"userID" binding:"required"`
  449. }
  450. // QueryMessageBoard 获取用户留言板信息
  451. // @Summary 获取用户留言板信息
  452. // @Produce json
  453. // @Security ApiKeyAuth
  454. // @Param userID query int true "用户ID"
  455. // @Success 200 {object} models.Messageboard
  456. // @Failure 500 {object} app.Response
  457. // @Router /User/QueryMessageBoard [get]
  458. // @Tags 用户信息
  459. func QueryMessageBoard(c *gin.Context) {
  460. appG := app.Gin{C: c}
  461. // 获取请求参数
  462. var req QueryMessageBoardReq
  463. if err := appG.C.ShouldBindQuery(&req); err != nil {
  464. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  465. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  466. return
  467. }
  468. messageBoards, err := models.GetMessageBoard(req.UserID)
  469. if err != nil {
  470. // 查询失败
  471. logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
  472. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  473. return
  474. }
  475. // 查询成功
  476. logger.GetLogger().Debugln("QueryMessageBoard successed: %v", messageBoards)
  477. appG.Response(http.StatusOK, e.SUCCESS, messageBoards)
  478. }
  479. // AddMessageBoardReq 添加用户留言板信息请求参数
  480. type AddMessageBoardReq struct {
  481. UserID int `form:"userID" binding:"required"`
  482. Message string `form:"message" binding:"required"`
  483. ContactNum string `form:"contactNum" binding:"required"`
  484. }
  485. // AddMessageBoard 添加用户留言板信息
  486. // @Summary 添加用户留言板信息
  487. // @Produce json
  488. // @Security ApiKeyAuth
  489. // @Param userID query int true "用户ID"
  490. // @Param message query string true "留言信息"
  491. // @Param contactNum query string true "联系电话"
  492. // @Success 200 {object} app.Response
  493. // @Failure 500 {object} app.Response
  494. // @Router /User/AddMessageBoard [post]
  495. // @Tags 用户信息
  496. func AddMessageBoard(c *gin.Context) {
  497. appG := app.Gin{C: c}
  498. // 获取请求参数
  499. var req AddMessageBoardReq
  500. if err := appG.C.ShouldBind(&req); err != nil {
  501. logger.GetLogger().Errorf("AddMessageBoard failed: %s", err.Error())
  502. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  503. return
  504. }
  505. if errCode := models.InsertMessageBoard(req.UserID, req.Message, req.ContactNum); errCode != 0 {
  506. // 执行失败
  507. logger.GetLogger().Errorf("AddMessageBoard failed: %s", e.GetMsg(errCode))
  508. appG.Response(http.StatusBadRequest, errCode, nil)
  509. return
  510. }
  511. // 执行成功
  512. logger.GetLogger().Debugln("AddMessageBoard successed: %v", "ok")
  513. appG.Response(http.StatusOK, e.SUCCESS, "")
  514. }
  515. // UpdateUserAccountStatusReq 更新用户状态请求参数
  516. type UpdateUserAccountStatusReq struct {
  517. UserID int `form:"userID" binding:"required"`
  518. AccountStatus int `form:"accountStatus" binding:"required"`
  519. }
  520. // UpdateUserAccountStatus 更新用户状态
  521. // @Summary 更新用户状态
  522. // @Produce json
  523. // @Security ApiKeyAuth
  524. // @Param userID query int true "用户ID"
  525. // @Param accountStatus query int true "账户状态 - 4:正常 6:注销(停用)"
  526. // @Success 200 {object} app.Response
  527. // @Failure 500 {object} app.Response
  528. // @Router /User/UpdateUserAccountStatus [post]
  529. // @Tags 用户信息
  530. func UpdateUserAccountStatus(c *gin.Context) {
  531. appG := app.Gin{C: c}
  532. // 获取请求参数
  533. var req UpdateUserAccountStatusReq
  534. if err := appG.C.ShouldBind(&req); err != nil {
  535. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  536. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  537. return
  538. }
  539. if err := models.UpdateUserAccountStatus(req.UserID, req.AccountStatus); err != nil {
  540. // 执行失败
  541. logger.GetLogger().Errorf("UpdateUserAccountStatus failed: %s", err.Error())
  542. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  543. return
  544. }
  545. // 执行成功
  546. logger.GetLogger().Debugln("UpdateUserAccountStatus successed: %v", "ok")
  547. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  548. }
  549. // UpdateUserHeadUrlReq 更新用户头像请求参数
  550. type UpdateUserHeadUrlReq struct {
  551. UserID int `json:"userID" binding:"required"`
  552. Headurl string `json:"headurl" binding:"required"`
  553. }
  554. // UpdateUserHeadUrl 更新用户头像
  555. // @Summary 更新用户头像
  556. // @Produce json
  557. // @Security ApiKeyAuth
  558. // @Param data body UpdateUserHeadUrlReq true "入参"
  559. // @Success 200 {object} app.Response
  560. // @Failure 500 {object} app.Response
  561. // @Router /User/UpdateUserHeadUrl [post]
  562. // @Tags 用户信息
  563. func UpdateUserHeadUrl(c *gin.Context) {
  564. appG := app.Gin{C: c}
  565. // 获取请求参数
  566. var req UpdateUserHeadUrlReq
  567. if err := appG.C.ShouldBindJSON(&req); err != nil {
  568. logger.GetLogger().Errorf("UpdateUserHeadUrlReq failed: %s", err.Error())
  569. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  570. return
  571. }
  572. if err := models.UpdateUserHeadUrl(req.UserID, req.Headurl); err != nil {
  573. // 执行失败
  574. logger.GetLogger().Errorf("UpdateUserHeadUrl failed: %s", err.Error())
  575. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  576. return
  577. }
  578. // 执行成功
  579. logger.GetLogger().Debugln("UpdateUserHeadUrl successed: %v", "ok")
  580. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  581. }
  582. type QueryMdUserSwapProtocolReq struct {
  583. UserId int `form:"userId" binding:"required"` // 用户ID
  584. }
  585. // QueryMdUserSwapProtocol 获取用户掉期协议签署表
  586. // @Summary 获取用户掉期协议签署表
  587. // @Produce json
  588. // @Security ApiKeyAuth
  589. // @Param userId query int true "用户ID"
  590. // @Success 200 {array} models.Mduserswapprotocol
  591. // @Failure 500 {object} app.Response
  592. // @Router /User/QueryMdUserSwapProtocol [get]
  593. // @Tags 用户信息
  594. func QueryMdUserSwapProtocol(c *gin.Context) {
  595. appG := app.Gin{C: c}
  596. // 获取请求参数
  597. var req QueryMdUserSwapProtocolReq
  598. if err := appG.C.ShouldBindQuery(&req); err != nil {
  599. logger.GetLogger().Errorf("QueryMdUserSwapProtocol failed: %s", err.Error())
  600. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  601. return
  602. }
  603. datas, err := models.QueryMdUserSwapProtocol(req.UserId, nil)
  604. if err != nil {
  605. // 查询失败
  606. logger.GetLogger().Errorf("QueryMdUserSwapProtocol failed: %s", err.Error())
  607. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  608. return
  609. }
  610. // 查询成功
  611. appG.Response(http.StatusOK, e.SUCCESS, datas)
  612. }
  613. type GetTodayAccountConfigInfoReq struct {
  614. Accountid int64 `form:"accountid" binding:"required"` // 资金账户ID
  615. }
  616. // GetTodayAccountConfigInfo 获取资金账户今日配置信息
  617. // @Summary 获取资金账户今日配置信息
  618. // @Produce json
  619. // @Security ApiKeyAuth
  620. // @Param accountid query int true "资金账户ID"
  621. // @Success 200 {object} models.GetTodayAccountConfigInfoRsp
  622. // @Failure 500 {object} app.Response
  623. // @Router /User/GetTodayAccountConfigInfo [get]
  624. // @Tags 用户信息
  625. func GetTodayAccountConfigInfo(c *gin.Context) {
  626. appG := app.Gin{C: c}
  627. // 获取请求参数
  628. var req GetTodayAccountConfigInfoReq
  629. if err := appG.C.ShouldBindQuery(&req); err != nil {
  630. logger.GetLogger().Errorf("GetTodayAccountConfigInfo failed: %s", err.Error())
  631. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  632. return
  633. }
  634. datas, err := models.GetTodayAccountConfigInfo(int(req.Accountid))
  635. if err != nil {
  636. // 查询失败
  637. logger.GetLogger().Errorf("GetTodayAccountConfigInfo failed: %s", err.Error())
  638. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  639. return
  640. }
  641. // 查询成功
  642. appG.Response(http.StatusOK, e.SUCCESS, datas)
  643. }
  644. // UpdateUserInfoWechatAndEmailReq 更新用户微信和邮箱入参
  645. type UpdateUserInfoWechatAndEmailReq struct {
  646. UserID int `json:"userID" binding:"required "` // 用户ID
  647. Wechat *string `json:"wechat"` // 微信号,如不必修改则不传,传空为清除微信号
  648. Email *string `json:"email"` // 邮箱地址,如不必修改则不传,传空为清除邮箱地址
  649. }
  650. // UpdateUserInfoWechatAndEmail 更新用户微信和邮箱
  651. // @Summary 更新用户微信和邮箱
  652. // @Produce json
  653. // @Security ApiKeyAuth
  654. // @Param data body UpdateUserInfoWechatAndEmailReq true "入参"
  655. // @Success 200 {object} app.Response
  656. // @Failure 500 {object} app.Response
  657. // @Router /User/UpdateUserInfoWechatAndEmail [post]
  658. // @Tags 用户信息
  659. func UpdateUserInfoWechatAndEmail(c *gin.Context) {
  660. appG := app.Gin{C: c}
  661. // 获取请求参数
  662. var req UpdateUserInfoWechatAndEmailReq
  663. if err := appG.C.ShouldBindJSON(&req); err != nil {
  664. logger.GetLogger().Errorf("UpdateUserInfoWechatAndEmail failed: %s", err.Error())
  665. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  666. return
  667. }
  668. if err := models.UpdateUserInfoWechatAndEmail(req.Wechat, req.Email, req.UserID); err != nil {
  669. // 执行失败
  670. logger.GetLogger().Errorf("UpdateUserInfoWechatAndEmail failed: %s", err.Error())
  671. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  672. return
  673. }
  674. // 执行成功
  675. logger.GetLogger().Debugln("UpdateUserInfoWechatAndEmail successed:", "ok")
  676. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  677. }
  678. // GetUserScoreReq 用户积分信息查询请求参数
  679. type QueryUserScoreReq struct {
  680. UserID int `form:"userID" binding:"required"` // 用户ID
  681. }
  682. // QueryUserScore 用户积分信息查询
  683. // @Summary 用户积分信息查询
  684. // @Produce json
  685. // @Security ApiKeyAuth
  686. // @Param userID query int true "用户ID"
  687. // @Success 200 {object} models.QueryUserScoreRsp
  688. // @Failure 500 {object} app.Response
  689. // @Router /User/QueryUserScore [get]
  690. // @Tags 用户信息
  691. func QueryUserScore(c *gin.Context) {
  692. appG := app.Gin{C: c}
  693. // 获取请求参数
  694. var req QueryUserScoreReq
  695. if err := appG.C.ShouldBindQuery(&req); err != nil {
  696. logger.GetLogger().Errorf("QueryUserScore failed: %s", err.Error())
  697. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  698. return
  699. }
  700. datas, err := models.GetUserScore(req.UserID)
  701. if err != nil {
  702. // 查询失败
  703. logger.GetLogger().Errorf("QueryUserScore failed: %s", err.Error())
  704. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  705. return
  706. }
  707. // 查询成功
  708. appG.Response(http.StatusOK, e.SUCCESS, datas)
  709. }
  710. // QueryUserScoreDetail 用户积分明细查询
  711. // @Summary 用户积分明细查询
  712. // @Produce json
  713. // @Security ApiKeyAuth
  714. // @Param userID query int true "用户ID"
  715. // @Success 200 {object} models.QueryUserScoreDetailRsp
  716. // @Failure 500 {object} app.Response
  717. // @Router /User/QueryUserScoreDetail [get]
  718. // @Tags 用户信息
  719. func QueryUserScoreDetail(c *gin.Context) {
  720. appG := app.Gin{C: c}
  721. // 获取请求参数
  722. var req QueryUserScoreReq
  723. if err := appG.C.ShouldBindQuery(&req); err != nil {
  724. logger.GetLogger().Errorf("QueryUserScoreDetail failed: %s", err.Error())
  725. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  726. return
  727. }
  728. datas, err := models.GetUserScoreDetail(req.UserID)
  729. if err != nil {
  730. // 查询失败
  731. logger.GetLogger().Errorf("QueryUserScoreDetail failed: %s", err.Error())
  732. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  733. return
  734. }
  735. // 查询成功
  736. appG.Response(http.StatusOK, e.SUCCESS, datas)
  737. }