初始化仓库
This commit is contained in:
98
common/models/ImMessageSession.php
Normal file
98
common/models/ImMessageSession.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* @property Order $order
|
||||
*/
|
||||
class ImMessageSession extends \common\modelsgii\ImMessageSession
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => TimestampBehavior::class,
|
||||
'attributes' => [
|
||||
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
|
||||
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return array_merge(parent::attributes(), ['noread_count','last_time','last_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = parent::rules();
|
||||
$rules[] = [['noread_count'], 'safe'];
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return array_merge(parent::attributeLabels(), [
|
||||
'noread_count' => '未读数量',
|
||||
'last_time' => '最新消息时间'
|
||||
]);
|
||||
}
|
||||
|
||||
public static function createSession($user_id,$service_id,$type)
|
||||
{
|
||||
$imMessageSession = new self();
|
||||
$imMessageSession->user_id = $user_id;
|
||||
$imMessageSession->service_id = $service_id;
|
||||
$imMessageSession->type = $type;
|
||||
$imMessageSession->saveOrFail();
|
||||
return $imMessageSession;
|
||||
}
|
||||
|
||||
public function getSessionOrder()
|
||||
{
|
||||
return $this->hasOne(ImMessageSessionOrder::className(),['ims_id'=>'id']);
|
||||
}
|
||||
|
||||
//关联订单
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->hasOne(Order::className(),['id'=>'order_id'])->via('sessionOrder');
|
||||
}
|
||||
|
||||
//关联用户
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne(User::className(),['id'=>'user_id']);
|
||||
}
|
||||
|
||||
//关联用户
|
||||
public function getUserByServiceId()
|
||||
{
|
||||
return $this->hasOne(User::className(),['id'=>'service_id']);
|
||||
}
|
||||
|
||||
//关联服务人员
|
||||
public function getServiceUser()
|
||||
{
|
||||
return $this->hasOne(ServiceUser::className(),['id'=>'service_id']);
|
||||
}
|
||||
|
||||
//关联服务人员
|
||||
public function getServiceUserByUserId()
|
||||
{
|
||||
return $this->hasOne(ServiceUser::className(),['id'=>'user_id']);
|
||||
}
|
||||
|
||||
//关联消息
|
||||
public function getImMessage()
|
||||
{
|
||||
return $this->hasMany(ImMessage::className(),['ims_id'=>'id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user