You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Http\Controllers\Api;
use App\Models\Order;use App\Models\OrderProductItem;use App\Models\Product;
/** * 仅用于测试 * Class TController * @package App\Http\Controllers\Api */class TestController{ public function index() { //test
$ids = Order::orderBy('id')->get(['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 ''; }}
|