quanwei
2025-11-21 2d9362ae6f528f57e6133d5d80f0b633c24e8eb6
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
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
 
namespace app\common\model\plus\assemble;
 
use app\common\model\BaseModel;
 
/**
 * 拼团商品
 */
class Product extends BaseModel
{
    protected $name = 'assemble_product';
    protected $pk = 'assemble_product_id';
 
    protected $append = ['product_sales', 'status_text'];
 
    /**
     * 计算显示销量 (初始销量 + 实际销量)
     */
    public function getProductSalesAttr($value, $data)
    {
        return $data['sales_initial'] + $data['total_sales'];
    }
 
    /**
     * 状态
     */
    public function getStatusTextAttr($value, $data)
    {
        if($data['status'] == 0){
            return '待审核';
        }
        if($data['status'] == 10){
            return '通过';
        }
        if($data['status'] == 20){
            return '未通过';
        }
        return '';
    }
 
    public static function detail($assemble_product_id, $with = ['product.sku', 'assembleSku'])
    {
        return (new static())->with($with)->where('assemble_product_id', '=', $assemble_product_id)->find();
    }
 
    public function active()
    {
        return $this->belongsTo('app\\common\\model\\plus\\assemble\\Active', 'assemble_activity_id', 'assemble_activity_id');
    }
 
    public function product()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
    }
    /**
     *关联商品规格表
     */
    public function assembleSku()
    {
        return $this->hasMany('app\\common\\model\\plus\\assemble\\AssembleSku', 'assemble_product_id', 'assemble_product_id');
    }
 
    /**
     * 关联供应商
     */
    public function supplier()
    {
        return $this->hasMany('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
    }
 
    /**
     * 商品ID是否存在
     */
    public static function isExistProductId($productId)
    {
        /*return (new static)->where('product_id', '=', $productId)
            ->where('is_delete', '=', 0)
            ->value('assemble_product_id');*/
        return (new static)->alias('a')->where('a.product_id', '=', $productId)
            ->join('assemble_activity aa', 'aa.assemble_activity_id=a.assemble_activity_id')
            ->where('aa.is_delete', '=', 0)
            ->where('a.is_delete', '=', 0)
            ->value('a.assemble_product_id');
    }
}