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.
 
 
 
 
 
 

211 lines
8.4 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 "ctrip_hotel_price".
  7. *
  8. * @property integer $id
  9. * @property string $hotel_name
  10. * @property integer $spider_hotel_id
  11. * @property integer $ctrip_hotel_id
  12. * @property string $room_type
  13. * @property string $bed_type
  14. * @property string $breakfast
  15. * @property string $price
  16. * @property string $start_date
  17. * @property string $create_time
  18. * @property string $ctrip_supplier_id
  19. * @property integer $son_room_type_id
  20. * @property string $room_policy
  21. * @property string $confirm_info
  22. * @property string $supply_id
  23. * @property string $showdown_id
  24. * @property string $payment_txt
  25. */
  26. class CtripHotelPrice extends \yii\db\ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return 'ctrip_hotel_price';
  34. }
  35. /**
  36. * @return \yii\db\Connection the database connection used by this AR class.
  37. */
  38. public static function getDb()
  39. {
  40. return Yii::$app->get('db2');
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function rules()
  46. {
  47. return [
  48. [['spider_hotel_id', 'ctrip_hotel_id', 'son_room_type_id'], 'integer'],
  49. [['ctrip_supplier_id', 'son_room_type_id'], 'required'],
  50. [['hotel_name', 'room_policy', 'confirm_info', 'payment_txt'], 'string', 'max' => 255],
  51. [['room_type', 'ctrip_supplier_id', 'supply_id', 'showdown_id'], 'string', 'max' => 100],
  52. [['bed_type', 'breakfast', 'start_date'], 'string', 'max' => 20],
  53. [['price'], 'string', 'max' => 10],
  54. [['create_time'], 'string', 'max' => 50],
  55. ];
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function attributeLabels()
  61. {
  62. return [
  63. 'id' => 'ID',
  64. 'hotel_name' => '酒店全名',
  65. 'spider_hotel_id' => '蜘蛛对应酒店id',
  66. 'ctrip_hotel_id' => '携程酒店id',
  67. 'room_type' => '大房型',
  68. 'bed_type' => '床型',
  69. 'breakfast' => '早餐类型',
  70. 'price' => '价格',
  71. 'start_date' => '入住日期',
  72. 'create_time' => '创建时间',
  73. 'ctrip_supplier_id' => '携程下属渠道号',
  74. 'son_room_type_id' => '子房型id',
  75. 'room_policy' => '政策:是否可取消',
  76. 'confirm_info' => '确认信息',
  77. 'supply_id' => 'tracevalue 里面的supplier_id',
  78. 'showdown_id' => 'tracevalue 里面的showdown__id',
  79. 'payment_txt' => '支付规则',
  80. ];
  81. }
  82. /**
  83. * User:Steven
  84. * Desc:获取携程与与携程有直连关系的酒店
  85. */
  86. public function getDirectHotel()
  87. {
  88. $db = Yii::$app->db;
  89. $sql1 = "SELECT HOTEL_ID,HOTEL_NAME,PRINCIPAL,base_user.user_name,price_compared_hotel.SendMsg FROM opera_hotel INNER JOIN price_compared_hotel ON opera_hotel.HOTEL_ID = price_compared_hotel.HotelId
  90. LEFT JOIN base_user on opera_hotel.PRINCIPAL=base_user.ID and base_user.CANCEL_FLAG=0 AND price_compared_hotel.ChannelId =" . Yii::$app->params['ctrip']['relation_supplier_id'];
  91. $rs = $db->createCommand($sql1)->queryAll();
  92. return $rs;
  93. }
  94. /**
  95. * User:Steven
  96. * Desc:获取用于比价的数据
  97. * @param $HOTEL_ID
  98. * @param string $start_date
  99. * @param string $end_date
  100. * @return array
  101. */
  102. public function getCtripData($HOTEL_ID, $start_date = '', $end_date = '')
  103. {
  104. $db2 = $this->getDb(); //南京数据库
  105. if ($start_date != '' && $end_date != '') {
  106. $sql_str = " and start_date BETWEEN '{$start_date}' and '{$end_date}'";
  107. } else {
  108. $sql_str = " and (1=1) ";
  109. }
  110. $sql2 = "select aa.spider_hotel_id,aa.ctrip_hotel_id,aa.hotel_name,aa.room_type,aa.start_date,aa.bed_type AS a_bed_type,aa.breakfast AS a_breakfast,aa.price AS a_price,aa.room_policy AS a_room_policy,aa.confirm_info AS a_confirm_info,
  111. aa.supply_id AS a_supply_id,aa.showdow_id AS a_showdow_id,aa.room_person as a_room_person,bb.room_person as b_room_person,aa.payment_txt AS a_payment_txt,bb.bed_type AS b_bed_type,bb.breakfast AS b_breakfast,bb.price AS b_price,bb.room_policy AS b_room_policy,
  112. bb.confirm_info AS b_confirm_info,bb.supply_id AS b_supply_id,bb.showdow_id AS b_showdow_id,bb.payment_txt AS b_payment_txt,aa.son_room_type_id as son_room_id
  113. from (SELECT b.* FROM
  114. (SELECT min(CAST(price as SIGNED)) as price,spider_hotel_id,room_type,start_date FROM ctrip_hotel_price WHERE supply_id <> 4297 AND spider_hotel_id = $HOTEL_ID and booking_des<>'订完'
  115. $sql_str GROUP BY spider_hotel_id,room_type,start_date
  116. ) AS a ,ctrip_hotel_price as b where a.spider_hotel_id=b.spider_hotel_id and a.price=b.price and a.room_type=b.room_type and a.start_date=b.start_date
  117. AND b.supply_id <> 4297 and b.booking_des<>'订完'
  118. ORDER BY b.spider_hotel_id,b.room_type,b.start_date,b.bed_type,b.breakfast) as aa
  119. LEFT JOIN
  120. (
  121. SELECT b.* FROM
  122. (SELECT min(CAST(price as SIGNED)) as price,spider_hotel_id,room_type,start_date FROM ctrip_hotel_price WHERE showdow_id = 0
  123. AND supply_id =4297 AND spider_hotel_id = $HOTEL_ID and booking_des<>'订完' $sql_str
  124. GROUP BY spider_hotel_id,room_type,start_date
  125. ) AS a ,ctrip_hotel_price as b where a.spider_hotel_id=b.spider_hotel_id and a.price=b.price and a.room_type=b.room_type and a.start_date=b.start_date and showdow_id = 0
  126. AND b.supply_id = 4297 and b.booking_des<>'订完'
  127. ORDER BY b.spider_hotel_id,b.room_type,b.start_date,b.bed_type,b.breakfast
  128. ) AS bb on aa.spider_hotel_id=bb.spider_hotel_id and aa.room_type=bb.room_type and aa.start_date=bb.start_date order BY aa.spider_hotel_id,aa.room_type,aa.start_date,aa.bed_type";
  129. $result = $db2->createCommand($sql2)->queryAll();
  130. return $result;
  131. }
  132. /**
  133. * 获取酒店的房型要素价格折算
  134. * @param $hotel_id
  135. */
  136. public function getHotelConversion($hotel_id)
  137. {
  138. $db = Yii::$app->db;
  139. $sql = "select remain_room_conversion,breakfast_conversion,cancel_rules_conversion,pay_type_conversion from hotel_price_conversion where hotel_id=$hotel_id";
  140. $rs = $db->createCommand($sql)->queryAll();
  141. return $rs;
  142. }
  143. /**
  144. * User:Steven
  145. * Desc:获取直连的房型的ID
  146. * @param $hotel_id
  147. * @return array
  148. */
  149. public function getRelationRoom($hotel_id)
  150. {
  151. $db = Yii::$app->db;
  152. $sql = "select channel_room_id from price_compared_room where HOTEL_ID=$hotel_id and CANCEL_FLAG=0 and channel_id=".Yii::$app->params['ctrip']['relation_supplier_id'];
  153. // $sql = "SELECT ID,b.ChannelRoomId FROM opera_hotel_room a INNER JOIN channel_room_relation b ON a.ID = b.RoomId WHERE HOTEL_ID = $hotel_id AND CANCEL_FLAG = 0 AND IS_ONSALE = 1";
  154. $rs = $db->createCommand($sql)->queryAll();
  155. return $rs;
  156. }
  157. /**
  158. * User:Steven
  159. * Desc:获取酒店数据的最新一次的更新时间
  160. * @param $HOTEL_ID
  161. * @return array
  162. */
  163. public function getHotelLastUpTime($HOTEL_ID = '')
  164. {
  165. $db2 = $this->getDb(); //南京数据库
  166. if ($HOTEL_ID == '') {
  167. $sql = "select min(create_time) as min_create_time,MAX(create_time) as max_create_time from ctrip_hotel_price";
  168. } else {
  169. $sql = "select create_time as max_create_time from ctrip_hotel_price where spider_hotel_id=$HOTEL_ID ORDER BY create_time desc LIMIT 1";
  170. }
  171. $result = $db2->createCommand($sql)->queryAll();
  172. return $result[0];
  173. }
  174. /**
  175. * 将可用的IP保存到IP池
  176. * @param $ip
  177. */
  178. public function addProxyIp($ip)
  179. {
  180. $db2 = $this->getDb(); //南京数据库
  181. $sql = "INSERT INTO `python`.`proxy_ips` (`ip`,`cancel_flag`, `proxy_level`) VALUES ('{$ip}', '0', '0')";
  182. $db2->createCommand($sql)->execute();
  183. }
  184. /**
  185. *
  186. * 获取可用IP的个数
  187. */
  188. public function getAbleProxyCount()
  189. {
  190. $db2 = $this->getDb(); //南京数据库
  191. $sql = "select count(*) as count from proxy_ips where cancel_flag=0 and proxy_level=0";
  192. $result = $db2->createCommand($sql)->queryAll();
  193. return $result;
  194. }
  195. }