quanwei
2025-10-29 76ed09d116f484b261d44219de300b79eb2013b3
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
 
namespace app\supplier\model\chat;
 
use app\common\model\plus\chat\Chat as ChatModel;
 
/**
 * 客服消息模型类
 */
class Chat extends ChatModel
{
 
    /**
     * 隐藏字段
     */
    protected $hidden = [
        'app_id',
        'status',
        'update_time'
    ];
 
    //消息列表
    public function getList($user, $data)
    {
        $model = new ChatRelation();
        if ($data['nickName']) {
            $model = $model->where('ju.nickName', 'like', '%' . $data['nickName'] . '%');
        }
        $list = $model->with(['user', 'supplier.logo'])
            ->where(['supplier_user_id' => $user['supplier_user_id']])
            ->order('update_time desc')
            ->paginate($data);
        foreach ($list as $key => &$value) {
            $value['newMessage'] = $this->where('user_id', '=', $value['user_id'])
                ->where('supplier_user_id', '=', $value['supplier_user_id'])
                ->order('chat_id desc')
                ->find();
        }
        return $list;
    }
 
    //获取聊天信息
    public function getMessage($data, $user)
    {
        $list = $this->with(['user', 'supplier.logo'])
            ->where('supplier_user_id', '=', $user['supplier_user_id'])
            ->where('user_id', '=', $data['user_id'])
            ->order('chat_id desc')
            ->paginate($data);
        return $list;
    }
 
    //获取消息条数
    public function mCount($user)
    {
        $num = 0;
        if ($user) {
            $where[] = ['user_id', '=', $user['user_id']];
            $where[] = ['status', '=', 0];
            $where[] = ['msg_type', '=', 1];
            $num = $this->where($where)->count();
        }
        return $num;
    }
}