修正model类

This commit is contained in:
thinkphp
2016-03-04 17:42:17 +08:00
parent c7be6204c9
commit e124d1f9dc
2 changed files with 28 additions and 28 deletions

View File

@@ -692,7 +692,7 @@ class Model
*/ */
public function setInc($field, $step = 1, $lazyTime = 0) public function setInc($field, $step = 1, $lazyTime = 0)
{ {
$condition = $this->options['where']; $condition = !empty($this->options['where']) ? $this->options['where'] : [];
if (empty($condition)) { if (empty($condition)) {
// 没有条件不做任何更新 // 没有条件不做任何更新
throw new Exception('no data to update'); throw new Exception('no data to update');
@@ -703,8 +703,6 @@ class Model
$step = $this->lazyWrite($guid, $step, $lazyTime); $step = $this->lazyWrite($guid, $step, $lazyTime);
if (empty($step)) { if (empty($step)) {
return true; // 等待下次写入 return true; // 等待下次写入
} elseif ($step < 0) {
$step = '-' . $step;
} }
} }
return $this->setField($field, ['exp', $field . '+' . $step]); return $this->setField($field, ['exp', $field . '+' . $step]);
@@ -721,7 +719,7 @@ class Model
*/ */
public function setDec($field, $step = 1, $lazyTime = 0) public function setDec($field, $step = 1, $lazyTime = 0)
{ {
$condition = $this->options['where']; $condition = !empty($this->options['where']) ? $this->options['where'] : [];
if (empty($condition)) { if (empty($condition)) {
// 没有条件不做任何更新 // 没有条件不做任何更新
throw new Exception('no data to update'); throw new Exception('no data to update');
@@ -732,8 +730,6 @@ class Model
$step = $this->lazyWrite($guid, -$step, $lazyTime); $step = $this->lazyWrite($guid, -$step, $lazyTime);
if (empty($step)) { if (empty($step)) {
return true; // 等待下次写入 return true; // 等待下次写入
} elseif ($step > 0) {
$step = '-' . $step;
} }
} }
return $this->setField($field, ['exp', $field . '-' . $step]); return $this->setField($field, ['exp', $field . '-' . $step]);
@@ -1036,7 +1032,8 @@ class Model
* @param array $value 子字段值 * @param array $value 子字段值
* @return boolean * @return boolean
*/ */
protected function fieldValidate($name, $rule, &$data, $options = [], $key = null, $value = null) { protected function fieldValidate($name, $rule, &$data, $options = [], $key = null, $value = null)
{
if (is_null($key)) { if (is_null($key)) {
$key = $name; $key = $name;
} }
@@ -1341,7 +1338,7 @@ class Model
$result = false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options); $result = false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options);
break; break;
case 'confirm': case 'confirm':
$result = $value == $this->getDataValue($data, $rule); $result = $this->getDataValue($data, $rule) == $value;
break; break;
case 'in': case 'in':
case 'notin': case 'notin':

View File

@@ -52,10 +52,13 @@ class langTest extends \PHPUnit_Framework_TestCase
Config::set('lang_list', ['zh-cn', 'zh-tw']); Config::set('lang_list', ['zh-cn', 'zh-tw']);
Lang::set('hello', '欢迎', 'zh-cn'); Lang::set('hello', '欢迎', 'zh-cn');
Lang::set('hello', '歡迎', 'zh-tw'); Lang::set('hello', '歡迎', 'zh-tw');
/*
Config::set('lang_detect_var', 'lang');
Config::set('lang_cookie_var', 'think_cookie');
$_GET['lang'] = 'zh-tw'; $_GET['lang'] = 'zh-tw';
Lang::detect(); Lang::detect();
$this->assertEquals('歡迎',Lang::get('hello') );*/ $this->assertEquals('歡迎', Lang::get('hello'));
$_GET['lang'] = 'zh-cn'; $_GET['lang'] = 'zh-cn';
Lang::detect(); Lang::detect();