酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

205 rivejä
7.0 KiB

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\dao\GroupDao;
  4. use app\admin\model\Area;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 配置-酒店房型
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class CfRoomInfo extends Backend
  15. {
  16. protected $noNeedRight = ['getRoomList',"getList"];
  17. /**
  18. * CfRoomInfo模型对象
  19. * @var \app\admin\model\CfRoomInfo
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\CfRoomInfo;
  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. * 查看
  38. */
  39. public function index()
  40. {
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $group_id=$this->auth->getGroupIds()[0];
  50. $groupDao = new GroupDao();
  51. $group_id = $groupDao->getTopGroup($group_id);
  52. $list = $this->model
  53. ->alias('a')
  54. ->join('hbp_cf_hotel_info b','a.hotel_id = b.id','left')
  55. ->join('hbp_admin c','a.create_id = c.id','left')
  56. ->field("a.id,a.hotel_id,a.room_name,a.room_memo,b.hotel_name,a.create_time,a.update_time,c.nickname")
  57. ->where($where);
  58. $list = $list
  59. ->where("a.group_id","=",$group_id)
  60. ->order($sort, $order)
  61. ->paginate($limit);
  62. $result = array("total" => $list->total(), "rows" => $list->items());
  63. return json($result);
  64. }
  65. return $this->view->fetch();
  66. }
  67. /**
  68. * 添加
  69. */
  70. public function add()
  71. {
  72. if ($this->request->isPost()) {
  73. $params = $this->request->post("row/a");
  74. if ($params) {
  75. $params = $this->preExcludeFields($params);
  76. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  77. $params[$this->dataLimitField] = $this->auth->id;
  78. }
  79. $result = false;
  80. Db::startTrans();
  81. try {
  82. //是否采用模型验证
  83. if ($this->modelValidate) {
  84. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  85. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  86. $this->model->validateFailException(true)->validate($validate);
  87. }
  88. $params['create_id']=$this->auth->id;
  89. $groupDao = new GroupDao();
  90. $params['group_id'] = $groupDao->getTopGroup($this->auth->getGroupIds()[0]);
  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. public function getRoomList(){
  165. $hotelId=$this->request->get('hotelId');
  166. $result= $this->model
  167. ->field("id,room_name as name,room_memo")
  168. ->where(["hotel_id"=>$hotelId,"del_flag"=>0])->select();
  169. return json(['list' => $result]);
  170. }
  171. public function getList(){
  172. $name=$this->request->post('name');
  173. $keyValue=$this->request->post('keyValue');
  174. $this->model->field('id,room_name as name');
  175. if($keyValue){
  176. $this->model->where(['id'=>$keyValue]);
  177. }elseif($name){
  178. $this->model->where(['room_name'=>['like','%'.$name.'%']]);
  179. }
  180. $result= $this->model->select();
  181. if($keyValue){
  182. return json(['list' => $result]);
  183. }
  184. return json(['list' => $result]);
  185. }
  186. }