Rule.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 会员规则管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Rule extends Backend
  11. {
  12. /**
  13. * @var \app\admin\model\UserRule
  14. */
  15. protected $model = null;
  16. protected $rulelist = [];
  17. protected $multiFields = 'ismenu,status';
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('UserRule');
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. // 必须将结果集转换为数组
  24. $ruleList = collection($this->model->order('weigh', 'desc')->select())->toArray();
  25. foreach ($ruleList as $k => &$v) {
  26. $v['title'] = __($v['title']);
  27. $v['remark'] = __($v['remark']);
  28. }
  29. unset($v);
  30. // Tree::instance()->init($ruleList)->icon = ['&nbsp;&nbsp;&nbsp;&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;'];
  31. Tree::instance()->init($ruleList);
  32. $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
  33. $ruledata = [0 => __('None')];
  34. foreach ($this->rulelist as $k => &$v) {
  35. if (!$v['ismenu']) {
  36. continue;
  37. }
  38. $ruledata[$v['id']] = $v['title'];
  39. }
  40. $this->view->assign('ruledata', $ruledata);
  41. }
  42. /**
  43. * 查看
  44. */
  45. public function index()
  46. {
  47. if ($this->request->isAjax()) {
  48. $list = $this->rulelist;
  49. $total = count($this->rulelist);
  50. $result = array("total" => $total, "rows" => $list);
  51. return json($result);
  52. }
  53. return $this->view->fetch();
  54. }
  55. /**
  56. * 添加
  57. */
  58. public function add()
  59. {
  60. if ($this->request->isPost()) {
  61. $this->token();
  62. }
  63. return parent::add();
  64. }
  65. /**
  66. * 编辑
  67. */
  68. public function edit($ids = null)
  69. {
  70. if ($this->request->isPost()) {
  71. $this->token();
  72. }
  73. return parent::edit($ids);
  74. }
  75. /**
  76. * 删除
  77. */
  78. public function del($ids = "")
  79. {
  80. if (!$this->request->isPost()) {
  81. $this->error(__("Invalid parameters"));
  82. }
  83. $ids = $ids ? $ids : $this->request->post("ids");
  84. if ($ids) {
  85. $delIds = [];
  86. foreach (explode(',', $ids) as $k => $v) {
  87. $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true));
  88. }
  89. $delIds = array_unique($delIds);
  90. $count = $this->model->where('id', 'in', $delIds)->delete();
  91. if ($count) {
  92. $this->success();
  93. }
  94. }
  95. $this->error();
  96. }
  97. }