1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
 
 
namespace app\common\model\plus\release;
 
use app\common\model\BaseModel;
 
/**
 * 客服消息关系模型
 */
class ChatRelation extends BaseModel
{
    protected $pk = 'relation_id';
    protected $name = 'release_chat_relation';
 
    /**
     * 关联会员表
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
    }
 
    /**
     * 关联会员表
     */
    public function otherUser()
    {
        return $this->belongsTo("app\\common\\model\\user\\User", 'user_id', 'other_user_id');
    }
 
    /**
     * 获取关联id
     */
    public static function getRelationId($user_id,$other_user_id)
    {
        $model = new static;
        $data = $model->where("user_id",'=',$user_id)->where("other_user_id",'=',$other_user_id)->find();
        if(empty($data)){
            $data = $model->where("other_user_id",'=',$user_id)->where("user_id",'=',$other_user_id)->find();
        }
        return empty($data) ? 0 : $data['relation_id'];
    }
}