酒店预订平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

216 linhas
7.5 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,"del_flag"=>0]);
  46. }elseif($name){
  47. $this->model->where(['plan_name'=>['like','%'.$name.'%'],"del_flag"=>0]);
  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','a.purchase_user_id = hbp_admin.id','left')
  76. ->join('hbp_cf_room_info e','a.room_id = e.id','left')
  77. ->join('hbp_cf_hotel_info f','a.hotel_id = f.id','left')
  78. ->field("a.*,hbp_admin.nickname,e.room_name,f.hotel_name")
  79. ->where($where);
  80. if ($group_id){
  81. $list = $list
  82. ->where("group_id","=",$group_id)
  83. ->order($sort, $order)
  84. ->paginate($limit);
  85. }else{
  86. $list = $list
  87. ->order($sort, $order)
  88. ->paginate($limit);
  89. }
  90. $result = $list->items();
  91. foreach ($result as $k=>$item){
  92. $result[$k]["continuity_type"]=$this->continuity_type[$item["continuity_type"]];
  93. $result[$k]["hbp_admin.nickname"] = $item["nickname"];
  94. }
  95. $result = array("total" => $list->total(), "rows" => $result);
  96. return json($result);
  97. }
  98. return $this->view->fetch();
  99. }
  100. /**
  101. * 添加
  102. */
  103. public function add()
  104. {
  105. if ($this->request->isPost()) {
  106. $params = $this->request->post("row/a");
  107. if ($params) {
  108. $params = $this->preExcludeFields($params);
  109. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  110. $params[$this->dataLimitField] = $this->auth->id;
  111. }
  112. $result = false;
  113. Db::startTrans();
  114. try {
  115. //是否采用模型验证
  116. if ($this->modelValidate) {
  117. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  118. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  119. $this->model->validateFailException(true)->validate($validate);
  120. }
  121. $params['create_id']=$this->auth->id;
  122. $params['group_id']=$this->auth->getGroupId();
  123. $result = $this->model->allowField(true)->save($params);
  124. Db::commit();
  125. } catch (ValidateException $e) {
  126. Db::rollback();
  127. $this->error($e->getMessage());
  128. } catch (PDOException $e) {
  129. Db::rollback();
  130. $this->error($e->getMessage());
  131. } catch (Exception $e) {
  132. Db::rollback();
  133. $this->error($e->getMessage());
  134. }
  135. if ($result !== false) {
  136. $this->success();
  137. } else {
  138. $this->error(__('No rows were inserted'));
  139. }
  140. }
  141. $this->error(__('Parameter %s can not be empty', ''));
  142. }
  143. $this->view->assign("continuity_type", $this->continuity_type);
  144. return $this->view->fetch();
  145. }
  146. /**
  147. * 编辑
  148. */
  149. public function edit($ids = null)
  150. {
  151. $row = $this->model->get($ids);
  152. if (!$row) {
  153. $this->error(__('No Results were found'));
  154. }
  155. $adminIds = $this->getDataLimitAdminIds();
  156. if (is_array($adminIds)) {
  157. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  158. $this->error(__('You have no permission'));
  159. }
  160. }
  161. if ($this->request->isPost()) {
  162. $params = $this->request->post("row/a");
  163. if ($params) {
  164. $params = $this->preExcludeFields($params);
  165. $result = false;
  166. Db::startTrans();
  167. try {
  168. //是否采用模型验证
  169. if ($this->modelValidate) {
  170. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  171. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  172. $row->validateFailException(true)->validate($validate);
  173. }
  174. $result = $row->allowField(true)->save($params);
  175. Db::commit();
  176. } catch (ValidateException $e) {
  177. Db::rollback();
  178. $this->error($e->getMessage());
  179. } catch (PDOException $e) {
  180. Db::rollback();
  181. $this->error($e->getMessage());
  182. } catch (Exception $e) {
  183. Db::rollback();
  184. $this->error($e->getMessage());
  185. }
  186. if ($result !== false) {
  187. $this->success();
  188. } else {
  189. $this->error(__('No rows were updated'));
  190. }
  191. }
  192. $this->error(__('Parameter %s can not be empty', ''));
  193. }
  194. $this->view->assign("continuity_type", $this->continuity_type);
  195. $this->view->assign("row", $row);
  196. return $this->view->fetch();
  197. }
  198. }