<?php


namespace app\models\system;

use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

class SystemProductStore extends BaseModel
{
    use ModelTrait;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'system_product_store';

    public static function saveProductStore($store_id, $product_id)
    {
        self::where('product_id', $product_id)->delete();
        $data = [];
        foreach ($store_id as $sid) {
            $data[] = ['product_id' => $product_id, 'store_id' => $sid];
        }
        self::insertAll($data);
    }

    public static function saveStoreProduct($product_id, $store_id)
    {
        self::where('store_id', $store_id)->delete();
        $data = [];
        foreach ($product_id as $pid) {
            $data[] = ['store_id' => $store_id, 'product_id' => $pid];
        }
        self::insertAll($data);
    }
}