|
- <?php
-
- namespace backend\modules\hotel\models;
-
- use backend\modules\api\models\BaseUser;
- use common\models\zModel;
-
- /**
- * This is the model class for table "opera_hotel_log".
- *
- * @property integer $ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $LOG_TYPE
- * @property integer $HOTEL_ID
- * @property integer $PARENT_ROOM_TYPE
- * @property integer $ROOM_TYPE
- * @property string $LOG_DESC
- * @property integer $ORDER_ID
- */
- class OperaHotelLog extends zModel
- {
- const LOG_TYPE_HOTEL = 1; //酒店操作日志
- const LOG_TYPE_ROOM = 2; //酒店房型操作日志
- const LOG_TYPE_ORDER = 3; //订单操作日志
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_hotel_log';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'LOG_TYPE', 'HOTEL_ID', 'PARENT_ROOM_TYPE', 'ROOM_TYPE', 'ORDER_ID'], 'integer'],
- [['CREATE_TIME'], 'string', 'max' => 20],
- [['LOG_DESC'], 'string'],
- ];
- }
-
- public function getOrderMain()
- {
- return $this->hasOne(OrderMain::className(), ['ORDER_ID' => 'ORDER_ID']);
- }
-
- public function getBaseUser()
- {
- return $this->hasOne(BaseUser::className(), ['ID' => 'CREATE_USER_ID']);
- }
-
- public function getOrderLog($order_id, $user_id = 0, $begin_date = null, $end_date = null)
- {
- $begin_date = isset($begin_date) ? $begin_date . '00:00:00': '2016-01-01 00:00:00';
- $end_date = isset($end_date) ? $end_date . '23:59:59': date('Y-m-d') . '23:59:59';
- $query = OperaHotelLog::find()
- ->select(['c.TRUE_NAME', 'a.CREATE_TIME', 'a.LOG_DESC'])
- ->joinWith('baseUser c')
- ->from('opera_hotel_log a')
- ->where(['a.ORDER_ID' => $order_id, 'a.LOG_TYPE' => self::LOG_TYPE_ORDER]);
- // $this->load($params);
- $query->andFilterWhere(['between', 'a.CREATE_TIME', $begin_date, $end_date]);
- if($user_id) {
- $query->andFilterWhere(['a.CREATE_USER_ID' => $user_id]);
- }
- $data = $query->asArray()->all();
-
- return $data;
- }
-
- public function getLogUser($order_id)
- {
- $user_list = OperaHotelLog::find()
- ->select(['b.ID', 'b.TRUE_NAME'])
- ->joinWith('baseUser b')
- ->from('opera_hotel_log a')
- ->where(['a.ORDER_ID' => $order_id])
- ->asArray()->all();
-
- return $user_list;
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'LOG_TYPE' => '日志类型',
- 'HOTEL_ID' => '酒店ID,对应opera_hotel.hotel_id',
- 'PARENT_ROOM_TYPE' => '基础房型',
- 'ROOM_TYPE' => '子房型,对应opera_hotel_room.room_type',
- 'LOG_DESC' => '日志描述',
- 'ORDER_ID' => 'Order ID',
- ];
- }
-
- public function beforeSave($insert)
- {
- if($this->isNewRecord) {
- $this->CREATE_TIME = date('Y-m-d H:i:s', time());
- }
-
- return parent::beforeSave($insert);
- }
- }
|