user.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. package controller
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "one-api/common"
  8. "one-api/model"
  9. "strconv"
  10. "github.com/gin-contrib/sessions"
  11. "github.com/gin-gonic/gin"
  12. )
  13. type LoginRequest struct {
  14. Username string `json:"username"`
  15. Password string `json:"password"`
  16. }
  17. func Login(c *gin.Context) {
  18. if !common.PasswordLoginEnabled {
  19. c.JSON(http.StatusOK, gin.H{
  20. "message": "管理员关闭了密码登录",
  21. "success": false,
  22. })
  23. return
  24. }
  25. var loginRequest LoginRequest
  26. err := json.NewDecoder(c.Request.Body).Decode(&loginRequest)
  27. if err != nil {
  28. c.JSON(http.StatusOK, gin.H{
  29. "message": "无效的参数",
  30. "success": false,
  31. })
  32. return
  33. }
  34. username := loginRequest.Username
  35. password := loginRequest.Password
  36. if username == "" || password == "" {
  37. c.JSON(http.StatusOK, gin.H{
  38. "message": "无效的参数",
  39. "success": false,
  40. })
  41. return
  42. }
  43. user := model.User{
  44. Username: username,
  45. Password: password,
  46. }
  47. err = user.ValidateAndFill()
  48. if err != nil {
  49. c.JSON(http.StatusOK, gin.H{
  50. "message": err.Error(),
  51. "success": false,
  52. })
  53. return
  54. }
  55. setupLogin(&user, c)
  56. }
  57. // setup session & cookies and then return user info
  58. func setupLogin(user *model.User, c *gin.Context) {
  59. session := sessions.Default(c)
  60. session.Set("id", user.Id)
  61. session.Set("username", user.Username)
  62. session.Set("role", user.Role)
  63. session.Set("status", user.Status)
  64. err := session.Save()
  65. if err != nil {
  66. c.JSON(http.StatusOK, gin.H{
  67. "message": "无法保存会话信息,请重试",
  68. "success": false,
  69. })
  70. return
  71. }
  72. cleanUser := model.User{
  73. Id: user.Id,
  74. Username: user.Username,
  75. DisplayName: user.DisplayName,
  76. Role: user.Role,
  77. Status: user.Status,
  78. StableMode: user.StableMode,
  79. MaxPrice: user.MaxPrice,
  80. }
  81. c.JSON(http.StatusOK, gin.H{
  82. "message": "",
  83. "success": true,
  84. "data": cleanUser,
  85. })
  86. }
  87. func Logout(c *gin.Context) {
  88. session := sessions.Default(c)
  89. session.Clear()
  90. err := session.Save()
  91. if err != nil {
  92. c.JSON(http.StatusOK, gin.H{
  93. "message": err.Error(),
  94. "success": false,
  95. })
  96. return
  97. }
  98. c.JSON(http.StatusOK, gin.H{
  99. "message": "",
  100. "success": true,
  101. })
  102. }
  103. func Register(c *gin.Context) {
  104. if !common.RegisterEnabled {
  105. c.JSON(http.StatusOK, gin.H{
  106. "message": "管理员关闭了新用户注册",
  107. "success": false,
  108. })
  109. return
  110. }
  111. if !common.PasswordRegisterEnabled {
  112. c.JSON(http.StatusOK, gin.H{
  113. "message": "管理员关闭了通过密码进行注册,请使用第三方账户验证的形式进行注册",
  114. "success": false,
  115. })
  116. return
  117. }
  118. var user model.User
  119. err := json.NewDecoder(c.Request.Body).Decode(&user)
  120. if err != nil {
  121. c.JSON(http.StatusOK, gin.H{
  122. "success": false,
  123. "message": "无效的参数",
  124. })
  125. return
  126. }
  127. if err := common.Validate.Struct(&user); err != nil {
  128. c.JSON(http.StatusOK, gin.H{
  129. "success": false,
  130. "message": "输入不合法 " + err.Error(),
  131. })
  132. return
  133. }
  134. if common.EmailVerificationEnabled {
  135. if user.Email == "" || user.VerificationCode == "" {
  136. c.JSON(http.StatusOK, gin.H{
  137. "success": false,
  138. "message": "管理员开启了邮箱验证,请输入邮箱地址和验证码",
  139. })
  140. return
  141. }
  142. if !common.VerifyCodeWithKey(user.Email, user.VerificationCode, common.EmailVerificationPurpose) {
  143. c.JSON(http.StatusOK, gin.H{
  144. "success": false,
  145. "message": "验证码错误或已过期",
  146. })
  147. return
  148. }
  149. }
  150. affCode := user.AffCode // this code is the inviter's code, not the user's own code
  151. inviterId, _ := model.GetUserIdByAffCode(affCode)
  152. cleanUser := model.User{
  153. Username: user.Username,
  154. Password: user.Password,
  155. DisplayName: user.Username,
  156. InviterId: inviterId,
  157. StableMode: user.StableMode,
  158. MaxPrice: user.MaxPrice,
  159. }
  160. if common.EmailVerificationEnabled {
  161. cleanUser.Email = user.Email
  162. }
  163. if err := cleanUser.Insert(inviterId); err != nil {
  164. c.JSON(http.StatusOK, gin.H{
  165. "success": false,
  166. "message": err.Error(),
  167. })
  168. return
  169. }
  170. c.JSON(http.StatusOK, gin.H{
  171. "success": true,
  172. "message": "",
  173. })
  174. return
  175. }
  176. func GetAllUsers(c *gin.Context) {
  177. p, _ := strconv.Atoi(c.Query("p"))
  178. if p < 0 {
  179. p = 0
  180. }
  181. users, err := model.GetAllUsers(p*common.ItemsPerPage, common.ItemsPerPage)
  182. if err != nil {
  183. c.JSON(http.StatusOK, gin.H{
  184. "success": false,
  185. "message": err.Error(),
  186. })
  187. return
  188. }
  189. c.JSON(http.StatusOK, gin.H{
  190. "success": true,
  191. "message": "",
  192. "data": users,
  193. })
  194. return
  195. }
  196. func SearchUsers(c *gin.Context) {
  197. keyword := c.Query("keyword")
  198. users, err := model.SearchUsers(keyword)
  199. if err != nil {
  200. c.JSON(http.StatusOK, gin.H{
  201. "success": false,
  202. "message": err.Error(),
  203. })
  204. return
  205. }
  206. c.JSON(http.StatusOK, gin.H{
  207. "success": true,
  208. "message": "",
  209. "data": users,
  210. })
  211. return
  212. }
  213. func GetUser(c *gin.Context) {
  214. id, err := strconv.Atoi(c.Param("id"))
  215. if err != nil {
  216. c.JSON(http.StatusOK, gin.H{
  217. "success": false,
  218. "message": err.Error(),
  219. })
  220. return
  221. }
  222. user, err := model.GetUserById(id, false)
  223. if err != nil {
  224. c.JSON(http.StatusOK, gin.H{
  225. "success": false,
  226. "message": err.Error(),
  227. })
  228. return
  229. }
  230. myRole := c.GetInt("role")
  231. if myRole <= user.Role && myRole != common.RoleRootUser {
  232. c.JSON(http.StatusOK, gin.H{
  233. "success": false,
  234. "message": "无权获取同级或更高等级用户的信息",
  235. })
  236. return
  237. }
  238. c.JSON(http.StatusOK, gin.H{
  239. "success": true,
  240. "message": "",
  241. "data": user,
  242. })
  243. return
  244. }
  245. func GenerateAccessToken(c *gin.Context) {
  246. id := c.GetInt("id")
  247. user, err := model.GetUserById(id, true)
  248. if err != nil {
  249. c.JSON(http.StatusOK, gin.H{
  250. "success": false,
  251. "message": err.Error(),
  252. })
  253. return
  254. }
  255. user.AccessToken = common.GetUUID()
  256. if model.DB.Where("access_token = ?", user.AccessToken).First(user).RowsAffected != 0 {
  257. c.JSON(http.StatusOK, gin.H{
  258. "success": false,
  259. "message": "请重试,系统生成的 UUID 竟然重复了!",
  260. })
  261. return
  262. }
  263. if err := user.Update(false); err != nil {
  264. c.JSON(http.StatusOK, gin.H{
  265. "success": false,
  266. "message": err.Error(),
  267. })
  268. return
  269. }
  270. c.JSON(http.StatusOK, gin.H{
  271. "success": true,
  272. "message": "",
  273. "data": user.AccessToken,
  274. })
  275. return
  276. }
  277. func GetAffCode(c *gin.Context) {
  278. id := c.GetInt("id")
  279. user, err := model.GetUserById(id, true)
  280. if err != nil {
  281. c.JSON(http.StatusOK, gin.H{
  282. "success": false,
  283. "message": err.Error(),
  284. })
  285. return
  286. }
  287. if user.AffCode == "" {
  288. user.AffCode = common.GetRandomString(4)
  289. if err := user.Update(false); err != nil {
  290. c.JSON(http.StatusOK, gin.H{
  291. "success": false,
  292. "message": err.Error(),
  293. })
  294. return
  295. }
  296. }
  297. c.JSON(http.StatusOK, gin.H{
  298. "success": true,
  299. "message": "",
  300. "data": user.AffCode,
  301. })
  302. return
  303. }
  304. func GetSelf(c *gin.Context) {
  305. id := c.GetInt("id")
  306. user, err := model.GetUserById(id, false)
  307. if err != nil {
  308. c.JSON(http.StatusOK, gin.H{
  309. "success": false,
  310. "message": err.Error(),
  311. })
  312. return
  313. }
  314. c.JSON(http.StatusOK, gin.H{
  315. "success": true,
  316. "message": "",
  317. "data": user,
  318. })
  319. return
  320. }
  321. func UpdateUser(c *gin.Context) {
  322. var updatedUser model.User
  323. err := json.NewDecoder(c.Request.Body).Decode(&updatedUser)
  324. if err != nil || updatedUser.Id == 0 {
  325. c.JSON(http.StatusOK, gin.H{
  326. "success": false,
  327. "message": "无效的参数",
  328. })
  329. return
  330. }
  331. if updatedUser.Password == "" {
  332. updatedUser.Password = "$I_LOVE_U" // make Validator happy :)
  333. }
  334. if err := common.Validate.Struct(&updatedUser); err != nil {
  335. c.JSON(http.StatusOK, gin.H{
  336. "success": false,
  337. "message": "输入不合法 " + err.Error(),
  338. })
  339. return
  340. }
  341. originUser, err := model.GetUserById(updatedUser.Id, false)
  342. if err != nil {
  343. c.JSON(http.StatusOK, gin.H{
  344. "success": false,
  345. "message": err.Error(),
  346. })
  347. return
  348. }
  349. myRole := c.GetInt("role")
  350. if myRole <= originUser.Role && myRole != common.RoleRootUser {
  351. c.JSON(http.StatusOK, gin.H{
  352. "success": false,
  353. "message": "无权更新同权限等级或更高权限等级的用户信息",
  354. })
  355. return
  356. }
  357. if myRole <= updatedUser.Role && myRole != common.RoleRootUser {
  358. c.JSON(http.StatusOK, gin.H{
  359. "success": false,
  360. "message": "无权将其他用户权限等级提升到大于等于自己的权限等级",
  361. })
  362. return
  363. }
  364. if updatedUser.Password == "$I_LOVE_U" {
  365. updatedUser.Password = "" // rollback to what it should be
  366. }
  367. updatePassword := updatedUser.Password != ""
  368. if err := updatedUser.Update(updatePassword); err != nil {
  369. c.JSON(http.StatusOK, gin.H{
  370. "success": false,
  371. "message": err.Error(),
  372. })
  373. return
  374. }
  375. if originUser.Quota != updatedUser.Quota {
  376. model.RecordLog(originUser.Id, model.LogTypeManage, fmt.Sprintf("管理员将用户额度从 %s修改为 %s", common.LogQuota(originUser.Quota), common.LogQuota(updatedUser.Quota)))
  377. }
  378. c.JSON(http.StatusOK, gin.H{
  379. "success": true,
  380. "message": "",
  381. })
  382. return
  383. }
  384. func UpdateSelf(c *gin.Context) {
  385. var user model.User
  386. err := json.NewDecoder(c.Request.Body).Decode(&user)
  387. if err != nil {
  388. c.JSON(http.StatusOK, gin.H{
  389. "success": false,
  390. "message": "无效的参数",
  391. })
  392. return
  393. }
  394. if user.Password == "" {
  395. user.Password = "$I_LOVE_U" // make Validator happy :)
  396. }
  397. if err := common.Validate.Struct(&user); err != nil {
  398. c.JSON(http.StatusOK, gin.H{
  399. "success": false,
  400. "message": "输入不合法 " + err.Error(),
  401. })
  402. return
  403. }
  404. cleanUser := model.User{
  405. Id: c.GetInt("id"),
  406. Username: user.Username,
  407. Password: user.Password,
  408. DisplayName: user.DisplayName,
  409. StableMode: user.StableMode,
  410. MaxPrice: user.MaxPrice,
  411. }
  412. if user.Password == "$I_LOVE_U" {
  413. user.Password = "" // rollback to what it should be
  414. cleanUser.Password = ""
  415. }
  416. updatePassword := user.Password != ""
  417. if err := cleanUser.Update(updatePassword); err != nil {
  418. c.JSON(http.StatusOK, gin.H{
  419. "success": false,
  420. "message": err.Error(),
  421. })
  422. return
  423. }
  424. c.JSON(http.StatusOK, gin.H{
  425. "success": true,
  426. "message": "",
  427. })
  428. return
  429. }
  430. func DeleteUser(c *gin.Context) {
  431. id, err := strconv.Atoi(c.Param("id"))
  432. if err != nil {
  433. c.JSON(http.StatusOK, gin.H{
  434. "success": false,
  435. "message": err.Error(),
  436. })
  437. return
  438. }
  439. originUser, err := model.GetUserById(id, false)
  440. if err != nil {
  441. c.JSON(http.StatusOK, gin.H{
  442. "success": false,
  443. "message": err.Error(),
  444. })
  445. return
  446. }
  447. myRole := c.GetInt("role")
  448. if myRole <= originUser.Role {
  449. c.JSON(http.StatusOK, gin.H{
  450. "success": false,
  451. "message": "无权删除同权限等级或更高权限等级的用户",
  452. })
  453. return
  454. }
  455. err = model.DeleteUserById(id)
  456. if err != nil {
  457. c.JSON(http.StatusOK, gin.H{
  458. "success": true,
  459. "message": "",
  460. })
  461. return
  462. }
  463. }
  464. func DeleteSelf(c *gin.Context) {
  465. id := c.GetInt("id")
  466. user, _ := model.GetUserById(id, false)
  467. if user.Role == common.RoleRootUser {
  468. c.JSON(http.StatusOK, gin.H{
  469. "success": false,
  470. "message": "不能删除超级管理员账户",
  471. })
  472. return
  473. }
  474. err := model.DeleteUserById(id)
  475. if err != nil {
  476. c.JSON(http.StatusOK, gin.H{
  477. "success": false,
  478. "message": err.Error(),
  479. })
  480. return
  481. }
  482. c.JSON(http.StatusOK, gin.H{
  483. "success": true,
  484. "message": "",
  485. })
  486. return
  487. }
  488. func CreateUser(c *gin.Context) {
  489. var user model.User
  490. err := json.NewDecoder(c.Request.Body).Decode(&user)
  491. if err != nil || user.Username == "" || user.Password == "" {
  492. c.JSON(http.StatusOK, gin.H{
  493. "success": false,
  494. "message": "无效的参数",
  495. })
  496. return
  497. }
  498. if err := common.Validate.Struct(&user); err != nil {
  499. c.JSON(http.StatusOK, gin.H{
  500. "success": false,
  501. "message": "输入不合法 " + err.Error(),
  502. })
  503. return
  504. }
  505. if user.DisplayName == "" {
  506. user.DisplayName = user.Username
  507. }
  508. myRole := c.GetInt("role")
  509. if user.Role >= myRole {
  510. c.JSON(http.StatusOK, gin.H{
  511. "success": false,
  512. "message": "无法创建权限大于等于自己的用户",
  513. })
  514. return
  515. }
  516. // Even for admin users, we cannot fully trust them!
  517. cleanUser := model.User{
  518. Username: user.Username,
  519. Password: user.Password,
  520. DisplayName: user.DisplayName,
  521. }
  522. if err := cleanUser.Insert(0); err != nil {
  523. c.JSON(http.StatusOK, gin.H{
  524. "success": false,
  525. "message": err.Error(),
  526. })
  527. return
  528. }
  529. c.JSON(http.StatusOK, gin.H{
  530. "success": true,
  531. "message": "",
  532. })
  533. return
  534. }
  535. type ManageRequest struct {
  536. Username string `json:"username"`
  537. Action string `json:"action"`
  538. }
  539. // ManageUser Only admin user can do this
  540. func ManageUser(c *gin.Context) {
  541. var req ManageRequest
  542. err := json.NewDecoder(c.Request.Body).Decode(&req)
  543. if err != nil {
  544. c.JSON(http.StatusOK, gin.H{
  545. "success": false,
  546. "message": "无效的参数",
  547. })
  548. return
  549. }
  550. user := model.User{
  551. Username: req.Username,
  552. }
  553. // Fill attributes
  554. model.DB.Where(&user).First(&user)
  555. if user.Id == 0 {
  556. c.JSON(http.StatusOK, gin.H{
  557. "success": false,
  558. "message": "用户不存在",
  559. })
  560. return
  561. }
  562. myRole := c.GetInt("role")
  563. if myRole <= user.Role && myRole != common.RoleRootUser {
  564. c.JSON(http.StatusOK, gin.H{
  565. "success": false,
  566. "message": "无权更新同权限等级或更高权限等级的用户信息",
  567. })
  568. return
  569. }
  570. switch req.Action {
  571. case "disable":
  572. user.Status = common.UserStatusDisabled
  573. if user.Role == common.RoleRootUser {
  574. c.JSON(http.StatusOK, gin.H{
  575. "success": false,
  576. "message": "无法禁用超级管理员用户",
  577. })
  578. return
  579. }
  580. case "enable":
  581. user.Status = common.UserStatusEnabled
  582. case "delete":
  583. if user.Role == common.RoleRootUser {
  584. c.JSON(http.StatusOK, gin.H{
  585. "success": false,
  586. "message": "无法删除超级管理员用户",
  587. })
  588. return
  589. }
  590. if err := user.Delete(); err != nil {
  591. c.JSON(http.StatusOK, gin.H{
  592. "success": false,
  593. "message": err.Error(),
  594. })
  595. return
  596. }
  597. case "promote":
  598. if myRole != common.RoleRootUser {
  599. c.JSON(http.StatusOK, gin.H{
  600. "success": false,
  601. "message": "普通管理员用户无法提升其他用户为管理员",
  602. })
  603. return
  604. }
  605. if user.Role >= common.RoleAdminUser {
  606. c.JSON(http.StatusOK, gin.H{
  607. "success": false,
  608. "message": "该用户已经是管理员",
  609. })
  610. return
  611. }
  612. user.Role = common.RoleAdminUser
  613. case "demote":
  614. if user.Role == common.RoleRootUser {
  615. c.JSON(http.StatusOK, gin.H{
  616. "success": false,
  617. "message": "无法降级超级管理员用户",
  618. })
  619. return
  620. }
  621. if user.Role == common.RoleCommonUser {
  622. c.JSON(http.StatusOK, gin.H{
  623. "success": false,
  624. "message": "该用户已经是普通用户",
  625. })
  626. return
  627. }
  628. user.Role = common.RoleCommonUser
  629. }
  630. if err := user.Update(false); err != nil {
  631. c.JSON(http.StatusOK, gin.H{
  632. "success": false,
  633. "message": err.Error(),
  634. })
  635. return
  636. }
  637. clearUser := model.User{
  638. Role: user.Role,
  639. Status: user.Status,
  640. }
  641. c.JSON(http.StatusOK, gin.H{
  642. "success": true,
  643. "message": "",
  644. "data": clearUser,
  645. })
  646. return
  647. }
  648. func EmailBind(c *gin.Context) {
  649. email := c.Query("email")
  650. code := c.Query("code")
  651. if !common.VerifyCodeWithKey(email, code, common.EmailVerificationPurpose) {
  652. c.JSON(http.StatusOK, gin.H{
  653. "success": false,
  654. "message": "验证码错误或已过期",
  655. })
  656. return
  657. }
  658. id := c.GetInt("id")
  659. user := model.User{
  660. Id: id,
  661. }
  662. err := user.FillUserById()
  663. if err != nil {
  664. c.JSON(http.StatusOK, gin.H{
  665. "success": false,
  666. "message": err.Error(),
  667. })
  668. return
  669. }
  670. user.Email = email
  671. // no need to check if this email already taken, because we have used verification code to check it
  672. err = user.Update(false)
  673. if err != nil {
  674. c.JSON(http.StatusOK, gin.H{
  675. "success": false,
  676. "message": err.Error(),
  677. })
  678. return
  679. }
  680. if user.Role == common.RoleRootUser {
  681. common.RootUserEmail = email
  682. }
  683. c.JSON(http.StatusOK, gin.H{
  684. "success": true,
  685. "message": "",
  686. })
  687. return
  688. }
  689. type topUpRequest struct {
  690. Key string `json:"key"`
  691. }
  692. func TopUp(c *gin.Context) {
  693. req := topUpRequest{}
  694. err := c.ShouldBindJSON(&req)
  695. if err != nil {
  696. c.JSON(http.StatusOK, gin.H{
  697. "success": false,
  698. "message": err.Error(),
  699. })
  700. return
  701. }
  702. id := c.GetInt("id")
  703. quota, err := model.Redeem(req.Key, id)
  704. if err != nil {
  705. c.JSON(http.StatusOK, gin.H{
  706. "success": false,
  707. "message": err.Error(),
  708. })
  709. return
  710. }
  711. c.JSON(http.StatusOK, gin.H{
  712. "success": true,
  713. "message": "",
  714. "data": quota,
  715. })
  716. return
  717. }
  718. type StableModeRequest struct {
  719. StableMode bool `json:"stableMode"`
  720. MaxPrice string `json:"maxPrice"`
  721. }
  722. func SetTableMode(c *gin.Context) {
  723. req := &StableModeRequest{}
  724. err := c.ShouldBindJSON(&req)
  725. if err != nil {
  726. c.JSON(http.StatusOK, gin.H{
  727. "success": false,
  728. "message": err.Error(),
  729. })
  730. return
  731. }
  732. log.Println(req)
  733. id := c.GetInt("id")
  734. user := model.User{
  735. Id: id,
  736. }
  737. err = user.FillUserById()
  738. if err != nil {
  739. c.JSON(http.StatusOK, gin.H{
  740. "success": false,
  741. "message": err.Error(),
  742. })
  743. return
  744. }
  745. user.StableMode = req.StableMode
  746. if !req.StableMode {
  747. req.MaxPrice = "0"
  748. }
  749. user.MaxPrice = req.MaxPrice
  750. err = user.Update(false)
  751. if err != nil {
  752. c.JSON(http.StatusOK, gin.H{
  753. "success": false,
  754. "message": err.Error(),
  755. })
  756. return
  757. }
  758. c.JSON(http.StatusOK, gin.H{
  759. "success": true,
  760. "message": "",
  761. "data": "设置成功",
  762. })
  763. return
  764. }