UserLevel.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\user;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\user\UserLevelServices;
  14. use think\facade\App;
  15. /**
  16. * 会员设置
  17. * Class UserLevel
  18. * @package app\adminapi\controller\v1\user
  19. */
  20. class UserLevel extends AuthController
  21. {
  22. /**
  23. * user constructor.
  24. * @param App $app
  25. * @param UserLevelServices $services
  26. */
  27. public function __construct(App $app, UserLevelServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /*
  33. * 获取添加资源表单
  34. * */
  35. public function create()
  36. {
  37. $where = $this->request->getMore(
  38. ['id', 0]
  39. );
  40. return app('json')->success($this->services->edit((int)$where['id']));
  41. }
  42. /*
  43. * 会员等级添加或者修改
  44. * @param $id 修改的等级id
  45. * @return json
  46. * */
  47. public function save()
  48. {
  49. $data = $this->request->postMore([
  50. ['id', 0],
  51. ['name', ''],
  52. ['is_forever', 0],
  53. ['money', 0],
  54. ['is_pay', 0],
  55. ['valid_date', 0],
  56. ['grade', 0],
  57. ['discount', 0],
  58. ['icon', ''],
  59. ['image', ''],
  60. ['is_show', ''],
  61. ['exp_num', 0]
  62. ]);
  63. if ($data['valid_date'] == 0) $data['is_forever'] = 1;//有效时间为0的时候就是永久
  64. if (!$data['name']) return app('json')->fail(400324);
  65. if (!$data['grade']) return app('json')->fail(400325);
  66. if (!$data['icon']) return app('json')->fail(400327);
  67. if (!$data['image']) return app('json')->fail(400328);
  68. if (!$data['exp_num']) return app('json')->fail(400329);
  69. $this->services->save((int)$data['id'], $data);
  70. return app('json')->success(100000);
  71. }
  72. /*
  73. * 获取系统设置的vip列表
  74. * @param int page
  75. * @param int limit
  76. * */
  77. public function get_system_vip_list()
  78. {
  79. $where = $this->request->getMore([
  80. ['page', 0],
  81. ['limit', 10],
  82. ['title', ''],
  83. ['is_show', ''],
  84. ]);
  85. return app('json')->success($this->services->getSytemList($where));
  86. }
  87. /*
  88. * 删除会员等级
  89. * @param int $id
  90. * */
  91. public function delete($id)
  92. {
  93. return app('json')->success($this->services->delLevel((int)$id));
  94. }
  95. /**
  96. * 设置会员等级显示|隐藏
  97. *
  98. * @return json
  99. */
  100. public function set_show($is_show = '', $id = '')
  101. {
  102. if ($is_show == '' || $id == '') return app('json')->fail(100100);
  103. return app('json')->success($this->services->setShow((int)$id, (int)$is_show));
  104. }
  105. /**
  106. * 等级列表快速编辑
  107. * field:value name:钻石会员/grade:8/discount:92.00
  108. * @return json
  109. */
  110. public function set_value($id)
  111. {
  112. $data = $this->request->postMore([
  113. ['field', ''],
  114. ['value', '']
  115. ]);
  116. if ($data['field'] == '' || $data['value'] == '') return app('json')->fail(100100);
  117. $this->services->setValue((int)$id, $data);
  118. return app('json')->success(100000);
  119. }
  120. }