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.
 
 
 
 
 
 

125 line
4.2 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "run_hotel".
  6. * 基础房型库存数量
  7. *
  8. * @property integer $ID
  9. * @property integer $CREATE_USER_ID
  10. * @property string $CREATE_TIME
  11. * @property integer $UPDATE_USER_ID
  12. * @property string $UPDATE_TIME
  13. * @property integer $HOTEL_ID
  14. * @property integer $BASE_ROOM_TYPE
  15. * @property string $RUN_DATE
  16. * @property integer $STOCK_TYPE
  17. * @property integer $REMAINING_COUNT
  18. * @property integer $SALED_COUNT
  19. * @property integer $IS_ONSALE
  20. */
  21. class RunHotel extends \yii\db\ActiveRecord
  22. {
  23. /**
  24. * @inheritdoc
  25. */
  26. public static function tableName()
  27. {
  28. return 'run_hotel';
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['CREATE_USER_ID', 'UPDATE_USER_ID', 'HOTEL_ID', 'BASE_ROOM_TYPE', 'STOCK_TYPE', 'REMAINING_COUNT', 'SALED_COUNT', 'IS_ONSALE'], 'integer'],
  37. [['CREATE_TIME', 'RUN_DATE'], 'required'],
  38. [['UPDATE_TIME'], 'safe'],
  39. [['CREATE_TIME', 'RUN_DATE'], 'string', 'max' => 20],
  40. ];
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'ID' => 'ID',
  49. 'CREATE_USER_ID' => '记录创建用户ID',
  50. 'CREATE_TIME' => '记录创建时间',
  51. 'UPDATE_USER_ID' => '记录最后更新用户ID',
  52. 'UPDATE_TIME' => '记录最后更新时间',
  53. 'HOTEL_ID' => '酒店ID',
  54. 'BASE_ROOM_TYPE' => '基础房型',
  55. 'RUN_DATE' => '售卖日期',
  56. 'STOCK_TYPE' => '库存类型',
  57. 'REMAINING_COUNT' => '库存剩余数量',
  58. 'SALED_COUNT' => '已售数量',
  59. 'IS_ONSALE' => ' 上下线标志 1:上线 0:下线',
  60. ];
  61. }
  62. /**
  63. * User:Steven
  64. * Desc:获取基础房型的库存 用于对部分房型的库存进行监控预警
  65. * @param $base_room_id 基础房型的ID
  66. */
  67. public function getRunHotelCount($base_room_id)
  68. {
  69. $begin_date = date('Y-m-d', time());
  70. $end_date = date('Y-m-d', strtotime('+1 month'));
  71. $sql = "select a.hotel_id,a.base_room_type,a.run_date,a.is_onsale,a.stock_type,c.hotel_name,b.base_room_name,c.principal,d.USER_NAME,
  72. sum(case a.stock_type when 228 then a.remaining_count else 0 end) as 'buyout',
  73. sum(case a.stock_type when 229 then a.remaining_count else 0 end) as 'inquiry',
  74. sum(case a.stock_type when 230 then a.remaining_count else 0 end) as 'retain'
  75. from run_hotel a
  76. LEFT JOIN opera_hotel_base_room b on a.base_room_type=b.main_id
  77. LEFT JOIN opera_hotel c on a.hotel_id=c.hotel_id
  78. LEFT JOIN base_user d on c.PRINCIPAL=d.ID
  79. where a.base_room_type={$base_room_id} and a.run_date BETWEEN '{$begin_date}' and '{$end_date}' GROUP BY base_room_type,run_date";
  80. $connection = Yii::$app->db;
  81. $res = $connection->createCommand($sql)->queryAll();
  82. return $res;
  83. }
  84. /**
  85. * User:Steven
  86. * Desc:获取部分基础房型(拆分房型和合并房型)已售数量的统计 (徐安)
  87. * @return array
  88. */
  89. public function getRoomSaledCount(){
  90. $date=date('Y-m-d',time());
  91. $sql="SELECT
  92. a.HOTEL_ID,
  93. a.RUN_DATE,
  94. sum(a.num) as saledcount
  95. FROM
  96. (
  97. SELECT
  98. HOTEL_ID,
  99. BASE_ROOM_TYPE,
  100. RUN_DATE,
  101. sum(SALED_COUNT) as num
  102. FROM
  103. run_hotel
  104. WHERE
  105. hotel_id = 23
  106. AND RUN_DATE >= '{$date}'
  107. AND BASE_ROOM_TYPE IN (9797, 150039, 150060)
  108. GROUP BY
  109. RUN_DATE,
  110. base_room_type
  111. ) AS a GROUP BY a.RUN_DATE";
  112. $connection = Yii::$app->db;
  113. $res = $connection->createCommand($sql)->queryAll();
  114. return $res;
  115. }
  116. }