|
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
|
|
namespace SixShop\Eav\Controller;
|
|
namespace SixShop\Eav\Controller;
|
|
|
|
|
|
|
|
use SixShop\Core\Request;
|
|
use SixShop\Core\Request;
|
|
|
-use SixShop\Eav\Entity\EvaValueEntity;
|
|
|
|
|
-use SixShop\Eav\Model\EvaAttributeModel;
|
|
|
|
|
|
|
+use SixShop\Eav\Entity\EavValueEntity;
|
|
|
|
|
+use SixShop\Eav\Model\EavAttributeModel;
|
|
|
use think\Response;
|
|
use think\Response;
|
|
|
|
|
|
|
|
use function SixShop\Core\error_response;
|
|
use function SixShop\Core\error_response;
|
|
@@ -17,7 +17,7 @@ class ValueController
|
|
|
* 查询指定实体的所有属性值
|
|
* 查询指定实体的所有属性值
|
|
|
* GET /eav/value?entity_id=123&entity_type_id=1
|
|
* GET /eav/value?entity_id=123&entity_type_id=1
|
|
|
*/
|
|
*/
|
|
|
- public function index(Request $request, EvaValueEntity $entity): Response
|
|
|
|
|
|
|
+ public function index(Request $request, EavValueEntity $entity): Response
|
|
|
{
|
|
{
|
|
|
$entityId = $request->get('entity_id/d');
|
|
$entityId = $request->get('entity_id/d');
|
|
|
$entityTypeId = $request->get('entity_type_id/d');
|
|
$entityTypeId = $request->get('entity_type_id/d');
|
|
@@ -31,7 +31,9 @@ class ValueController
|
|
|
$list = $entity->where([
|
|
$list = $entity->where([
|
|
|
'entity_id' => $entityId,
|
|
'entity_id' => $entityId,
|
|
|
'entity_type_id' => $entityTypeId,
|
|
'entity_type_id' => $entityTypeId,
|
|
|
- ])->select();
|
|
|
|
|
|
|
+ ])->with(['attribute' => function ($query) {
|
|
|
|
|
+ $query->with(['options']);
|
|
|
|
|
+ }])->select();
|
|
|
return success_response($list);
|
|
return success_response($list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -42,7 +44,7 @@ class ValueController
|
|
|
* { "entity_id": 123, "entity_type_id": 1, "attribute_id": 2, "value": "红色" }
|
|
* { "entity_id": 123, "entity_type_id": 1, "attribute_id": 2, "value": "红色" }
|
|
|
* ]
|
|
* ]
|
|
|
*/
|
|
*/
|
|
|
- public function save(Request $request, EvaValueEntity $entity): Response
|
|
|
|
|
|
|
+ public function save(Request $request, EavValueEntity $entity): Response
|
|
|
{
|
|
{
|
|
|
$data = $request->post();
|
|
$data = $request->post();
|
|
|
if (empty($data) || !is_array($data)) {
|
|
if (empty($data) || !is_array($data)) {
|
|
@@ -59,7 +61,7 @@ class ValueController
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
// 获取属性类型
|
|
// 获取属性类型
|
|
|
- $attr = EvaAttributeModel::find($item['attribute_id']);
|
|
|
|
|
|
|
+ $attr = EavAttributeModel::find($item['attribute_id']);
|
|
|
if (!$attr) {
|
|
if (!$attr) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -101,7 +103,7 @@ class ValueController
|
|
|
* 删除指定实体的所有属性值
|
|
* 删除指定实体的所有属性值
|
|
|
* DELETE /eav/value?entity_id=123&entity_type_id=1
|
|
* DELETE /eav/value?entity_id=123&entity_type_id=1
|
|
|
*/
|
|
*/
|
|
|
- public function delete(Request $request, EvaValueEntity $entity): Response
|
|
|
|
|
|
|
+ public function delete(Request $request, EavValueEntity $entity): Response
|
|
|
{
|
|
{
|
|
|
$entityId = $request->get('entity_id/d');
|
|
$entityId = $request->get('entity_id/d');
|
|
|
$entityTypeId = $request->get('entity_type_id/d');
|
|
$entityTypeId = $request->get('entity_type_id/d');
|