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.
 
 
 
 
 
 

171 rivejä
6.9 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use backend\modules\hotel\models\OperaRoomDistrib;
  4. use yii\db\ActiveRecord;
  5. use yii\db\Expression;
  6. /**
  7. * This is the model class for table "run_hotel_distrib".
  8. *
  9. * @property integer $ID
  10. * @property integer $CREATE_USER_ID
  11. * @property string $CREATE_TIME
  12. * @property integer $UPDATE_USER_ID
  13. * @property string $UPDATE_TIME
  14. * @property integer $DISTRIB_ID
  15. * @property integer $HOTEL_ID
  16. * @property integer $BASE_ROOM_TYPE
  17. * @property integer $ROOM_TYPE
  18. * @property string $RUN_DATE
  19. * @property integer $REMAINING_COUNT
  20. * @property integer $SALED_COUNT
  21. * @property string $PROD_PRICE
  22. * @property string $CUS_PRICE
  23. * @property integer $RUN_STATUS
  24. * @property integer $OVERSELL_FLAG
  25. * @property string $CONSUME_STOCK_TYPE
  26. * @property integer $AUTHORITY_STATUS
  27. */
  28. class RunHotelDistrib extends ActiveRecord
  29. {
  30. const AUTHORITY_STATUS_ON = 1; //渠道授权 开
  31. const AUTHORITY_STATUS_DOWN = 0; //渠道授权 关
  32. /**
  33. * @inheritdoc
  34. */
  35. public static function tableName()
  36. {
  37. return 'run_hotel_distrib';
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function rules()
  43. {
  44. return [
  45. [['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'],
  46. [['CREATE_TIME'], 'required'],
  47. [['UPDATE_TIME'], 'safe'],
  48. [['PROD_PRICE', 'CUS_PRICE'], 'number'],
  49. [['CREATE_TIME'], 'string', 'max' => 20],
  50. [['RUN_DATE'], 'string', 'max' => 10],
  51. [['CONSUME_STOCK_TYPE'], 'string', 'max' => 100],
  52. ];
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'ID' => 'ID',
  61. 'CREATE_USER_ID' => '记录创建用户ID',
  62. 'CREATE_TIME' => '记录创建时间',
  63. 'UPDATE_USER_ID' => '记录最后更新用户ID',
  64. 'UPDATE_TIME' => '记录最后更新时间',
  65. 'DISTRIB_ID' => '分销商ID',
  66. 'HOTEL_ID' => '酒店ID',
  67. 'BASE_ROOM_TYPE' => '基础房型',
  68. 'ROOM_TYPE' => '子房型',
  69. 'RUN_DATE' => 'Run Date',
  70. 'REMAINING_COUNT' => '库存剩余数量',
  71. 'SALED_COUNT' => '已售数量',
  72. 'PROD_PRICE' => '分销价',
  73. 'CUS_PRICE' => '零售价',
  74. 'RUN_STATUS' => ' 房态 326:固定数量 329:关房',
  75. 'OVERSELL_FLAG' => '允许超卖标志 1:允许超卖 0:不允许超卖',
  76. 'CONSUME_STOCK_TYPE' => '下单时消耗的库存类型顺序',
  77. 'AUTHORITY_STATUS' => '授权状态 1:授权 0:关闭授权',
  78. ];
  79. }
  80. /**
  81. * Function Description:判断该渠道是否授权
  82. * Function Name: getRunHotelDistribOne
  83. * @param $model
  84. * @param $date
  85. *
  86. * @return static
  87. *
  88. * @author LUOCJ
  89. */
  90. public static function getRunHotelDistribOne($model, $date, $org_id)
  91. {
  92. $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]);
  93. return $res;
  94. }
  95. /**
  96. * Des:获取酒店价格库存
  97. * Name: getHotelStockPrice
  98. * @param $hotel_id
  99. * @param $base_room_type
  100. * @param $room_type
  101. * @param $run_date
  102. * @param $org_id
  103. * @return mixed
  104. * @author 倪宗锋
  105. */
  106. public function getHotelStockPrice($hotel_id, $base_room_type, $room_type, $run_date, $org_id)
  107. {
  108. //1,获取每日房间属性
  109. $select = [
  110. 'rhd.run_date',//入住日期
  111. 'remaining_count' => new Expression("case rhd.run_status when 326 then rhd.remaining_count when 329 then -1 else 0 end"),//库存剩余数量
  112. 'rhd.oversell_flag',//允许超卖标志 1:允许超卖 0:不允许超卖
  113. 'rhd.consume_stock_type',//下单时消耗的库存类型顺序
  114. 'price' => new Expression("case when bss.sale_type = 177 then rhd.prod_price else rhd.cus_price end"),//价格
  115. 'bss.sale_type',//销售类型
  116. 'bss.commision_flag',
  117. 'bss.commision_type',
  118. 'bss.back_commision_type',
  119. 'bss.back_commision_method',
  120. 'bss.back_percent',
  121. 'bss.back_value',
  122. '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)"),
  123. '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))"),
  124. ];
  125. $where = [
  126. 'and',
  127. ['=', 'rhd.distrib_id', $org_id],
  128. ['=', 'rhd.hotel_id', $hotel_id],
  129. ['=', 'rhd.room_type', $room_type],
  130. ['=', 'rhd.base_room_type', $base_room_type],
  131. ['=', 'rhd.run_date', $run_date],
  132. ['=', 'bss.parent_type', 25],
  133. ['=', 'bss.cancel_flag', 0],
  134. ['=', 'd.authority_status', 1],//run_hotel_distrib 授权
  135. ['=', 'rhd.run_status', 326],
  136. ['=', 'oh.hotel_status', 1],
  137. ['=', 'ohbr.cancel_flag', 0],
  138. ['=', 'ohr.is_onsale', 1],
  139. ['=', 'rhsr.run_status', 1],
  140. ];
  141. $hotel_info = self::find()->select($select)
  142. ->from('run_hotel_distrib as rhd')
  143. ->leftJoin('base_supplier_sale as bss', 'rhd.distrib_id = bss.supplier_id')
  144. ->leftJoin('opera_hotel as oh', 'oh.hotel_id=rhd.hotel_id')
  145. ->leftJoin('opera_hotel_base_room as ohbr', 'ohbr.hotel_id=rhd.hotel_id and ohbr.base_room_type = rhd.base_room_type')
  146. ->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')
  147. ->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')
  148. ->leftJoin(OperaRoomDistrib::tableName() . ' d', 'ohr.ID=d.ROOM_ID and rhd.DISTRIB_ID=d.DISTRIB_ID and d.CANCEL_FLAG=0')
  149. ->where($where)
  150. ->asArray()
  151. ->one();
  152. if (empty($hotel_info['limit_total_num']) && empty($hotel_info['max_total_num'])) {
  153. $result['code'] = '1';
  154. $result['info'] = "($hotel_id-$base_room_type-$room_type-$run_date-$org_id)该酒店房型不可售";
  155. return $result;
  156. }
  157. $result['code'] = '0';
  158. $result['info'] = '获取酒店房型价格库存成功';
  159. $result['list'] = $hotel_info;
  160. return $result;
  161. }
  162. }