feat: #10000 代码优化

This commit is contained in:
赵世界 2022-08-30 23:11:48 +08:00
parent a941fe6a1a
commit 16e120fa1f
6 changed files with 27 additions and 21 deletions

View File

@ -46,9 +46,9 @@ class Test extends Command
// $this->info('全部下架'); // $this->info('全部下架');
// exit(); // exit();
// 1-7 11 // 1-7 11
// $shop = Shop::query()->find(11); $shop = Shop::query()->find(1);
// $business = BusinessFactory::init()->make($shop->plat_id); $business = BusinessFactory::init()->make($shop->plat_id);
// $business->setShop($shop); $business->setShop($shop);
// 下载商品列表 // 下载商品列表
// $business->downloadGoodsListAndBind(); // $business->downloadGoodsListAndBind();
@ -59,9 +59,9 @@ class Test extends Command
// $business->incrQuantity(1); // $business->incrQuantity(1);
// 订单下载 // 订单下载
// $beginTime = DateTimeUtils::getMicroTime('2022-08-23 00:00:00'); $beginTime = DateTimeUtils::getMicroTime('2022-08-30 19:17:03');
// $endTime = DateTimeUtils::getMicroTime('2022-08-24 00:00:00'); $endTime = DateTimeUtils::getMicroTime('2022-08-30 19:19:03');
// $business->downloadOrdersAndSave($beginTime, $endTime); $business->downloadOrdersAndSave($beginTime, $endTime);
// $shops = Shop::query()->where('status', 1)->get(); // $shops = Shop::query()->where('status', 1)->get();
// $that = $this; // $that = $this;

View File

@ -11,6 +11,7 @@ use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class BusinessOrdersUpdate class BusinessOrdersUpdate
{ {
@ -42,6 +43,7 @@ class BusinessOrdersUpdate
}) })
->first(); ->first();
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('事件库存更新失败: ' . $e->getMessage());
return false; return false;
} }
if ($this->goodsSku) { if ($this->goodsSku) {

View File

@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use App\Events\BusinessOrdersUpdate; use App\Events\BusinessOrdersUpdate;
use App\Jobs\BusinessGoodsSkuIncrQuantity; use App\Jobs\BusinessGoodsSkuIncrQuantity;
use Illuminate\Support\Facades\Log as LogFile;
class UpdateBusinessGoodsStock implements ShouldQueue 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']); $shops = Shop::query()->where('id', '<>', $event->businessOrderItem['shop_id'])->whereNotIn('status', [0, 3])->get(['id', 'plat_id']);
if (empty($shops)) { if (empty($shops)) {
LogFile::info('可操作店铺为空');
return; return;
} }

View File

@ -44,6 +44,8 @@ abstract class BusinessClient
$orderRecord->update($order); $orderRecord->update($order);
} }
foreach ($order['sub_order_list'] as $item) { foreach ($order['sub_order_list'] as $item) {
$item['update_time'] = $item['updated_at'];
unset($item['updated_at']);
$item['shop_id'] = $shopId; $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); $orderItem = BusinessOrderItem::firstOrNew(['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], $item);
$num = 0; $num = 0;
@ -141,7 +143,6 @@ abstract class BusinessClient
$res = (new Client())->request($method, $url, $headers); $res = (new Client())->request($method, $url, $headers);
$size = $res->getBody()->getSize(); $size = $res->getBody()->getSize();
$res = json_decode($res->getBody()->getContents(), true); $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 = new Log();
$log->module = 'plat'; $log->module = 'plat';
$log->action = $method; $log->action = $method;
@ -149,13 +150,12 @@ abstract class BusinessClient
$log->target_id = $this->getShop()->id; $log->target_id = $this->getShop()->id;
$log->target_field = $params['type']; $log->target_field = $params['type'];
$log->user_id = Auth::id() ?? 999; $log->user_id = Auth::id() ?? 999;
if ($size < 64000) { if ($size < 48000) {
$log->message = json_encode($res, 256); $log->message = json_encode($res, 256) . '=====' . json_encode($params, 256);
}
if ('pdd.ktt.goods.incr.quantity' === $params['type']) {
$log->message .= json_encode($params, 256);
} }
$log->save(); $log->save();
if (isset($res['error_response'])) {
throw new \RuntimeException($res['error_response']['error_msg']);
} }
return $res; return $res;

View File

@ -5,6 +5,7 @@ namespace App\Services\Business\KuaiTuanTuan;
use App\Models\BusinessGoodsSku; use App\Models\BusinessGoodsSku;
use App\Models\GoodsSku; use App\Models\GoodsSku;
use App\Services\Business\BusinessClient; use App\Services\Business\BusinessClient;
use Illuminate\Support\Facades\Log;
class KuaiTuanTuan extends BusinessClient class KuaiTuanTuan extends BusinessClient
{ {

View File

@ -38,6 +38,7 @@ class CreateBusinessOrderItemsTable extends Migration
$table->bigInteger('theoretically_refund_amount')->nullable(); $table->bigInteger('theoretically_refund_amount')->nullable();
$table->string('thumb_url')->nullable(); $table->string('thumb_url')->nullable();
$table->integer('verification_number')->nullable(); $table->integer('verification_number')->nullable();
$table->bigInteger('update_time')->nullable();
$table->timestamps(); $table->timestamps();
// 索引 // 索引
$table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']); $table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']);