Rule.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * UserRule模型对象
  14. */
  15. protected $model = null;
  16. protected $rulelist = [];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('UserRule');
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. // 必须将结果集转换为数组
  23. $ruleList = collection($this->model->order('weigh', 'desc')->select())->toArray();
  24. foreach ($ruleList as $k => &$v)
  25. {
  26. $v['title'] = __($v['title']);
  27. $v['remark'] = __($v['remark']);
  28. }
  29. unset($v);
  30. Tree::instance()->init($ruleList);
  31. $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
  32. $ruledata = [0 => __('None')];
  33. foreach ($this->rulelist as $k => &$v)
  34. {
  35. if (!$v['ismenu'])
  36. continue;
  37. $ruledata[$v['id']] = $v['title'];
  38. }
  39. $this->view->assign('ruledata', $ruledata);
  40. }
  41. /**
  42. * 查看
  43. */
  44. public function index()
  45. {
  46. if ($this->request->isAjax())
  47. {
  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 del($ids = "")
  59. {
  60. if ($ids)
  61. {
  62. $delIds = [];
  63. foreach (explode(',', $ids) as $k => $v)
  64. {
  65. $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, TRUE));
  66. }
  67. $delIds = array_unique($delIds);
  68. $count = $this->model->where('id', 'in', $delIds)->delete();
  69. if ($count)
  70. {
  71. $this->success();
  72. }
  73. }
  74. $this->error();
  75. }
  76. }