|
|
@@ -15,17 +15,22 @@ class ValueController
|
|
|
{
|
|
|
/**
|
|
|
* 查询指定实体的所有属性值
|
|
|
- * GET /eav/value?entity_id=123
|
|
|
+ * GET /eav/value?entity_id=123&entity_type_id=1
|
|
|
*/
|
|
|
public function index(Request $request, EvaValueEntity $entity): Response
|
|
|
{
|
|
|
$entityId = $request->get('entity_id/d');
|
|
|
+ $entityTypeId = $request->get('entity_type_id/d');
|
|
|
if (!$entityId) {
|
|
|
return error_response('缺少实体ID');
|
|
|
}
|
|
|
+ if (!$entityTypeId) {
|
|
|
+ return error_response('缺少实体类型ID');
|
|
|
+ }
|
|
|
// 查询该实体的所有属性值
|
|
|
$list = $entity->where([
|
|
|
- 'entity_id' => $entityId
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'entity_type_id' => $entityTypeId,
|
|
|
])->select();
|
|
|
return success_response($list);
|
|
|
}
|
|
|
@@ -47,6 +52,7 @@ class ValueController
|
|
|
foreach ($data as $item) {
|
|
|
if (
|
|
|
empty($item['entity_id']) ||
|
|
|
+ empty($item['entity_type_id']) ||
|
|
|
empty($item['attribute_id']) ||
|
|
|
!isset($item['value'])
|
|
|
) {
|
|
|
@@ -59,6 +65,7 @@ class ValueController
|
|
|
}
|
|
|
$saveData = [
|
|
|
'entity_id' => $item['entity_id'],
|
|
|
+ 'entity_type_id' => $item['entity_type_id'],
|
|
|
'attribute_id' => $item['attribute_id'],
|
|
|
];
|
|
|
switch ($attr->backend_type) {
|
|
|
@@ -78,6 +85,7 @@ class ValueController
|
|
|
// 先查找是否已存在,存在则更新,否则新增
|
|
|
$exist = $entity->where([
|
|
|
'entity_id' => $item['entity_id'],
|
|
|
+ 'entity_type_id' => $item['entity_type_id'],
|
|
|
'attribute_id' => $item['attribute_id']
|
|
|
])->find();
|
|
|
if ($exist) {
|
|
|
@@ -91,15 +99,16 @@ class ValueController
|
|
|
|
|
|
/**
|
|
|
* 删除指定实体的所有属性值
|
|
|
- * DELETE /eav/value?entity_id=123
|
|
|
+ * DELETE /eav/value?entity_id=123&entity_type_id=1
|
|
|
*/
|
|
|
public function delete(Request $request, EvaValueEntity $entity): Response
|
|
|
{
|
|
|
$entityId = $request->get('entity_id/d');
|
|
|
- if (!$entityId) {
|
|
|
+ $entityTypeId = $request->get('entity_type_id/d');
|
|
|
+ if (!$entityId || !$entityTypeId) {
|
|
|
return error_response('参数缺失');
|
|
|
}
|
|
|
- $entity->where(['entity_id' => $entityId])->delete();
|
|
|
+ $entity->where(['entity_id' => $entityId, 'entity_type_id' => $entityTypeId])->delete();
|
|
|
return success_response('删除成功');
|
|
|
}
|
|
|
-}
|
|
|
+}
|