UserLevel.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\user;
  12. use app\controller\admin\AuthController;
  13. use app\services\user\level\UserLevelServices;
  14. use think\facade\App;
  15. /**
  16. * 会员设置
  17. * Class UserLevel
  18. * @package app\controller\admin\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 $this->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. ['explain', ''],
  62. ['exp_num', 0],
  63. ['achievement', 0],
  64. ['sub_grade_num', 0],
  65. ['group_award', 0],
  66. ]);
  67. if ($data['valid_date'] == 0) $data['is_forever'] = 1;//有效时间为0的时候就是永久
  68. if (!$data['name']) return $this->fail('请输入等级名称');
  69. if (!$data['grade']) return $this->fail('请输入等级');
  70. if (!$data['explain']) return $this->fail('请输入等级说明');
  71. if (!$data['icon']) return $this->fail('请上传等级图标');
  72. if (!$data['image']) return $this->fail('请上传等级背景图标');
  73. // if (!$data['exp_num']) return $this->fail('请输入升级经验值');
  74. if (!$data['achievement']) return $this->fail('请输入升级业绩');
  75. return $this->success($this->services->save((int)$data['id'], $data));
  76. }
  77. /*
  78. * 获取系统设置的vip列表
  79. * @param int page
  80. * @param int limit
  81. * */
  82. public function get_system_vip_list()
  83. {
  84. $where = $this->request->getMore([
  85. ['page', 0],
  86. ['limit', 10],
  87. ['title', ''],
  88. ['is_show', ''],
  89. ]);
  90. return $this->success($this->services->getSytemList($where));
  91. }
  92. /*
  93. * 删除会员等级
  94. * @param int $id
  95. * */
  96. public function delete($id)
  97. {
  98. return $this->success($this->services->delLevel((int)$id));
  99. }
  100. /**
  101. * 设置会员等级显示|隐藏
  102. *
  103. * @return json
  104. */
  105. public function set_show($is_show = '', $id = '')
  106. {
  107. if ($is_show == '' || $id == '') return $this->fail('缺少参数');
  108. return $this->success($this->services->setShow((int)$id, (int)$is_show));
  109. }
  110. /**
  111. * 等级列表快速编辑
  112. * field:value name:钻石会员/grade:8/discount:92.00
  113. * @return json
  114. */
  115. public function set_value($id)
  116. {
  117. $data = $this->request->postMore([
  118. ['field', ''],
  119. ['value', '']
  120. ]);
  121. if ($data['field'] == '' || $data['value'] == '') return $this->fail('缺少参数');
  122. $this->services->setValue((int)$id, $data);
  123. return $this->success('保存成功');
  124. }
  125. }