diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 348af78..49ef95a 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -46,9 +46,9 @@ class Test extends Command // $this->info('全部下架'); // exit(); // 1-7 11 -// $shop = Shop::query()->find(11); -// $business = BusinessFactory::init()->make($shop->plat_id); -// $business->setShop($shop); + $shop = Shop::query()->find(1); + $business = BusinessFactory::init()->make($shop->plat_id); + $business->setShop($shop); // 下载商品列表 // $business->downloadGoodsListAndBind(); @@ -59,9 +59,9 @@ class Test extends Command // $business->incrQuantity(1); // 订单下载 -// $beginTime = DateTimeUtils::getMicroTime('2022-08-23 00:00:00'); -// $endTime = DateTimeUtils::getMicroTime('2022-08-24 00:00:00'); -// $business->downloadOrdersAndSave($beginTime, $endTime); + $beginTime = DateTimeUtils::getMicroTime('2022-08-30 19:17:03'); + $endTime = DateTimeUtils::getMicroTime('2022-08-30 19:19:03'); + $business->downloadOrdersAndSave($beginTime, $endTime); // $shops = Shop::query()->where('status', 1)->get(); // $that = $this; diff --git a/app/Events/BusinessOrdersUpdate.php b/app/Events/BusinessOrdersUpdate.php index c4025e2..e19e304 100644 --- a/app/Events/BusinessOrdersUpdate.php +++ b/app/Events/BusinessOrdersUpdate.php @@ -11,6 +11,7 @@ use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Log; class BusinessOrdersUpdate { @@ -42,6 +43,7 @@ class BusinessOrdersUpdate }) ->first(); } catch (\Exception $e) { + Log::error('事件库存更新失败: ' . $e->getMessage()); return false; } if ($this->goodsSku) { diff --git a/app/Listeners/UpdateBusinessGoodsStock.php b/app/Listeners/UpdateBusinessGoodsStock.php index 540a2e6..e34380f 100644 --- a/app/Listeners/UpdateBusinessGoodsStock.php +++ b/app/Listeners/UpdateBusinessGoodsStock.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use App\Events\BusinessOrdersUpdate; use App\Jobs\BusinessGoodsSkuIncrQuantity; +use Illuminate\Support\Facades\Log as LogFile; class UpdateBusinessGoodsStock implements ShouldQueue { @@ -50,6 +51,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue } $shops = Shop::query()->where('id', '<>', $event->businessOrderItem['shop_id'])->whereNotIn('status', [0, 3])->get(['id', 'plat_id']); if (empty($shops)) { + LogFile::info('可操作店铺为空'); return; } diff --git a/app/Services/Business/BusinessClient.php b/app/Services/Business/BusinessClient.php index dde01f6..d0be26f 100644 --- a/app/Services/Business/BusinessClient.php +++ b/app/Services/Business/BusinessClient.php @@ -44,6 +44,8 @@ abstract class BusinessClient $orderRecord->update($order); } foreach ($order['sub_order_list'] as $item) { + $item['update_time'] = $item['updated_at']; + unset($item['updated_at']); $item['shop_id'] = $shopId; $orderItem = BusinessOrderItem::firstOrNew(['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], $item); $num = 0; @@ -141,21 +143,19 @@ abstract class BusinessClient $res = (new Client())->request($method, $url, $headers); $size = $res->getBody()->getSize(); $res = json_decode($res->getBody()->getContents(), true); - if (!in_array($params['type'], ['pdd.ktt.increment.order.query', 'pdd.ktt.order.list'], true)) { - $log = new Log(); - $log->module = 'plat'; - $log->action = $method; - $log->target_type = $this->getShop()->plat_id . '--' . $this->getShop()->name; - $log->target_id = $this->getShop()->id; - $log->target_field = $params['type']; - $log->user_id = Auth::id() ?? 999; - if ($size < 64000) { - $log->message = json_encode($res, 256); - } - if ('pdd.ktt.goods.incr.quantity' === $params['type']) { - $log->message .= json_encode($params, 256); - } - $log->save(); + $log = new Log(); + $log->module = 'plat'; + $log->action = $method; + $log->target_type = $this->getShop()->plat_id . '--' . $this->getShop()->name; + $log->target_id = $this->getShop()->id; + $log->target_field = $params['type']; + $log->user_id = Auth::id() ?? 999; + if ($size < 48000) { + $log->message = json_encode($res, 256) . '=====' . json_encode($params, 256); + } + $log->save(); + if (isset($res['error_response'])) { + throw new \RuntimeException($res['error_response']['error_msg']); } return $res; diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 8b11707..5c953a1 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -5,6 +5,7 @@ namespace App\Services\Business\KuaiTuanTuan; use App\Models\BusinessGoodsSku; use App\Models\GoodsSku; use App\Services\Business\BusinessClient; +use Illuminate\Support\Facades\Log; class KuaiTuanTuan extends BusinessClient { diff --git a/database/migrations/2022_08_05_093658_create_business_order_items_table.php b/database/migrations/2022_08_05_093658_create_business_order_items_table.php index e4bc837..f5ce467 100644 --- a/database/migrations/2022_08_05_093658_create_business_order_items_table.php +++ b/database/migrations/2022_08_05_093658_create_business_order_items_table.php @@ -38,6 +38,7 @@ class CreateBusinessOrderItemsTable extends Migration $table->bigInteger('theoretically_refund_amount')->nullable(); $table->string('thumb_url')->nullable(); $table->integer('verification_number')->nullable(); + $table->bigInteger('update_time')->nullable(); $table->timestamps(); // 索引 $table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']);