心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemberGroupController.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2020年06月25日
  7. * 会员等级控制器
  8. */
  9. namespace app\admin\controller\member;
  10. use core\basic\Controller;
  11. use app\admin\model\member\MemberGroupModel;
  12. class MemberGroupController extends Controller
  13. {
  14. private $model;
  15. public function __construct()
  16. {
  17. $this->model = new MemberGroupModel();
  18. }
  19. // 会员等级列表
  20. public function index()
  21. {
  22. if ((! ! $id = get('id', 'int')) && $result = $this->model->getGroup($id)) {
  23. $this->assign('more', true);
  24. $this->assign('group', $result);
  25. } else {
  26. $this->assign('list', true);
  27. if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
  28. $result = $this->model->findGroup($field, $keyword);
  29. } else {
  30. $result = $this->model->getList();
  31. }
  32. $this->assign('groups', $result);
  33. }
  34. $this->display('member/group.html');
  35. }
  36. // 会员等级增加
  37. public function add()
  38. {
  39. if ($_POST) {
  40. // 获取数据
  41. $gcode = post('gcode', 'int') ?: get_auto_code($this->model->getLastGid(), 1);
  42. $gname = post('gname');
  43. $description = post('description');
  44. $status = post('status') ?: 1;
  45. $lscore = post('lscore', 'int') ?: 0;
  46. $uscore = post('uscore', 'int') ?: 9999999999;
  47. if (! $gcode) {
  48. alert_back('等级编号不能为空!');
  49. }
  50. if (! $gname) {
  51. alert_back('等级名称不能为空!');
  52. }
  53. if ($this->model->findGroupCode($gcode)) {
  54. alert_back('等级编码不能重复!');
  55. }
  56. // 构建数据
  57. $data = array(
  58. 'gcode' => $gcode,
  59. 'gname' => $gname,
  60. 'description' => $description,
  61. 'status' => $status,
  62. 'lscore' => $lscore,
  63. 'uscore' => $uscore,
  64. 'create_user' => session('username'),
  65. 'update_user' => session('username')
  66. );
  67. // 执行会员等级添加
  68. if ($this->model->addGroup($data)) {
  69. $this->log('新增会员等级成功!');
  70. if (! ! $backurl = get('backurl')) {
  71. success('新增成功!', base64_decode($backurl));
  72. } else {
  73. success('新增成功!', url('/admin/MemberGroup/index'));
  74. }
  75. } else {
  76. $this->log('新增会员等级失败!');
  77. error('新增失败!', - 1);
  78. }
  79. }
  80. }
  81. // 会员等级删除
  82. public function del()
  83. {
  84. if (! $id = get('id', 'int')) {
  85. error('传递的参数值错误!', - 1);
  86. }
  87. if ($this->model->findGroupUser($id)) {
  88. error('会员等级下存在用户,无法直接删除!', - 1);
  89. }
  90. if ($this->model->delGroup($id)) {
  91. $this->log('删除会员等级' . $id . '成功!');
  92. success('删除成功!', - 1);
  93. } else {
  94. $this->log('删除会员等级' . $id . '失败!');
  95. error('删除失败!', - 1);
  96. }
  97. }
  98. // 会员等级修改
  99. public function mod()
  100. {
  101. if (! $id = get('id', 'int')) {
  102. error('传递的参数值错误!', - 1);
  103. }
  104. // 单独修改状态
  105. if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
  106. if ($this->model->modGroup($id, "$field='$value',update_user='" . session('username') . "'")) {
  107. location(- 1);
  108. } else {
  109. alert_back('修改失败!');
  110. }
  111. }
  112. // 修改操作
  113. if ($_POST) {
  114. // 获取数据
  115. $gcode = post('gcode', 'int') ?: get_auto_code($this->model->getLastGid(), 1);
  116. $gname = post('gname');
  117. $description = post('description');
  118. $status = post('status') ?: 1;
  119. $lscore = post('lscore', 'int') ?: 0;
  120. $uscore = post('uscore', 'int') ?: 9999999999;
  121. if (! $gcode) {
  122. alert_back('等级编号不能为空!');
  123. }
  124. if (! $gname) {
  125. alert_back('等级名称不能为空!');
  126. }
  127. if ($this->model->findGroupCode($gcode, $id)) {
  128. alert_back('等级编码不能重复!');
  129. }
  130. // 构建数据
  131. $data = array(
  132. 'gcode' => $gcode,
  133. 'gname' => $gname,
  134. 'description' => $description,
  135. 'status' => $status,
  136. 'lscore' => $lscore,
  137. 'uscore' => $uscore,
  138. 'update_user' => session('username')
  139. );
  140. // 执行会员等级修改
  141. if ($this->model->modGroup($id, $data)) {
  142. $this->log('修改会员等级成功!');
  143. if (! ! $backurl = get('backurl')) {
  144. success('修改成功!', base64_decode($backurl));
  145. } else {
  146. success('修改成功!', url('/admin/MemberGroup/index'));
  147. }
  148. } else {
  149. $this->log('修改会员等级失败!');
  150. error('修改失败!', - 1);
  151. }
  152. } else {
  153. // 调取修改内容
  154. $this->assign('mod', true);
  155. if (! $result = $this->model->getGroup($id)) {
  156. error('编辑的内容已经不存在!', - 1);
  157. }
  158. $this->assign('group', $result);
  159. $this->display('member/group.html');
  160. }
  161. }
  162. }