<?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();
|
}
|
}
|