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.
 
 
 
 
 
 

115 lines
3.2 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use backend\modules\api\models\BaseUser;
  4. use common\models\zModel;
  5. /**
  6. * This is the model class for table "opera_hotel_log".
  7. *
  8. * @property integer $ID
  9. * @property integer $CREATE_USER_ID
  10. * @property string $CREATE_TIME
  11. * @property integer $LOG_TYPE
  12. * @property integer $HOTEL_ID
  13. * @property integer $PARENT_ROOM_TYPE
  14. * @property integer $ROOM_TYPE
  15. * @property string $LOG_DESC
  16. * @property integer $ORDER_ID
  17. */
  18. class OperaHotelLog extends zModel
  19. {
  20. const LOG_TYPE_HOTEL = 1; //酒店操作日志
  21. const LOG_TYPE_ROOM = 2; //酒店房型操作日志
  22. const LOG_TYPE_ORDER = 3; //订单操作日志
  23. /**
  24. * @inheritdoc
  25. */
  26. public static function tableName()
  27. {
  28. return 'opera_hotel_log';
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['CREATE_USER_ID', 'LOG_TYPE', 'HOTEL_ID', 'PARENT_ROOM_TYPE', 'ROOM_TYPE', 'ORDER_ID'], 'integer'],
  37. [['CREATE_TIME'], 'string', 'max' => 20],
  38. [['LOG_DESC'], 'string'],
  39. ];
  40. }
  41. public function getOrderMain()
  42. {
  43. return $this->hasOne(OrderMain::className(), ['ORDER_ID' => 'ORDER_ID']);
  44. }
  45. public function getBaseUser()
  46. {
  47. return $this->hasOne(BaseUser::className(), ['ID' => 'CREATE_USER_ID']);
  48. }
  49. public function getOrderLog($order_id, $user_id = 0, $begin_date = null, $end_date = null)
  50. {
  51. $begin_date = isset($begin_date) ? $begin_date . '00:00:00': '2016-01-01 00:00:00';
  52. $end_date = isset($end_date) ? $end_date . '23:59:59': date('Y-m-d') . '23:59:59';
  53. $query = OperaHotelLog::find()
  54. ->select(['c.TRUE_NAME', 'a.CREATE_TIME', 'a.LOG_DESC'])
  55. ->joinWith('baseUser c')
  56. ->from('opera_hotel_log a')
  57. ->where(['a.ORDER_ID' => $order_id, 'a.LOG_TYPE' => self::LOG_TYPE_ORDER]);
  58. // $this->load($params);
  59. $query->andFilterWhere(['between', 'a.CREATE_TIME', $begin_date, $end_date]);
  60. if($user_id) {
  61. $query->andFilterWhere(['a.CREATE_USER_ID' => $user_id]);
  62. }
  63. $data = $query->asArray()->all();
  64. return $data;
  65. }
  66. public function getLogUser($order_id)
  67. {
  68. $user_list = OperaHotelLog::find()
  69. ->select(['b.ID', 'b.TRUE_NAME'])
  70. ->joinWith('baseUser b')
  71. ->from('opera_hotel_log a')
  72. ->where(['a.ORDER_ID' => $order_id])
  73. ->asArray()->all();
  74. return $user_list;
  75. }
  76. /**
  77. * @inheritdoc
  78. */
  79. public function attributeLabels()
  80. {
  81. return [
  82. 'ID' => 'ID',
  83. 'CREATE_USER_ID' => '记录创建用户ID',
  84. 'CREATE_TIME' => '记录创建时间',
  85. 'LOG_TYPE' => '日志类型',
  86. 'HOTEL_ID' => '酒店ID,对应opera_hotel.hotel_id',
  87. 'PARENT_ROOM_TYPE' => '基础房型',
  88. 'ROOM_TYPE' => '子房型,对应opera_hotel_room.room_type',
  89. 'LOG_DESC' => '日志描述',
  90. 'ORDER_ID' => 'Order ID',
  91. ];
  92. }
  93. public function beforeSave($insert)
  94. {
  95. if($this->isNewRecord) {
  96. $this->CREATE_TIME = date('Y-m-d H:i:s', time());
  97. }
  98. return parent::beforeSave($insert);
  99. }
  100. }