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

212 lines
7.3 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,purchase_user_id,plan_memo');
  44. if($keyValue){
  45. $this->model->where(['id'=>$keyValue]);
  46. }elseif($name){
  47. $this->model->where(['plan_name'=>['like','%'.$name.'%']]);
  48. }
  49. $roomId =$this->request->get('room_id');
  50. if ($roomId){
  51. $this->model->where("room_id","=",$roomId);
  52. }
  53. $result= $this->model->select();
  54. if($keyValue){
  55. return json(['list' => $result]);
  56. }
  57. return json(['list' => $result]);
  58. }
  59. /**
  60. * 查看
  61. */
  62. public function index()
  63. {
  64. //设置过滤方法
  65. $this->request->filter(['strip_tags', 'trim']);
  66. if ($this->request->isAjax()) {
  67. //如果发送的来源是Selectpage,则转发到Selectpage
  68. if ($this->request->request('keyField')) {
  69. return $this->selectpage();
  70. }
  71. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  72. $group_id=$this->auth->getGroupId();
  73. $list = $this->model
  74. ->alias("a")
  75. ->join('hbp_admin c','a.create_id = c.id','left')
  76. ->join('hbp_admin d','a.purchase_user_id = d.id','left')
  77. ->join('hbp_cf_room_info e','a.room_id = e.id','left')
  78. ->join('hbp_cf_hotel_info f','a.hotel_id = f.id','left')
  79. ->field("a.*,c.nickname,d.nickname as purchase_user_name,e.room_name,f.hotel_name")
  80. ->where($where);
  81. if ($group_id){
  82. $list = $list
  83. ->where("group_id","=",$group_id)
  84. ->order($sort, $order)
  85. ->paginate($limit);
  86. }else{
  87. $list = $list
  88. ->order($sort, $order)
  89. ->paginate($limit);
  90. }
  91. $result = array("total" => $list->total(), "rows" => $list->items());
  92. return json($result);
  93. }
  94. return $this->view->fetch();
  95. }
  96. /**
  97. * 添加
  98. */
  99. public function add()
  100. {
  101. if ($this->request->isPost()) {
  102. $params = $this->request->post("row/a");
  103. if ($params) {
  104. $params = $this->preExcludeFields($params);
  105. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  106. $params[$this->dataLimitField] = $this->auth->id;
  107. }
  108. $result = false;
  109. Db::startTrans();
  110. try {
  111. //是否采用模型验证
  112. if ($this->modelValidate) {
  113. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  114. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  115. $this->model->validateFailException(true)->validate($validate);
  116. }
  117. $params['create_id']=$this->auth->id;
  118. $params['group_id']=$this->auth->getGroupId();
  119. $result = $this->model->allowField(true)->save($params);
  120. Db::commit();
  121. } catch (ValidateException $e) {
  122. Db::rollback();
  123. $this->error($e->getMessage());
  124. } catch (PDOException $e) {
  125. Db::rollback();
  126. $this->error($e->getMessage());
  127. } catch (Exception $e) {
  128. Db::rollback();
  129. $this->error($e->getMessage());
  130. }
  131. if ($result !== false) {
  132. $this->success();
  133. } else {
  134. $this->error(__('No rows were inserted'));
  135. }
  136. }
  137. $this->error(__('Parameter %s can not be empty', ''));
  138. }
  139. $this->view->assign("continuity_type", $this->continuity_type);
  140. return $this->view->fetch();
  141. }
  142. /**
  143. * 编辑
  144. */
  145. public function edit($ids = null)
  146. {
  147. $row = $this->model->get($ids);
  148. if (!$row) {
  149. $this->error(__('No Results were found'));
  150. }
  151. $adminIds = $this->getDataLimitAdminIds();
  152. if (is_array($adminIds)) {
  153. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  154. $this->error(__('You have no permission'));
  155. }
  156. }
  157. if ($this->request->isPost()) {
  158. $params = $this->request->post("row/a");
  159. if ($params) {
  160. $params = $this->preExcludeFields($params);
  161. $result = false;
  162. Db::startTrans();
  163. try {
  164. //是否采用模型验证
  165. if ($this->modelValidate) {
  166. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  167. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  168. $row->validateFailException(true)->validate($validate);
  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("continuity_type", $this->continuity_type);
  191. $this->view->assign("row", $row);
  192. return $this->view->fetch();
  193. }
  194. }