酒店预订平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

181 行
6.1 KiB

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