1.首先排查js文件和控制器文件的代码是否存在逻辑问题
2.如果正常则考虑是 日期时间条件解析的问题
打开文件
thinkphp/library/think/db/Builder.php第478行
/**
* 日期时间条件解析
* @access protected
* @param string $value
* @param string $key
* @param array $options
* @param string $bindName
* @param integer $bindType
* @return string
*/
protected function parseDateTime($value, $key, $options = [], $bindName = null, $bindType = null)
{
// 获取时间字段类型
if (strpos($key, '.')) {
list($table, $key) = explode('.', $key);
if (isset($options['alias']) && $pos = array_search($table, $options['alias'])) {
$table = $pos;
} else {
$prefix = config('database.prefix');
if (strpos($table, $prefix) === false) {
$table = $prefix . $table;
}
}
} else {
$table = $options['table'];
}
$type = $this->query->getTableInfo($table, 'type');
if (isset($type[$key])) {
$info = $type[$key];
}
if (isset($info)) {
if (is_string($value)) {
$value = strtotime($value) ?: $value;
}
if (preg_match('/(datetime|timestamp)/is', $info)) {
// 日期及时间戳类型
$value = date('Y-m-d H:i:s', $value);
} elseif (preg_match('/(date)/is', $info)) {
// 日期及时间戳类型
$value = date('Y-m-d', $value);
}
}
$bindName = $bindName ?: $key;
if ($this->query->isBind($bindName)) {
$bindName .= '_' . str_replace('.', '_', uniqid('', true));
}
$this->query->bind($bindName, $value, $bindType);
return ':' . $bindName;
}
使用这段代码来替换之前的代码
区别在于
if (isset($options['alias']) && $pos = array_search($table, $options['alias'])) {
$table = $pos;
} else {
$prefix = config('database.prefix');
if (strpos($table, $prefix) === false) {
$table = $prefix . $table;
}
}
替换之后问题应该就解决了,我的项目就是这么处理的