You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------
namespace Admin\Model;
use Think\Model;
/**
* 文档基础模型
*/
class SubsiteModel extends Model{
//批量添加
protected $dbcount=0;
protected $syncKey="id";
protected $syncData;
protected $syncWhere=false;
public function __construct($name = '', $tablePrefix = '', $connection = '')
{
parent::__construct($name, $tablePrefix, $connection);
if(in_array($this->trueTableName,C('SUBSITE_TABLE'))){
$SUBSITE_DB = C("SUBSITE_DB_CONFIG");
$i = 1;
foreach ($SUBSITE_DB as $k => $v) {
$this->db($i,$v);
$i++;
}
$this->dbcount = $i;
}
}
//修改主键默认id
public function syncKey($key){
$this->syncKey = $key;
return $this;
}
//持续化数据条件
protected function syncCreate($data)
{
$this->syncData = $data;
if(isset($this->options['where'])){
$this->syncWhere = $this->options['where'];
}
}
//同步添加
public function syncAdd($data)
{
$this->syncCreate($data);
$syncVal = $this->db(0)->add();
if(empty($syncVal)){
return $syncVal;
}
$this->syncData[$this->syncKey] = $syncVal;
for ($i=1; $i < $this->dbcount; $i++) {
$this->db($i)->add($this->syncData);
}
return $syncVal;
}
//同步修改
public function syncSave($data)
{
$this->syncCreate($data);
for ($i=0; $i < $this->dbcount; $i++) {
$this->db($i)->where($this->syncWhere)->save($this->syncData);
}
return true;
}
}