内核更新

This commit is contained in:
2016-12-28 10:41:09 +08:00
parent c89254e12a
commit ffab826db0
65 changed files with 1194 additions and 610 deletions

View File

@@ -2,6 +2,8 @@
namespace traits\model;
use think\db\Query;
trait SoftDelete
{
@@ -22,7 +24,7 @@ trait SoftDelete
/**
* 查询软删除数据
* @access public
* @return \think\db\Query
* @return Query
*/
public static function withTrashed()
{
@@ -34,7 +36,7 @@ trait SoftDelete
/**
* 只查询软删除数据
* @access public
* @return \think\db\Query
* @return Query
*/
public static function onlyTrashed()
{
@@ -77,8 +79,8 @@ trait SoftDelete
*/
public static function destroy($data, $force = false)
{
$model = new static();
$query = $model->db();
// 包含软删除数据
$query = self::withTrashed();
if (is_array($data) && key($data) !== 0) {
$query->where($data);
$data = null;
@@ -109,15 +111,19 @@ trait SoftDelete
public function restore($where = [])
{
$name = $this->getDeleteTimeField();
if (empty($where)) {
$pk = $this->getPk();
$where[$pk] = $this->getData($pk);
$where[$name] = ['not null', ''];
}
// 恢复删除
return $this->isUpdate()->save([$name => null], $where);
return $this->db(false)->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]);
}
/**
* 查询默认不包含软删除数据
* @access protected
* @param \think\db\Query $query 查询对象
* @param Query $query 查询对象
* @return void
*/
protected function base($query)

View File

@@ -11,7 +11,7 @@
namespace traits\think;
use \think\Exception;
use think\Exception;
trait Instance
{