protected function arrToCondition($arr, $tableName)
{
empty($tableName) && ($tableName = Cml::getContainer()->make('cml_route')->getControllerName());
/*
//这个应该开发人员自己判断。框架不做额外开销
$dbFields = $this->getDbFields($tableName, $tablePrefix);
foreach (array_keys($arr) as $key) {
if (!isset($dbFields[$key])) unset($arr[$key]); //过滤db表中不存在的字段
}
*/
$s = $p = '';
$params = [];
foreach ($arr as $k => $v) {
if (is_array($v)) {
//自增或自减
switch (key($v)) {
case 'inc':
$p = "`{$k}`= `{$k}`+" . abs(intval(current($v)));
break;
case 'dec':
$p = "`{$k}`= `{$k}`-" . abs(intval(current($v)));
break;
case 'func':
$func = strtoupper(key(current($v)));
$funcParams = current(current($v));
foreach ($funcParams as $key => $val) {
if (!isset($dbFields[$val])) {
$funcParams[$key] = '%s';
$params[] = $val;
}
}
$p = "`{$k}`= {$func}(" . implode($funcParams, ',') . ')';
break;
default:
//计算类型
$conkey = key($v);
if (!isset($dbFields[$conkey])) {
$conkey = $k;
}
if (!in_array(key(current($v)), ['+', '-', '*', '/', '%', '^', '&', '|', '<<', '>>', '~'])) {
throw new \InvalidArgumentException(Lang::get('_PARSE_UPDATE_SQL_PARAMS_ERROR_'));
}
$p = "`{$k}`= `{$conkey}`" . key(current($v)) . abs(intval(current(current($v))));
break;
}
} else {
$p = "`{$k}`= %s";
$params[] = $v;
}
$s .= (empty($s) ? '' : ',') . $p;
}
$this->bindParams = array_merge($params, $this->bindParams);
return $s;
}