quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
 
namespace app\common\model\plus\groupbuy;
 
use app\common\model\BaseModel;
 
/**
 * 团购商品模型
 */
class Product extends BaseModel
{
    protected $name = 'groupbuy_product';
    protected $pk = 'groupbuy_product_id';
 
    public function active()
    {
        return $this->belongsTo('app\\common\\model\\plus\\groupbuy\\Active', 'groupbuy_active_id', 'groupbuy_active_id');
    }
    /**
     * 关联商品表
     */
    public function product()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
    }
 
    /**
     * 关联团购SKU表
     */
    public function groupbuySku()
    {
        return $this->hasMany('app\\common\\model\\plus\\groupbuy\\ProductSku', 'groupbuy_product_id', 'groupbuy_product_id');
    }
 
    /**
     * 关联供应商
     */
    public function supplier()
    {
        return $this->hasMany('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
    }
 
    /**
     * 获取团购商品详情
     */
    public static function detail($groupbuy_product_id, $with = [])
    {
        return (new static())->with($with)->where('groupbuy_product_id', '=', $groupbuy_product_id)->find();
    }
 
    /**
     * 判断商品ID是否存在
     */
    public static function isExistProductId($productId)
    {
        return (new static)->alias('a')->where('a.product_id', '=', $productId)
            ->join('groupbuy_active ga', 'ga.groupbuy_active_id=a.groupbuy_active_id')
            ->where('ga.is_delete', '=', 0)
            ->where('a.is_delete', '=', 0)
            ->value('a.groupbuy_product_id');
    }
 
    /**
     * 根据商品ID获取团购商品
     */
    public static function getByProductId($productId)
    {
        return (new static())->where('product_id', '=', $productId)
            ->where('is_delete', '=', 0)
            ->where('state', '=', 10)
            ->find();
    }
}