|
- <?php
-
- namespace backend\modules\api\models;
-
- use backend\modules\hotel\models\OperaRoomDistrib;
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "run_hotel_distrib".
- *
- * @property integer $ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $DISTRIB_ID
- * @property integer $HOTEL_ID
- * @property integer $BASE_ROOM_TYPE
- * @property integer $ROOM_TYPE
- * @property string $RUN_DATE
- * @property integer $REMAINING_COUNT
- * @property integer $SALED_COUNT
- * @property string $PROD_PRICE
- * @property string $CUS_PRICE
- * @property integer $RUN_STATUS
- * @property integer $OVERSELL_FLAG
- * @property string $CONSUME_STOCK_TYPE
- * @property integer $AUTHORITY_STATUS
- */
- class RunHotelDistrib extends ActiveRecord
- {
- const AUTHORITY_STATUS_ON = 1; //渠道授权 开
- const AUTHORITY_STATUS_DOWN = 0; //渠道授权 关
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'run_hotel_distrib';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'DISTRIB_ID', 'HOTEL_ID', 'BASE_ROOM_TYPE', 'ROOM_TYPE', 'REMAINING_COUNT', 'SALED_COUNT', 'RUN_STATUS', 'OVERSELL_FLAG', 'AUTHORITY_STATUS'], 'integer'],
- [['CREATE_TIME'], 'required'],
- [['UPDATE_TIME'], 'safe'],
- [['PROD_PRICE', 'CUS_PRICE'], 'number'],
- [['CREATE_TIME'], 'string', 'max' => 20],
- [['RUN_DATE'], 'string', 'max' => 10],
- [['CONSUME_STOCK_TYPE'], 'string', 'max' => 100],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'UPDATE_USER_ID' => '记录最后更新用户ID',
- 'UPDATE_TIME' => '记录最后更新时间',
- 'DISTRIB_ID' => '分销商ID',
- 'HOTEL_ID' => '酒店ID',
- 'BASE_ROOM_TYPE' => '基础房型',
- 'ROOM_TYPE' => '子房型',
- 'RUN_DATE' => 'Run Date',
- 'REMAINING_COUNT' => '库存剩余数量',
- 'SALED_COUNT' => '已售数量',
- 'PROD_PRICE' => '分销价',
- 'CUS_PRICE' => '零售价',
- 'RUN_STATUS' => ' 房态 326:固定数量 329:关房',
- 'OVERSELL_FLAG' => '允许超卖标志 1:允许超卖 0:不允许超卖',
- 'CONSUME_STOCK_TYPE' => '下单时消耗的库存类型顺序',
- 'AUTHORITY_STATUS' => '授权状态 1:授权 0:关闭授权',
- ];
- }
-
- /**
- * Function Description:判断该渠道是否授权
- * Function Name: getRunHotelDistribOne
- * @param $model
- * @param $date
- *
- * @return static
- *
- * @author LUOCJ
- */
- public static function getRunHotelDistribOne($model, $date, $org_id)
- {
- $res = RunHotelDistrib::findOne(['distrib_id' => $org_id, 'hotel_id' => $model->extra_res_info, 'base_room_type' => $model->top_res_id, 'room_type' => $model->sub_res_id, 'run_date' => $date, 'authority_status' => RunHotelDistrib::AUTHORITY_STATUS_ON]);
- return $res;
- }
-
- /**
- * Des:获取酒店价格库存
- * Name: getHotelStockPrice
- * @param $hotel_id
- * @param $base_room_type
- * @param $room_type
- * @param $run_date
- * @param $org_id
- * @return mixed
- * @author 倪宗锋
- */
- public function getHotelStockPrice($hotel_id, $base_room_type, $room_type, $run_date, $org_id)
- {
- //1,获取每日房间属性
- $select = [
- 'rhd.run_date',//入住日期
- 'remaining_count' => new Expression("case rhd.run_status when 326 then rhd.remaining_count when 329 then -1 else 0 end"),//库存剩余数量
- 'rhd.oversell_flag',//允许超卖标志 1:允许超卖 0:不允许超卖
- 'rhd.consume_stock_type',//下单时消耗的库存类型顺序
- 'price' => new Expression("case when bss.sale_type = 177 then rhd.prod_price else rhd.cus_price end"),//价格
- 'bss.sale_type',//销售类型
- 'bss.commision_flag',
- 'bss.commision_type',
- 'bss.back_commision_type',
- 'bss.back_commision_method',
- 'bss.back_percent',
- 'bss.back_value',
- 'limit_total_num' => new Expression("if(rhd.OVERSELL_FLAG=1,(SELECT SUM(REMAINING_COUNT) from run_hotel g where rhd.HOTEL_ID=g.HOTEL_ID and rhd.BASE_ROOM_TYPE=g.BASE_ROOM_TYPE and rhd.RUN_DATE=g.RUN_DATE and g.STOCK_TYPE in (228,229,230)), rhd.REMAINING_COUNT)"),
- 'max_total_num' => new Expression("(SELECT SUM(REMAINING_COUNT) from run_hotel g where rhd.HOTEL_ID=g.HOTEL_ID and rhd.BASE_ROOM_TYPE=g.BASE_ROOM_TYPE and rhd.RUN_DATE=g.RUN_DATE and g.STOCK_TYPE in (228,229,230))"),
- ];
- $where = [
- 'and',
- ['=', 'rhd.distrib_id', $org_id],
- ['=', 'rhd.hotel_id', $hotel_id],
- ['=', 'rhd.room_type', $room_type],
- ['=', 'rhd.base_room_type', $base_room_type],
- ['=', 'rhd.run_date', $run_date],
- ['=', 'bss.parent_type', 25],
- ['=', 'bss.cancel_flag', 0],
- ['=', 'd.authority_status', 1],//run_hotel_distrib 授权
- ['=', 'rhd.run_status', 326],
- ['=', 'oh.hotel_status', 1],
- ['=', 'ohbr.cancel_flag', 0],
- ['=', 'ohr.is_onsale', 1],
- ['=', 'rhsr.run_status', 1],
- ];
- $hotel_info = self::find()->select($select)
- ->from('run_hotel_distrib as rhd')
- ->leftJoin('base_supplier_sale as bss', 'rhd.distrib_id = bss.supplier_id')
- ->leftJoin('opera_hotel as oh', 'oh.hotel_id=rhd.hotel_id')
- ->leftJoin('opera_hotel_base_room as ohbr', 'ohbr.hotel_id=rhd.hotel_id and ohbr.base_room_type = rhd.base_room_type')
- ->leftJoin('opera_hotel_room as ohr', 'ohr.hotel_id=rhd.hotel_id and ohr.parent_room_type = rhd.base_room_type and ohr.room_type = rhd.room_type')
- ->leftJoin('run_hotel_sub_room as rhsr', 'rhsr.hotel_id = rhd.hotel_id and rhsr.base_room_type = rhd.base_room_type and rhsr.room_type=rhd.room_type')
- ->leftJoin(OperaRoomDistrib::tableName() . ' d', 'ohr.ID=d.ROOM_ID and rhd.DISTRIB_ID=d.DISTRIB_ID and d.CANCEL_FLAG=0')
- ->where($where)
- ->asArray()
- ->one();
- if (empty($hotel_info['limit_total_num']) && empty($hotel_info['max_total_num'])) {
- $result['code'] = '1';
- $result['info'] = "($hotel_id-$base_room_type-$room_type-$run_date-$org_id)该酒店房型不可售";
- return $result;
- }
- $result['code'] = '0';
- $result['info'] = '获取酒店房型价格库存成功';
- $result['list'] = $hotel_info;
- return $result;
- }
- }
|