quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<?php
 
namespace app\branch\model\user;
 
use app\common\model\user\Favorite as FavoriteModel;
/**
 * 收藏模型
 */
class Favorite extends FavoriteModel
{
    /**
     * 获取关注店铺的用户
     */
    public function getUserList($branch_id, $params)
    {
        $model = $this;
        if(isset($params['search']) && $params['search'] != ''){
            $model = $model->where('user.nickName|user.mobile', 'like', '%' . trim($params['search']) . '%');
        }
        return $model->alias('fav')->field(['fav.*'])->with(['user'])
            ->join('user user', 'user.user_id = fav.user_id','left')
            ->where('fav.pid', '=', $branch_id)
            ->where('fav.type', '=', 10)
            ->paginate($params);
    }
 
    /**
     * 获取某天的关注用户数
     */
    public function getUserTotal($day, $branch_id)
    {
        $startTime = strtotime($day);
        return $this->where('pid', '=', $branch_id)
            ->where('type', '=', 10)
            ->where('create_time', '>=', $startTime)
            ->where('create_time', '<', $startTime + 86400)
            ->count();
    }
    /**
     * 获取某天的店铺关注数
     * $endDate不传则默认当天
     */
    public function getFavData($startDate, $endDate, $type, $branch_id){
        $model = $this;
        !is_null($startDate) && $model = $model->where('create_time', '>=', strtotime($startDate));
 
        if(is_null($endDate)){
            !is_null($startDate) && $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
        }else{
            $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
        }
 
        return $model->where('branch_id', '=', $branch_id)
            ->where('type', '=', $type)
            ->count();
    }
}