quanwei
2025-11-21 2d9362ae6f528f57e6133d5d80f0b633c24e8eb6
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
<?php
namespace app\api\model\plus\business;
use app\common\model\plus\business\Saving as CommonSaving;
/**
 * 名片记录模型
 */
class Saving extends CommonSaving
{
    /**
     * 添加记录
     */
    public function add($data)
    {
        $data['app_id']=self::$app_id;
        $data['create_time']=time();
        return $this->save($data);
    }
    
    /**
     * 获取浏览记录统计
     */
    public function getBrowseStats($user_id)
    {
        return [
            'total' => $this->where(['affiliation_id'=>$user_id,'type'=>10])->count(),
            'today' => $this->where(['affiliation_id'=>$user_id,'type'=>10])->whereTime('create_time', 'today')->count(),
            'week' => $this->where(['affiliation_id'=>$user_id,'type'=>10])->whereTime('create_time', 'week')->count(),
            'month' => $this->where(['affiliation_id'=>$user_id,'type'=>10])->whereTime('create_time', 'month')->count()
        ];
    }
    
    /**
     * 获取最近访客
     */
    public function getRecentVisitors($user_id, $limit = 5)
    {
        return $this->with(['user' => ['image']])
            ->where(['affiliation_id'=>$user_id,'type'=>10])
            ->order('create_time', 'desc')
            ->limit($limit)
            ->select();
    }
}