酒店预订平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

210 рядки
7.4 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 CfHotelInfo extends Backend
  14. {
  15. /**
  16. * CfHotelInfo模型对象
  17. * @var \app\admin\model\CfHotelInfo
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\CfHotelInfo;
  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_admin c','a.create_id = c.id','left')
  51. ->field("a.*,c.nickname")
  52. ->where($where);
  53. if ($group_id){
  54. $list = $list
  55. ->where("group_id","=",$group_id)
  56. ->order($sort, $order)
  57. ->paginate($limit);
  58. }else{
  59. $list = $list
  60. ->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. public function getHotelList(){
  69. $name=$this->request->post('name');
  70. $keyValue=$this->request->post('keyValue');
  71. $result= $this->model->getList($name,$keyValue);
  72. if($keyValue){
  73. return json(['list' => $result]);
  74. }
  75. return json(['list' => $result]);
  76. }
  77. /**
  78. * 添加
  79. */
  80. public function add()
  81. {
  82. if ($this->request->isPost()) {
  83. $params = $this->request->post("row/a");
  84. if ($params) {
  85. $params = $this->preExcludeFields($params);
  86. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  87. $params[$this->dataLimitField] = $this->auth->id;
  88. }
  89. $result = false;
  90. Db::startTrans();
  91. try {
  92. //是否采用模型验证
  93. if ($this->modelValidate) {
  94. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  95. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  96. $this->model->validateFailException(true)->validate($validate);
  97. }
  98. $area=new Area();
  99. if ($params["area"]){
  100. $params["area_name"]=$area->where("id","=",$params["area"])->value("name");
  101. }
  102. if ($params["province"]){
  103. $params["province_name"]=$area->where("id","=",$params["province"])->value("name");
  104. }
  105. if ($params["city"]){
  106. $params["city_name"]=$area->where("id","=",$params["city"])->value("name");
  107. }
  108. $params['create_id']=$this->auth->id;
  109. $params['group_id']=$this->auth->getGroupId();
  110. $result = $this->model->allowField(true)->save($params);
  111. Db::commit();
  112. } catch (ValidateException $e) {
  113. Db::rollback();
  114. $this->error($e->getMessage());
  115. } catch (PDOException $e) {
  116. Db::rollback();
  117. $this->error($e->getMessage());
  118. } catch (Exception $e) {
  119. Db::rollback();
  120. $this->error($e->getMessage());
  121. }
  122. if ($result !== false) {
  123. $this->success();
  124. } else {
  125. $this->error(__('No rows were inserted'));
  126. }
  127. }
  128. $this->error(__('Parameter %s can not be empty', ''));
  129. }
  130. return $this->view->fetch();
  131. }
  132. /**
  133. * 编辑
  134. */
  135. public function edit($ids = null)
  136. {
  137. $row = $this->model->get($ids);
  138. if (!$row) {
  139. $this->error(__('No Results were found'));
  140. }
  141. $adminIds = $this->getDataLimitAdminIds();
  142. if (is_array($adminIds)) {
  143. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  144. $this->error(__('You have no permission'));
  145. }
  146. }
  147. if ($this->request->isPost()) {
  148. $params = $this->request->post("row/a");
  149. if ($params) {
  150. $params = $this->preExcludeFields($params);
  151. $result = false;
  152. Db::startTrans();
  153. try {
  154. //是否采用模型验证
  155. if ($this->modelValidate) {
  156. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  157. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  158. $row->validateFailException(true)->validate($validate);
  159. }
  160. $area=new Area();
  161. if ($params["area"]){
  162. $params["area_name"]=$area->where("id","=",$params["area"])->value("name");
  163. }
  164. if ($params["province"]){
  165. $params["province_name"]=$area->where("id","=",$params["province"])->value("name");
  166. }
  167. if ($params["city"]){
  168. $params["city_name"]=$area->where("id","=",$params["city"])->value("name");
  169. }
  170. $result = $row->allowField(true)->save($params);
  171. Db::commit();
  172. } catch (ValidateException $e) {
  173. Db::rollback();
  174. $this->error($e->getMessage());
  175. } catch (PDOException $e) {
  176. Db::rollback();
  177. $this->error($e->getMessage());
  178. } catch (Exception $e) {
  179. Db::rollback();
  180. $this->error($e->getMessage());
  181. }
  182. if ($result !== false) {
  183. $this->success();
  184. } else {
  185. $this->error(__('No rows were updated'));
  186. }
  187. }
  188. $this->error(__('Parameter %s can not be empty', ''));
  189. }
  190. $this->view->assign("row", $row);
  191. return $this->view->fetch();
  192. }
  193. }