酒店预订平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

145 linhas
5.0 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\dao\GroupDao;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. use think\Exception;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 供应商配置
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class CfSuplierInfo extends Backend
  15. {
  16. protected $noNeedRight = ['getList'];
  17. /**
  18. * CfSuplierInfo模型对象
  19. * @var \app\admin\model\CfSuplierInfo
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\CfSuplierInfo;
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. /**
  37. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  38. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  39. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  40. */
  41. /**
  42. * 添加
  43. */
  44. public function add()
  45. {
  46. if ($this->request->isPost()) {
  47. $params = $this->request->post("row/a");
  48. if ($params) {
  49. $params = $this->preExcludeFields($params);
  50. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  51. $params[$this->dataLimitField] = $this->auth->id;
  52. }
  53. $result = false;
  54. Db::startTrans();
  55. try {
  56. //是否采用模型验证
  57. if ($this->modelValidate) {
  58. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  59. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  60. $this->model->validateFailException(true)->validate($validate);
  61. }
  62. $params['create_id']=$this->auth->id;
  63. $groupDao = new GroupDao();
  64. $params['group_id'] = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  65. $result = $this->model->allowField(true)->save($params);
  66. Db::commit();
  67. } catch (ValidateException $e) {
  68. Db::rollback();
  69. $this->error($e->getMessage());
  70. } catch (PDOException $e) {
  71. Db::rollback();
  72. $this->error($e->getMessage());
  73. } catch (Exception $e) {
  74. Db::rollback();
  75. $this->error($e->getMessage());
  76. }
  77. if ($result !== false) {
  78. $this->success();
  79. } else {
  80. $this->error(__('No rows were inserted'));
  81. }
  82. }
  83. $this->error(__('Parameter %s can not be empty', ''));
  84. }
  85. return $this->view->fetch();
  86. }
  87. /**
  88. * 查看
  89. */
  90. public function index()
  91. {
  92. //设置过滤方法
  93. $this->request->filter(['strip_tags', 'trim']);
  94. if ($this->request->isAjax()) {
  95. //如果发送的来源是Selectpage,则转发到Selectpage
  96. if ($this->request->request('keyField')) {
  97. return $this->selectpage();
  98. }
  99. $groupDao = new GroupDao();
  100. $group_id = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  101. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  102. $list = $this->model
  103. ->where($where)
  104. ->where("group_id",'=',$group_id)
  105. ->order($sort, $order)
  106. ->paginate($limit);
  107. $result = array("total" => $list->total(), "rows" => $list->items());
  108. return json($result);
  109. }
  110. return $this->view->fetch();
  111. }
  112. public function getList(){
  113. $name=$this->request->post('name');
  114. $keyValue=$this->request->post('keyValue');
  115. $this->model->field('id,supplier_name as name');
  116. $groupDao = new GroupDao();
  117. $group_id = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  118. $where = ["group_id"=>$group_id];
  119. if($keyValue){
  120. $where = ['id'=>$keyValue,"group_id"=>$group_id];
  121. }elseif($name){
  122. $where = ['supplier_name'=>['like','%'.$name.'%'],"group_id"=>$group_id];
  123. }
  124. $result= $this->model->where($where)->select();
  125. if($keyValue){
  126. return json(['list' => $result]);
  127. }
  128. return json(['list' => $result]);
  129. }
  130. }