InsurancePersonal.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\Category as CategoryModel;
  5. use fast\Tree;
  6. /**
  7. * 个人保险
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class InsurancePersonal extends Backend
  12. {
  13. /**
  14. * InsurancePersonal模型对象
  15. * @var \app\admin\model\InsurancePersonal
  16. */
  17. protected $model = null;
  18. protected $c_model = null;
  19. protected $categorylist = [];
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\InsurancePersonal;
  24. $this->c_model = model('app\common\model\Category');
  25. $tree = Tree::instance();
  26. $tree->init(collection($this->c_model->order('weigh desc,id desc')->where(['type'=>'gerenxian'])->select())->toArray(), 'pid');
  27. $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
  28. $categorydata = [0 => ['type' => 'test', 'name' => __('None')]];
  29. foreach ($this->categorylist as $k => $v) {
  30. $categorydata[$v['id']] = $v;
  31. }
  32. $typeList = CategoryModel::getTypeList();
  33. $this->view->assign("flagList", $this->c_model->getFlagList());
  34. $this->view->assign("typeList", $typeList);
  35. $this->view->assign("parentList", $categorydata);
  36. }
  37. public function import()
  38. {
  39. parent::import();
  40. }
  41. /**
  42. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  43. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  44. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  45. */
  46. /**
  47. * 查看
  48. */
  49. public function index()
  50. {
  51. //设置过滤方法
  52. $this->request->filter(['strip_tags', 'trim']);
  53. if ($this->request->isAjax()) {
  54. //如果发送的来源是Selectpage,则转发到Selectpage
  55. if ($this->request->request('keyField')) {
  56. return $this->selectpage();
  57. }
  58. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  59. $list = $this->model
  60. ->where($where)
  61. ->order($sort, $order)
  62. ->paginate($limit);
  63. if($list){
  64. foreach ($list as $key=>$value){
  65. $list[$key]['category_name'] = CategoryModel::where(array('id'=>$value['category_id']))->value('name');
  66. }
  67. }
  68. $result = array("total" => $list->total(), "rows" => $list->items());
  69. return json($result);
  70. }
  71. return $this->view->fetch();
  72. }
  73. }