<?php
|
|
namespace app\api\model\plus\groupbuy;
|
|
use app\common\model\plus\groupbuy\BillUser as BillUserModel;
|
|
/**
|
* 团购用户参与记录模型(API端)
|
*/
|
class BillUser extends BillUserModel
|
{
|
/**
|
* 添加团购用户参与记录
|
*/
|
public function add($data)
|
{
|
return self::create($data);
|
}
|
|
/**
|
* 获取用户团购参与数量
|
*/
|
public static function getOrderNum($user_id, $groupbuy_product_id, $groupbuy_active_id)
|
{
|
$model = new self();
|
return $model->alias('user')
|
->join('groupbuy_bill bill', 'bill.groupbuy_bill_id = user.groupbuy_bill_id', 'left')
|
->where('user.user_id', '=', $user_id)
|
->where('bill.groupbuy_product_id', '=', $groupbuy_product_id)
|
->where('bill.groupbuy_active_id', '=', $groupbuy_active_id)
|
->where('bill.status', 'in', [10, 20])
|
->count();
|
}
|
|
/**
|
* 检查用户是否已参与团购
|
*/
|
public static function checkUserJoined($user_id, $groupbuy_bill_id)
|
{
|
return self::where('user_id', '=', $user_id)
|
->where('groupbuy_bill_id', '=', $groupbuy_bill_id)
|
->find();
|
}
|
}
|