|
@@ -260,6 +260,35 @@ class Base {
|
|
|
['_result' => ['code' => Response::DO_SUCCESS, 'msg' => '添加成功', 'body' => $res]]
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除指定数据
|
|
|
+ *
|
|
|
+ * @return false|Response
|
|
|
+ */
|
|
|
+ public function remove() {
|
|
|
+ if(!$this->properties()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $properties = [];
|
|
|
+ foreach ($this->properties() as $key => $val) {
|
|
|
+ $properties[] = $this->entity()->convertToProperty($key);
|
|
|
+ }
|
|
|
+
|
|
|
+ $valid = $this->valid($properties);
|
|
|
+ if($valid->isError()) {
|
|
|
+ return $valid;
|
|
|
+ }
|
|
|
+ $affectedRows = $this->db()->where($this->properties())->delete($this->getTable());
|
|
|
+ if($this->db()->isError()) {
|
|
|
+ return Response::FailSave(static::class .'::'. __FUNCTION__,
|
|
|
+ ['_result' => ['code' => Response::FAIL_FOR_SAVE, 'msg' => $this->db()->getMessage(), 'body' => []]
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ return Response::Success(static::class .'::'. __FUNCTION__,
|
|
|
+ ['_result' => ['code' => Response::DO_SUCCESS, 'msg' => '删除成功,总共删除了'. $affectedRows . '条记录', 'body' => $affectedRows]]
|
|
|
+ );
|
|
|
+ }
|
|
|
/**
|
|
|
* 更新
|
|
|
*
|
|
@@ -271,7 +300,6 @@ class Base {
|
|
|
if($valid->isError()) {
|
|
|
return $valid;
|
|
|
}
|
|
|
- return $this->updateFields();
|
|
|
//检查是否有重复的
|
|
|
list($uniqueWhere, $uniqueOr, $exclude, $primaryKey) = $this->condition();
|
|
|
// 检查 unique 是否已经存在相关数据
|
|
@@ -326,6 +354,12 @@ class Base {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新字段
|
|
|
+ *
|
|
|
+ * @return mixed|\Qii\Driver\Qii\Driver\Response|Response
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
public function updateFields() {
|
|
|
$properties = $this->properties();
|
|
|
$fields = $this->entity()->convertToProperties(array_keys($properties));
|