From 4054e2a39e9c4c64f2d92b185d830ce7272c86c5 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Wed, 11 Sep 2024 17:19:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=94=9F=E6=B4=BB=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=93=81=E8=A7=84=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsLogic.php | 37 +++++++++++++++++++ .../model/localstore/LocalStoreGoodsItem.php | 10 +++++ .../model/localstore/LocalStoreGoodsSpec.php | 15 ++++++++ .../localstore/LocalStoreGoodsSpecValue.php | 15 ++++++++ 4 files changed, 77 insertions(+) create mode 100644 app/common/model/localstore/LocalStoreGoodsItem.php create mode 100644 app/common/model/localstore/LocalStoreGoodsSpec.php create mode 100644 app/common/model/localstore/LocalStoreGoodsSpecValue.php diff --git a/app/api/logic/LocalStoreGoodsLogic.php b/app/api/logic/LocalStoreGoodsLogic.php index 1c6ff724..f75dfc79 100644 --- a/app/api/logic/LocalStoreGoodsLogic.php +++ b/app/api/logic/LocalStoreGoodsLogic.php @@ -5,6 +5,9 @@ namespace app\api\logic; use app\common\basics\Logic; use app\common\model\localstore\LocalStoreGoods; use app\common\model\localstore\LocalStoreGoodsPic; +use app\common\model\localstore\LocalStoreGoodsItem; +use app\common\model\localstore\LocalStoreGoodsSpec; +use app\common\model\localstore\LocalStoreGoodsSpecValue; use app\common\enum\LocalStoreGoodsEnum; use think\facade\Config; @@ -84,8 +87,42 @@ class LocalStoreGoodsLogic extends Logic 'price' => $form['price'], 'desc' => $form['desc'] ?? '', 'details' => $form['details'] ?? '', + 'is_multiple_spec' => !empty($form['sku']) ? 1 : 0, 'create_time' => time(), ]); + + $item = array(); + if (!empty($form['sku'])) { +// foreach ($form['sku'] as &$v) { +// foreach ($v['spec'] as &$v2) { +// $spec_id = LocalStoreGoodsSpec::insertGetId([ +// 'goods_id' => $id, +// 'name' => $v['name'] +// ]); +// +// foreach ($v2['item'] as &$v3) { +// $spec_value_id[] = LocalStoreGoodsSpecValue::insertGetId([ +// 'goods_id' => $id, +// 'spec_id' => $spec_id, +// 'value' => $v3 +// ]); +// } +// } +// } + + foreach ($form['sku']['spec'] as $k => &$v) { + $spec_id = LocalStoreGoodsSpec::insertGetId([ + 'goods_id' => $id, + 'name' => $v['name'] + ]); + $spec_value_id[] = LocalStoreGoodsSpecValue::insertGetId([ + 'goods_id' => $id, + 'spec_id' => $spec_id, + 'value' => $v['item'][$k] + ]); + dump($spec_value_id); + } + } } else if ($form['type'] === 'edit') { LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id])->update([ 'title' => $form['title'], diff --git a/app/common/model/localstore/LocalStoreGoodsItem.php b/app/common/model/localstore/LocalStoreGoodsItem.php new file mode 100644 index 00000000..b5a1b1ff --- /dev/null +++ b/app/common/model/localstore/LocalStoreGoodsItem.php @@ -0,0 +1,10 @@ +hasMany(LocalStoreGoodsPic::class, 'lsg_id'); + } +} \ No newline at end of file diff --git a/app/common/model/localstore/LocalStoreGoodsSpecValue.php b/app/common/model/localstore/LocalStoreGoodsSpecValue.php new file mode 100644 index 00000000..27e7d62f --- /dev/null +++ b/app/common/model/localstore/LocalStoreGoodsSpecValue.php @@ -0,0 +1,15 @@ +hasMany(LocalStoreGoodsPic::class, 'lsg_id'); + } +} \ No newline at end of file