|
- <?php
-
- namespace backend\modules\hotel\models;
-
- use Yii;
- use yii\data\ActiveDataProvider;
-
- /**
- * This is the model class for table "ctrip_hotel_price".
- *
- * @property integer $id
- * @property string $hotel_name
- * @property integer $spider_hotel_id
- * @property integer $ctrip_hotel_id
- * @property string $room_type
- * @property string $bed_type
- * @property string $breakfast
- * @property string $price
- * @property string $start_date
- * @property string $create_time
- * @property string $ctrip_supplier_id
- * @property integer $son_room_type_id
- * @property string $room_policy
- * @property string $confirm_info
- * @property string $supply_id
- * @property string $showdown_id
- * @property string $payment_txt
- */
- class CtripHotelPrice extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'ctrip_hotel_price';
- }
-
- /**
- * @return \yii\db\Connection the database connection used by this AR class.
- */
- public static function getDb()
- {
- return Yii::$app->get('db2');
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['spider_hotel_id', 'ctrip_hotel_id', 'son_room_type_id'], 'integer'],
- [['ctrip_supplier_id', 'son_room_type_id'], 'required'],
- [['hotel_name', 'room_policy', 'confirm_info', 'payment_txt'], 'string', 'max' => 255],
- [['room_type', 'ctrip_supplier_id', 'supply_id', 'showdown_id'], 'string', 'max' => 100],
- [['bed_type', 'breakfast', 'start_date'], 'string', 'max' => 20],
- [['price'], 'string', 'max' => 10],
- [['create_time'], 'string', 'max' => 50],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'hotel_name' => '酒店全名',
- 'spider_hotel_id' => '蜘蛛对应酒店id',
- 'ctrip_hotel_id' => '携程酒店id',
- 'room_type' => '大房型',
- 'bed_type' => '床型',
- 'breakfast' => '早餐类型',
- 'price' => '价格',
- 'start_date' => '入住日期',
- 'create_time' => '创建时间',
- 'ctrip_supplier_id' => '携程下属渠道号',
- 'son_room_type_id' => '子房型id',
- 'room_policy' => '政策:是否可取消',
- 'confirm_info' => '确认信息',
- 'supply_id' => 'tracevalue 里面的supplier_id',
- 'showdown_id' => 'tracevalue 里面的showdown__id',
- 'payment_txt' => '支付规则',
- ];
- }
-
- /**
- * User:Steven
- * Desc:获取携程与与携程有直连关系的酒店
- */
- public function getDirectHotel()
- {
- $db = Yii::$app->db;
- $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
- 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'];
- $rs = $db->createCommand($sql1)->queryAll();
- return $rs;
- }
-
- /**
- * User:Steven
- * Desc:获取用于比价的数据
- * @param $HOTEL_ID
- * @param string $start_date
- * @param string $end_date
- * @return array
- */
- public function getCtripData($HOTEL_ID, $start_date = '', $end_date = '')
- {
- $db2 = $this->getDb(); //南京数据库
- if ($start_date != '' && $end_date != '') {
- $sql_str = " and start_date BETWEEN '{$start_date}' and '{$end_date}'";
- } else {
- $sql_str = " and (1=1) ";
- }
- $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,
- 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,
- 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
- from (SELECT b.* FROM
- (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<>'订完'
- $sql_str GROUP BY spider_hotel_id,room_type,start_date
- ) 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 b.supply_id <> 4297 and b.booking_des<>'订完'
- ORDER BY b.spider_hotel_id,b.room_type,b.start_date,b.bed_type,b.breakfast) as aa
- LEFT JOIN
- (
- SELECT b.* FROM
- (SELECT min(CAST(price as SIGNED)) as price,spider_hotel_id,room_type,start_date FROM ctrip_hotel_price WHERE showdow_id = 0
- AND supply_id =4297 AND spider_hotel_id = $HOTEL_ID and booking_des<>'订完' $sql_str
- GROUP BY spider_hotel_id,room_type,start_date
- ) 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
- AND b.supply_id = 4297 and b.booking_des<>'订完'
- ORDER BY b.spider_hotel_id,b.room_type,b.start_date,b.bed_type,b.breakfast
- ) 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";
- $result = $db2->createCommand($sql2)->queryAll();
- return $result;
- }
-
-
- /**
- * 获取酒店的房型要素价格折算
- * @param $hotel_id
- */
- public function getHotelConversion($hotel_id)
- {
- $db = Yii::$app->db;
- $sql = "select remain_room_conversion,breakfast_conversion,cancel_rules_conversion,pay_type_conversion from hotel_price_conversion where hotel_id=$hotel_id";
- $rs = $db->createCommand($sql)->queryAll();
- return $rs;
- }
-
- /**
- * User:Steven
- * Desc:获取直连的房型的ID
- * @param $hotel_id
- * @return array
- */
- public function getRelationRoom($hotel_id)
- {
- $db = Yii::$app->db;
- $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'];
- // $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";
- $rs = $db->createCommand($sql)->queryAll();
- return $rs;
- }
-
- /**
- * User:Steven
- * Desc:获取酒店数据的最新一次的更新时间
- * @param $HOTEL_ID
- * @return array
- */
- public function getHotelLastUpTime($HOTEL_ID = '')
- {
- $db2 = $this->getDb(); //南京数据库
- if ($HOTEL_ID == '') {
- $sql = "select min(create_time) as min_create_time,MAX(create_time) as max_create_time from ctrip_hotel_price";
- } else {
- $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";
- }
- $result = $db2->createCommand($sql)->queryAll();
- return $result[0];
- }
-
- /**
- * 将可用的IP保存到IP池
- * @param $ip
- */
- public function addProxyIp($ip)
- {
- $db2 = $this->getDb(); //南京数据库
- $sql = "INSERT INTO `python`.`proxy_ips` (`ip`,`cancel_flag`, `proxy_level`) VALUES ('{$ip}', '0', '0')";
- $db2->createCommand($sql)->execute();
- }
-
-
- /**
- *
- * 获取可用IP的个数
- */
- public function getAbleProxyCount()
- {
- $db2 = $this->getDb(); //南京数据库
- $sql = "select count(*) as count from proxy_ips where cancel_flag=0 and proxy_level=0";
- $result = $db2->createCommand($sql)->queryAll();
- return $result;
- }
- }
|