Rule.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. {
  27. $v['title'] = __($v['title']);
  28. $v['remark'] = __($v['remark']);
  29. }
  30. unset($v);
  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. {
  36. if (!$v['ismenu'])
  37. continue;
  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. {
  49. $list = $this->rulelist;
  50. $total = count($this->rulelist);
  51. $result = array("total" => $total, "rows" => $list);
  52. return json($result);
  53. }
  54. return $this->view->fetch();
  55. }
  56. /**
  57. * 删除
  58. */
  59. public function del($ids = "")
  60. {
  61. if ($ids)
  62. {
  63. $delIds = [];
  64. foreach (explode(',', $ids) as $k => $v)
  65. {
  66. $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, TRUE));
  67. }
  68. $delIds = array_unique($delIds);
  69. $count = $this->model->where('id', 'in', $delIds)->delete();
  70. if ($count)
  71. {
  72. $this->success();
  73. }
  74. }
  75. $this->error();
  76. }
  77. }