From 29425379f41d6466e974b5a2313121a9e9966688 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 1 Sep 2021 09:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=93=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/TestController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/TestController.php b/app/Http/Controllers/Api/TestController.php index f2e17b1..4e4d5ed 100644 --- a/app/Http/Controllers/Api/TestController.php +++ b/app/Http/Controllers/Api/TestController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers\Api; +use App\Models\Order; +use App\Models\OrderProductItem; use App\Models\Product; /** @@ -14,6 +16,19 @@ class TestController public function index() { //test - return Product::query()->whereIn('id', explode(',', '1,2,3,4,5,6'))->get(['id AS product_id', 'supplier_id']); + $ids = Order::all(['id AS order_id', 'product_ids', 'agent_id', 'agent_product_id']); + foreach ($ids as $v) { + $item = Product::query()->whereIn('id', explode(',', $v['product_ids'])) + ->orderBy('id')->get(['id AS product_id', 'supplier_id'])->toArray(); + foreach ($item as $v2) { + if (!OrderProductItem::query()->where(['order_id' => $v['order_id'], 'product_id' => $v2['product_id']])->exists()) { + $v2['order_id'] = $v['order_id']; + $v2['agent_id'] = $v['agent_id']; + $v2['agent_product_id'] = $v['agent_product_id']; + OrderProductItem::query()->create($v2); + } + } + } + return ''; } }