<?php
namespace model\pro;
use model\element;
use model\pro\pro;
class exchange extends \model\element
{
	public $pro =null;
	public function __construct($elecfg='pro_exchange')
    {
		parent::__construct($elecfg);
		$this->pro = new pro();
	}

    /**
     * 添加一条记录
     * @param array $data 字段与值数组
     * @return bool
     */
	function add($data){
        $this->db->Begin();
        $saveData = $this->formartSaveData($data);
		$key = $this->db->select($this->table,$this->key,$saveData);
		if(empty($key)){
			$this->db->insert($this->table,$saveData);
			$key = $this->db->id();
			$this->pro->addLinkToNumidx($saveData['pe_p_id1'],$saveData['pe_p_id2'],'exchange',$key);
		}
        $this->db->End();
        return $key;
    }
	/**
	 * 删除记录
	 * @param string|int|array $ids, id集数组或字符串，字符串用 , 号分隔
	 * @return bool
	 */
	function deleteRows($ids){
        if(!is_array($ids)){
            $ids = explode(',',$ids);
        }
		$this->db->Begin();
		$this->db->delete($this->table,[$this->key=>$ids]);
		$this->pro->deleteLinkFromNumidx('exchange',$ids);
		$this->db->End();
		return true;
	}
}
