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.
 
 
 
 
 
 

215 line
6.7 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%opera_hotel_base_room}}".
  6. *
  7. * @property integer $MAIN_ID
  8. * @property string $CREATE_TIME
  9. * @property integer $CREATE_USER_ID
  10. * @property string $UPDATE_TIME
  11. * @property integer $CANCEL_FLAG
  12. * @property integer $HOTEL_ID
  13. * @property integer $BASE_ROOM_TYPE
  14. * @property string $BASE_ROOM_NAME
  15. * @property string $BED_TYPE
  16. * @property integer $CURRENCY_CODE
  17. * @property double $AREA_SIZE
  18. */
  19. class OperaHotelBaseRoom extends \yii\db\ActiveRecord
  20. {
  21. public $checked;
  22. // 酒店房型图片宽度
  23. const ROOM_PIC_WIDTH = 160;
  24. // 酒店房型图片高度
  25. const ROOM_PIC_HEIGHT = 130;
  26. // 币种数组
  27. const CURRENCY_CODE = array('1' => '人民币');
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%opera_hotel_base_room}}';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['CREATE_USER_ID', 'CANCEL_FLAG', 'HOTEL_ID', 'BASE_ROOM_TYPE', 'CURRENCY_CODE'], 'integer'],
  42. [['CREATE_TIME', 'UPDATE_TIME', 'BASE_ROOM_NAME', 'BED_TYPE', 'AREA_SIZE'], 'string', 'max' => 50],
  43. [['BASE_ROOM_NAME'], 'required'],
  44. [['BED_TYPE'], 'required', 'on' => 'set_bed_type', 'message' => '床型不能为空'],
  45. [['CURRENCY_CODE'], 'required', 'on' => 'set_bed_type', 'message' => '币种不能为空'],
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'MAIN_ID' => '基础房型ID',
  55. 'CREATE_TIME' => 'Create Time',
  56. 'CREATE_USER_ID' => 'Create User ID',
  57. 'UPDATE_TIME' => 'Update Time',
  58. 'CANCEL_FLAG' => 'Cancel Flag',
  59. 'HOTEL_ID' => '酒店ID',
  60. 'BASE_ROOM_TYPE' => '基础房型ID(历史数据)',
  61. 'BASE_ROOM_NAME' => '基础房型名称',
  62. 'BED_TYPE' => '床型',
  63. 'CURRENCY_CODE' => '币种',
  64. 'AREA_SIZE' => '房型面积',
  65. 'ROOM_IMG' => '基础房型图片',
  66. ];
  67. }
  68. //新增基本房型
  69. public function AddBaseroom($name, $user_id, $hotel_id)
  70. {
  71. $hotel_id = isset($hotel_id) ? $hotel_id : 0;
  72. $sql = "insert into opera_hotel_base_room (hotel_id,base_room_type,base_room_name,create_user_id,create_time,update_time) VALUES ('$hotel_id',0,'$name','$user_id',now(),now())";
  73. writeLog(__FUNCTION__ . " sql= " . $sql);
  74. $res = $this->DBTool->execSql($sql);
  75. return $res;
  76. }
  77. /**
  78. * 根据酒店查询出基础房型和可售房型,然后处理判断
  79. *
  80. */
  81. public function getBaseRoomAll($hotel_id)
  82. {
  83. $res = OperaHotel::findOne(['HOTEL_ID' => $hotel_id]);
  84. $hotel_type_all = explode(',', $res['ROOM_TYPE_ALL']);
  85. // $hotel_type_sale = explode(',', $res['ROOM_TYPE_SALE']);
  86. $rs = OperaHotelBaseRoom::find()
  87. ->select(['MAIN_ID', 'BED_TYPE', 'CURRENCY_CODE', 'BASE_ROOM_NAME', 'case when MAIN_ID in (' . $res['ROOM_TYPE_SALE'] . ') then 1 else 0 end as checked'])
  88. ->where(['CANCEL_FLAG' => 0, 'MAIN_ID' => $hotel_type_all])
  89. // -> asArray()
  90. ->all();
  91. return $rs;
  92. }
  93. public function getBedType($base_room)
  94. {
  95. $rs = OperaHotelBaseRoom::find()
  96. ->select(['MAIN_ID', 'BED_TYPE', 'CURRENCY_CODE', 'BASE_ROOM_NAME', 'case when BED_TYPE in (1,2,10) then 1 else 0 end as checked'])
  97. ->where(['CANCEL_FLAG' => 0, 'MAIN_ID' => $base_room])
  98. // -> asArray()
  99. ->all();
  100. return $rs;
  101. }
  102. //根据基本房型名称查询res_id
  103. public function getUpId($name, $hotel_id)
  104. {
  105. $sql = "select main_id as res_id from opera_hotel_base_room where base_room_name ='$name' and cancel_flag = 0 and hotel_id = '$hotel_id'";
  106. writeLog(__FUNCTION__ . " sql= " . $sql);
  107. $res = $this->DBTool->queryBySql($sql);
  108. return $res;
  109. }
  110. // 根据hotelid查询该酒店所有的基础房型
  111. public function getHotelBaseRoom($hotel)
  112. {
  113. $res = OperaHotelBaseRoom::find()
  114. ->where(['HOTEL_ID' => $hotel, 'CANCEL_FLAG' => 0])->all();
  115. // -> asArray() -> all();
  116. return $res;
  117. }
  118. // 根据hotelid查询该酒店所有的基础房型
  119. public function getHotelBaseRoomForSelect($hotel, $channel_id)
  120. {
  121. $where = [
  122. 'and',
  123. ['=', 'a.HOTEL_ID', $hotel],
  124. ['=', 'a.CANCEL_FLAG', 0],
  125. ['is', 'b.base_room_id', null]
  126. ];
  127. $res = self::find()
  128. ->from(self::tableName() . ' a')
  129. ->leftJoin(ChannelBaseRoomMapping::tableName() . ' b', 'a.MAIN_ID = b.base_room_id and b.channel_id = ' . $channel_id)
  130. ->where($where)
  131. ->all();
  132. return $res;
  133. }
  134. /**
  135. * @Author wanglg
  136. * @Desc 生成不重复的文件名称
  137. * @param $path 文件路径
  138. * @param $suffix 文件后缀
  139. * @return string
  140. */
  141. public static function getImgName($path, $suffix)
  142. {
  143. $flag = true;
  144. $str = 'abcdefghijkmnpqrstwxyzABCDEFGHIJKMNPQRSTWXYZ23456789';
  145. while ($flag) {
  146. $name = str_shuffle(substr(str_shuffle($str), 0, 10) . time() . rand(10000, 999999));
  147. if (!file_exists("$path$name$suffix")) {
  148. $flag = false;
  149. }
  150. }
  151. return $name . $suffix;
  152. }
  153. public function beforeSave($insert)
  154. {
  155. if ($this->isNewRecord) {
  156. $this->CREATE_TIME = date('Y-m-d H:i:s');
  157. $this->CREATE_USER_ID = Yii::$app->user->id;
  158. } else {
  159. $this->UPDATE_TIME = date('Y-m-d H:i:s');
  160. }
  161. return parent::beforeSave($insert);
  162. }
  163. /**
  164. * Des:获取cs基础房型数据
  165. * Name: getRoomInfo
  166. * @param $roomId
  167. * @param $channel_id
  168. * @return array
  169. * @author 倪宗锋
  170. */
  171. public function getRoomInfo($roomId, $channel_id)
  172. {
  173. $select = [
  174. 'a.MAIN_ID',
  175. 'a.BASE_ROOM_NAME',
  176. 'a.HOTEL_ID',
  177. 'b.sub_base_room_id',
  178. 'c.sub_hotel_id'
  179. ];
  180. $where = [
  181. 'and',
  182. ['=', 'a.CANCEL_FLAG', 0],
  183. ['=', 'a.MAIN_ID', $roomId]
  184. ];
  185. $getInfo = self::find()->select($select)
  186. ->from(self::tableName() . ' a')
  187. ->leftJoin(ChannelBaseRoomMapping::tableName() . ' b', 'a.MAIN_ID = b.base_room_id and b.channel_id = ' . $channel_id)
  188. ->leftJoin(ChannelHotelMapping::tableName() . ' c', 'a.HOTEL_ID = c.hotel_id and c.channel_id = ' . $channel_id)
  189. ->where($where)
  190. ->asArray()
  191. ->one();
  192. return $getInfo;
  193. }
  194. }