酒店预订平台
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.
 
 
 
 
 
 

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