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.
 
 
 
 
 
 

109 lines
3.1 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. /**
  6. * This is the model class for table "price_compared_room".
  7. *
  8. * @property integer $ID
  9. * @property integer $cancel_flag
  10. * @property integer $channel_room_id
  11. * @property integer $hotel_id
  12. * @property integer $channel_id
  13. */
  14. class PriceComparedRoom extends \yii\db\ActiveRecord
  15. {
  16. /**
  17. * @inheritdoc
  18. */
  19. public static function tableName()
  20. {
  21. return 'price_compared_room';
  22. }
  23. /**
  24. * @inheritdoc
  25. */
  26. public function rules()
  27. {
  28. return [
  29. [['cancel_flag', 'channel_room_id', 'room_id', 'channel_id', 'hotel_id'], 'integer'],
  30. [['room_id', 'hotel_id', 'channel_room_id', 'channel_id'], 'required'],
  31. ];
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function attributeLabels()
  37. {
  38. return [
  39. 'ID' => 'ID',
  40. 'cancel_flag' => 'Cancel Flag',
  41. 'channel_room_id' => '渠道房型ID',
  42. 'hotel_id' => '酒店ID',
  43. 'channel_id' => '渠道',
  44. 'room_id' => '房型ID',
  45. ];
  46. }
  47. public function getOperaHotel()
  48. {
  49. return $this->hasOne(OperaHotel::className(), ['HOTEL_ID' => 'hotel_id']);
  50. }
  51. public function getOperaHotelRoom()
  52. {
  53. return $this -> hasOne(OperaHotelRoom::className(), ['ID' => 'room_id']);
  54. }
  55. public function getComparedRoom($filter)
  56. {
  57. $query = PriceComparedRoom::find()
  58. -> joinWith('operaHotelRoom')
  59. -> joinWith('operaHotelRoom.operaHotelBaseRoom')
  60. -> leftJoin('opera_sort as os1', '`opera_hotel_room`.PARENT_ROOM_TYPE = os1.base_room_id AND os1.room_id = 0')
  61. -> leftJoin('opera_sort as os2', '`opera_hotel_room`.ROOM_TYPE = os2.room_id AND os2.room_id != 0 AND `opera_hotel_room`.HOTEL_ID = os2.hotel_id')
  62. -> from('price_compared_room')
  63. -> where(['price_compared_room.hotel_id' => $filter['hotel_id']])
  64. -> orderBy(['os1.seq' => SORT_ASC, 'os2.seq' => SORT_ASC, 'price_compared_room.channel_room_id' => SORT_ASC]);
  65. if($filter['channel_id'] != null)
  66. {
  67. $query->andFilterWhere(['=', 'price_compared_room.channel_room_id', $filter['channel_id']]);
  68. }
  69. if($filter['cancel_flag'] != null && $filter['cancel_flag'] != -1)
  70. {
  71. $query->andFilterWhere(['=', 'price_compared_room.cancel_flag', $filter['cancel_flag']]);
  72. }
  73. if($filter['channel'] != null && $filter['channel'] != -1)
  74. {
  75. $query->andFilterWhere(['=', 'price_compared_room.channel_id', $filter['channel']]);
  76. }
  77. // $res = $query -> createCommand() -> getSql();
  78. $dataProvider = new ActiveDataProvider([
  79. 'query' => $query,
  80. 'pagination' => [
  81. 'pageSize' => 20,
  82. ],
  83. ]);
  84. return $dataProvider;
  85. }
  86. public function beforeSave($insert)
  87. {
  88. if($this -> isNewRecord)
  89. {
  90. $this -> cancel_flag = 0;
  91. }
  92. return parent::beforeSave($insert);
  93. }
  94. }