UserGroupLevel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\admin\controller\AuthController;
  4. use app\models\system\SystemGroupLevel;
  5. use think\facade\Route as Url;
  6. use crmeb\traits\CurdControllerTrait;
  7. use crmeb\services\{UtilService, JsonService, FormBuilder as Form};
  8. /**
  9. * 会员设置
  10. * Class UserLevel
  11. * @package app\admin\controller\user
  12. */
  13. class UserGroupLevel extends AuthController
  14. {
  15. use CurdControllerTrait;
  16. /*
  17. * 等级展示
  18. * */
  19. public function index()
  20. {
  21. return $this->fetch();
  22. }
  23. /*
  24. * 创建form表单
  25. * */
  26. public function create($id = 0)
  27. {
  28. if ($id) $vipinfo = SystemGroupLevel::get($id);
  29. $field[] = Form::input('name', '等级名称', isset($vipinfo) ? $vipinfo->name : '')->col(Form::col(24));
  30. $field[] = Form::number('suit_award', "套装极差奖", isset($vipinfo) ? $vipinfo->suit_award : 0)->min(0)->col(8);
  31. $field[] = Form::number('group_award', "普通商品极差奖(%)", isset($vipinfo) ? $vipinfo->group_award : 0)->min(0)->col(8);
  32. $field[] = Form::number('integral_group_award', "积分商品极差奖(%)", isset($vipinfo) ? $vipinfo->integral_group_award : 0)->min(0)->col(8);
  33. $field[] = Form::number('level_num', "伞下套装单数", isset($vipinfo) ? $vipinfo->level_num : 0)->min(0)->col(8);
  34. $field[] = Form::number('company_award', "分公司奖", isset($vipinfo) ? $vipinfo->company_award : 0)->min(0)->col(8);
  35. $field[] = Form::number('operate_award', "营运公司奖", isset($vipinfo) ? $vipinfo->operate_award : 0)->min(0)->col(8);
  36. $field[] = Form::radio('system_award', '参与加权分红', isset($vipinfo) ? $vipinfo->system_award : 0)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8);
  37. $field[] = Form::radio('is_show', '是否显示', isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(8);
  38. $field[] = Form::textarea('explain', '等级说明', isset($vipinfo) ? $vipinfo->explain : '');
  39. $form = Form::make_post_form('添加等级设置', $field, Url::buildUrl('save', ['id' => $id]), 2);
  40. $this->assign(compact('form'));
  41. return $this->fetch('public/form-builder');
  42. }
  43. /*
  44. * 会员等级添加或者修改
  45. * @param $id 修改的等级id
  46. * @return json
  47. * */
  48. public function save($id = 0)
  49. {
  50. $data = UtilService::postMore([
  51. ['name', ''],
  52. ['suit_award', 0],
  53. ['group_award', 0],
  54. ['integral_group_award', 0],
  55. ['level_num', 0],
  56. ['company_award', 0],
  57. ['operate_award', 0],
  58. ['is_show', ''],
  59. ['system_award', 0],
  60. ['explain', ''],
  61. ]);
  62. if (!$data['name']) JsonService::fail('请输入等级名称');
  63. SystemGroupLevel::beginTrans();
  64. try {
  65. //修改
  66. if ($id) {
  67. if (SystemGroupLevel::edit($data, $id)) {
  68. SystemGroupLevel::commitTrans();
  69. JsonService::successful('修改成功');
  70. } else {
  71. SystemGroupLevel::rollbackTrans();
  72. JsonService::fail('修改失败');
  73. }
  74. } else {
  75. //新增
  76. $data['add_time'] = time();
  77. if (SystemGroupLevel::create($data)) {
  78. SystemGroupLevel::commitTrans();
  79. JsonService::successful('添加成功');
  80. } else {
  81. SystemGroupLevel::rollbackTrans();
  82. JsonService::fail('添加失败');
  83. }
  84. }
  85. } catch (\Exception $e) {
  86. SystemGroupLevel::rollbackTrans();
  87. JsonService::fail($e->getMessage());
  88. }
  89. }
  90. /*
  91. * 获取系统设置的vip列表
  92. * @param int page
  93. * @param int limit
  94. * */
  95. public function get_system_vip_list()
  96. {
  97. $where = UtilService::getMore([
  98. ['page', 0],
  99. ['limit', 10],
  100. ['title', ''],
  101. ['is_show', ''],
  102. ]);
  103. JsonService::successlayui(SystemGroupLevel::getSystemList($where));
  104. }
  105. /*
  106. * 删除会员等级
  107. * @param int $id
  108. * */
  109. public function delete($id = 0)
  110. {
  111. if (SystemGroupLevel::edit(['is_del' => 1], $id))
  112. JsonService::successful('删除成功');
  113. else
  114. JsonService::fail('删除失败');
  115. }
  116. public function set_show($is_show = '', $id = '')
  117. {
  118. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  119. $res = SystemGroupLevel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  120. if ($res) {
  121. JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  122. } else {
  123. JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  124. }
  125. }
  126. public function set_value($field = '', $id = '', $value = '')
  127. {
  128. $field == '' || $id == '' || $value == '' && JsonService::fail('缺少参数');
  129. if (SystemGroupLevel::where(['id' => $id])->update([$field => $value]))
  130. JsonService::successful('保存成功');
  131. else
  132. JsonService::fail('保存失败');
  133. }
  134. }