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
<?php
 
namespace app\common\model\plus\groupbuy;
 
use app\common\model\BaseModel;
 
/**
 * 团购用户参与记录模型
 */
class BillUser extends BaseModel
{
    protected $name = 'groupbuy_bill_user';
    protected $pk = 'groupbuy_bill_user_id';
 
    /**
     * 获取团购用户参与记录详情
     */
    public static function detail($groupbuy_bill_user_id)
    {
        return (new static())->where('groupbuy_bill_user_id', '=', $groupbuy_bill_user_id)->find();
    }
 
    /**
     * 根据团购订单ID获取参与用户
     */
    public static function getUsersByBillId($groupbuy_bill_id)
    {
        return (new static())
            ->where('groupbuy_bill_id', '=', $groupbuy_bill_id)
            ->with(['user'])
            ->select();
    }
 
    /**
     * 关联用户表
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id')
            ->bind('nickName,avatarUrl');
    }
 
    /**
     * 检查用户是否已参与某个团购
     */
    public static function checkUserJoined($user_id, $groupbuy_bill_id)
    {
        return (new static())
            ->where('user_id', '=', $user_id)
            ->where('groupbuy_bill_id', '=', $groupbuy_bill_id)
            ->find();
    }
}