<?php
declare (strict_types = 1);

namespace app\index\model;

use app\common\model\ProductPurchaseLinkBaseModel;

/**
 * 产品购买链接模型
 * @mixin \think\Model
 */
class ProductPurchaseLinkModel extends ProductPurchaseLinkBaseModel
{
    // 关联购买平台
    public function platform()
    {
        return $this->hasOne(ProductPurchasePlatformModel::class, 'id', 'platform_id');
    }

    // 所属产品范围查询
    public function scopeByProductId($query, $product_id)
    {
        if (is_array($product_id)) {
            return $query->where('product_id', 'IN', $product_id);
        }
        return $query->where('product_id', '=', $product_id);
    }
}
