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.

Addhotel.php 2.2 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: gaoh
  5. * Date: 2016/11/2
  6. * Time: 13:18
  7. */
  8. require_once "Api/ApiBase.php";
  9. require_once "Lib/Action/AddhotelModel.php";
  10. class Addhotel extends ApiBase
  11. {
  12. //新增酒店信息
  13. public function AddHotelfunc()
  14. {
  15. //取值
  16. $hotel_name = $_REQUEST['hotel_name'];
  17. $area_id = $_REQUEST['area_id'];
  18. $address = $_REQUEST['address'];
  19. $star_level=isset($_REQUEST['star_level'])?$_REQUEST['star_level']:'0';
  20. //为了遍历 基础房型以数组形式接收
  21. is_array($base_room_type = $_REQUEST['base_room_type']) ? null : $base_room_type = array();
  22. $AddM = new AddhotelModel();
  23. $room_type = '';
  24. //用户ID,采购人暂时设为默认
  25. $user_id = $this->login_user_id;
  26. $purchase_name = 0;
  27. //遍历基本房型数组,数据库存在则取出ID,不存在新增并拿到ID,返回ID字符串
  28. foreach ($base_room_type as $v) {
  29. //根据基本房型名称查询res_id
  30. $res = $AddM->getId($v);
  31. //如果为空
  32. if ($res['code']==0 & $res['rowset'] == null) {
  33. //新增基本房型
  34. $obj = $AddM->AddBaseroom($v, $user_id, $area_id);
  35. // //再得到res_id 用逗号连接
  36. $res = $AddM->getId($v);
  37. $room_type .= $res['rowset']['0']['res_id'] . ',';
  38. //如果不为空 直接得到res_id
  39. } else {
  40. $room_type .= $res['rowset']['0']['res_id'] . ',';
  41. }
  42. }
  43. //消除末尾的逗号
  44. $room_type_all = trim($room_type, ',');
  45. //新增酒店信息 返回数据
  46. $data = $AddM->AddHotel($hotel_name, $area_id, $address, $room_type_all, $purchase_name,$user_id,$star_level);
  47. if ($data['code']==0){
  48. $data['info']='添加成功';
  49. }else{
  50. $data['info']='酒店名称已存在';
  51. }
  52. $data['hotel_name'] = $hotel_name;
  53. $data['area_id'] = $area_id;
  54. $data['address'] = $address;
  55. $data['room_type_all'] = $room_type_all;
  56. return $data;
  57. }
  58. }
  59. $a = new Addhotel();
  60. $res = $a->AddHotelfunc();
  61. echo json_encode($res);