收支核对修改
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2020-09-30 17:32:46
|
||||
* @LastEditTime: 2020-10-24 12:11:18
|
||||
* @LastEditTime: 2020-10-26 10:33:22
|
||||
* @LastEditors: kangkang
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /phptest/fastphp/base/Model.php
|
||||
@@ -52,18 +52,6 @@ class Model extends Sql
|
||||
return $this->field($fields)->where($where)->order($order)->limit($limit)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照页数获取数据 复杂查询
|
||||
* @param $fields 'id,count(1)...'
|
||||
* @param $order 'id desc'/'id asc'
|
||||
* @param $limit = '100' 限制查询100条
|
||||
* $limit = '2,100' 查询第二页 100条数据
|
||||
*/
|
||||
public function getListPages($where = [], $fields = '*', $order = 'id desc', $limit = '50')
|
||||
{
|
||||
return $this->field($fields)->wheres($where)->order($order)->limit($limit)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取一条数据
|
||||
* @param {type}
|
||||
|
||||
@@ -28,11 +28,12 @@ class Sql
|
||||
*/
|
||||
public function where($where)
|
||||
{
|
||||
$this->param = [];
|
||||
$this->filter = '';
|
||||
$this->filter .= '';
|
||||
if ($where) {
|
||||
if(!strpos('$this->filter','WHERE') !== false){
|
||||
if(!strpos($this->filter,'WHERE') !== false){
|
||||
$this->filter .= ' WHERE ';
|
||||
} else {
|
||||
$this->filter .= ' AND ';
|
||||
}
|
||||
if (is_string($where)) {
|
||||
$this->filter .= $where;
|
||||
@@ -45,8 +46,9 @@ class Sql
|
||||
if($value[0] == 'in'){
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $key;
|
||||
$this->param[$key] = $value[1];
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` = :' . $key;
|
||||
@@ -57,8 +59,9 @@ class Sql
|
||||
if($value[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $key;
|
||||
$this->param[$key] = $value[1];
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` = :' . $key;
|
||||
@@ -71,73 +74,15 @@ class Sql
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 查询条件 处理复杂查询条件
|
||||
* @param {*} [ 'day_time' => [ ['>' , val1], ['<' , val2] ] ]
|
||||
* @return {*}
|
||||
*/
|
||||
public function wheres($where)
|
||||
{
|
||||
$this->param = [];
|
||||
$this->filter = '';
|
||||
if ($where) {
|
||||
|
||||
if(!strpos('$this->filter','WHERE') !== false){
|
||||
$this->filter .= ' WHERE ';
|
||||
}
|
||||
if (is_string($where)) {
|
||||
$this->filter .= ' WHERE ' . $where;
|
||||
} else {
|
||||
$flag = true;
|
||||
foreach ($where as $key => $value) {
|
||||
if ($flag) {
|
||||
$flag = false;
|
||||
if (is_array($value)) {
|
||||
$flag2 = true;
|
||||
foreach($value as $k => $v) {
|
||||
if($flag2){
|
||||
$flag2 = false;
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
} else {
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` = :' . $key;
|
||||
$this->param[$key] = $value;
|
||||
}
|
||||
} else {
|
||||
if (is_array($value)) {
|
||||
foreach($value as $k => $v) {
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` = :' . $key;
|
||||
$this->param[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function paramIsExit($key,$param){
|
||||
if(!isset($param[$key])){
|
||||
return $key;
|
||||
} else {
|
||||
$key .= $key;
|
||||
return $this->paramIsExit($key,$param);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拼装排序条件
|
||||
* @param array $order 排序条件
|
||||
@@ -202,6 +147,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetchAll();
|
||||
@@ -217,6 +163,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetch();
|
||||
@@ -233,6 +180,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->rowCount();
|
||||
@@ -279,6 +227,7 @@ class Sql
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $data);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->rowCount();
|
||||
|
||||
Reference in New Issue
Block a user