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