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