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