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