酒店预订平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CfRoomPlan.php 7.5 KiB

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