Membergrade.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Membergrade extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/membergrade.lang.php');
  18. }
  19. public function index()
  20. {
  21. if (request()->isPost()) {
  22. $update_arr = array();
  23. if (!empty(input('post.mg/a'))) {
  24. $mg_arr = array();
  25. $i = 1;
  26. $max_exppoints = '-1'; #用户判断 下级会员等级积分应大于上级等级积分
  27. foreach (input('post.mg/a') as $k => $v) {
  28. $mg_arr[$i]['level'] = $i;
  29. $level_name = $v['level_name'];
  30. $exppoints = intval($v['exppoints']);
  31. if (empty($level_name)) {
  32. $this->error(lang('param_error'));
  33. }
  34. $mg_arr[$i]['level_name'] = $level_name;
  35. //所需经验值
  36. if ($max_exppoints >= $exppoints) {
  37. $this->error($level_name . lang('exppoints_greater_than') . $max_exppoints);
  38. } else {
  39. $mg_arr[$i]['exppoints'] = $exppoints;
  40. }
  41. $max_exppoints = $exppoints;
  42. $i++;
  43. }
  44. $update_arr['member_grade'] = serialize($mg_arr);
  45. } else {
  46. $this->error(lang('ds_common_op_fail'));
  47. }
  48. $result = true;
  49. if ($update_arr) {
  50. $config_model = model('config');
  51. $result = $config_model->editConfig($update_arr);
  52. }
  53. if ($result) {
  54. $this->log(lang('ds_edit') . lang('ds_member_grade'), 1);
  55. $this->success(lang('ds_common_save_succ'));
  56. } else {
  57. $this->log(lang('ds_edit') . lang('ds_member_grade'), 0);
  58. $this->error(lang('ds_common_save_fail'));
  59. }
  60. } else {
  61. $list_config = rkcache('config', true);
  62. $membergrade_list = $list_config['member_grade'] ? unserialize($list_config['member_grade']) : array();
  63. foreach ($membergrade_list as $key => $value) {
  64. $maxlevel[] = $value['level'];
  65. }
  66. View::assign('maxlevel', max($maxlevel) + 1);
  67. View::assign('membergrade_list', $membergrade_list);
  68. $this->setAdminCurItem('index');
  69. return View::fetch();
  70. }
  71. }
  72. /**
  73. * 获取卖家栏目列表,针对控制器下的栏目
  74. */
  75. protected function getAdminItemList()
  76. {
  77. $menu_array = array(
  78. array(
  79. 'name' => 'index',
  80. 'text' => lang('ds_manage'),
  81. 'url' => (string)url('Membergrade/index')
  82. )
  83. );
  84. return $menu_array;
  85. }
  86. }