Commit 88e10852 authored by rlgy's avatar rlgy

bugfixed

parent f4fa051f
...@@ -78,7 +78,12 @@ class Coin extends BaseActiveRecord ...@@ -78,7 +78,12 @@ class Coin extends BaseActiveRecord
*/ */
public function addOne($params) public function addOne($params)
{ {
return $this->realWrite($params); $this->setAttributes($params, false);
try {
return (bool)$this->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
} }
/** /**
...@@ -86,23 +91,12 @@ class Coin extends BaseActiveRecord ...@@ -86,23 +91,12 @@ class Coin extends BaseActiveRecord
*/ */
public function updateOne($params) public function updateOne($params)
{ {
return $this->realWrite($params); if (isset($params['id']) && !empty($params['id'])) {
}
protected function realWrite($params)
{
$params = array_filter($params, function ($value) {
return $value;
});
if (isset($params['id'])) {
$coin = self::findOne(['id' => $params['id']]); $coin = self::findOne(['id' => $params['id']]);
if ($coin === null) { if ($coin === null) {
return ['code' => 1, 'msg' => '币种不存在']; return ['code' => 1, 'msg' => '币种不存在'];
} }
unset($params['id']); unset($params['id']);
} else {
$coin = self::findOne(['name' => $params['name']]);
!$coin && $coin = $this;
} }
$coin->setAttributes($params, false); $coin->setAttributes($params, false);
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment