From d8373b8fc78eec36fd71d416ca5792de14d820e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Mon, 8 Aug 2022 15:05:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E6=8E=A5=E5=8F=A3=E8=AF=B7?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Business/BusinessClient.php | 41 +++++++++++-------- .../Business/KuaiTuanTuan/KuaiTuanTuan.php | 16 ++------ app/Services/Business/MiaoXuan/Goods.php | 13 +++--- app/Services/Business/MiaoXuan/MiaoXuan.php | 11 +---- composer.json | 1 + composer.lock | 5 ++- 6 files changed, 41 insertions(+), 46 deletions(-) diff --git a/app/Services/Business/BusinessClient.php b/app/Services/Business/BusinessClient.php index cbc6eac..af1c81d 100644 --- a/app/Services/Business/BusinessClient.php +++ b/app/Services/Business/BusinessClient.php @@ -10,6 +10,7 @@ abstract class BusinessClient protected $redirectUri = 'http://erp.chutang66.com/callback'; protected $code; protected $shop; + protected $skuId = 0; abstract public function auth(); @@ -51,39 +52,47 @@ abstract class BusinessClient return $this->shop; } - protected function setCode($code) + public function setCode($code) { $this->code = $code; return $this; } - protected function getCode() + public function getCode() { return $this->code; } + public function setSkuId($skuId) + { + $this->skuId = $skuId; + + return $this; + } + + public function getSkuId() + { + return $this->skuId; + } + public function formDataPostRequest($url, $params) { $headers = [ - 'headers' => ['Content-type' => 'multipart/form-data;charset=UTF-8'], + 'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'], 'form_params' => $params ]; $res = (new Client())->request('POST', $url, $headers); $res = json_decode($res->getBody()->getContents(), true); - if (isset($res['error_response'])) { - $log = new Log(); - $log->module = 'plat'; - $log->action = 'POST'; - $log->target_type = 'kuaituantuan'; - $log->target_id = 0; - $log->target_field = '更新库存'; - $log->user_id = 1; - $log->message = json_encode($res, 256); - $log->save(); - - throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']); - } + $log = new Log(); + $log->module = 'plat'; + $log->action = 'POST'; + $log->target_type = $this->shop->plat_id; + $log->target_id = $this->skuId; + $log->target_field = $params['type']; + $log->user_id = 1; + $log->message = json_encode($res, 256); + $log->save(); return $res; } diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 979be48..e63da0c 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -2,7 +2,6 @@ namespace App\Services\Business\KuaiTuanTuan; -use App\Listeners\BindBusinessGoods; use App\Models\BusinessGoodsSku; use App\Models\GoodsSku; use App\Services\Business\BusinessClient; @@ -40,7 +39,7 @@ class KuaiTuanTuan extends BusinessClient public function downloadGoods($page = 1) { [$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page); - $res = $this->formDataPostRequest($type, $appendParams); + $res = $this->doRequest($type, $appendParams); $goods = $res['ktt_goods_query_list_response']['goods_list']; $this->bindGoods($goods); $pageNum = ceil($res['total'] / $appendParams['size']); @@ -59,16 +58,7 @@ class KuaiTuanTuan extends BusinessClient $goodsSku = GoodsSku::query()->find($skuId); $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']); [$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id); - $this->formDataPostRequest($type, $appendParams); - $log = new Log(); - $log->module = 'plat'; - $log->action = 'POST'; - $log->target_type = 'kuaituantuan'; - $log->target_id = 0; - $log->target_field = $type; - $log->user_id = 1; - $log->message = 'success'; - $log->save(); + $this->doRequest($type, $appendParams); } public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') @@ -78,7 +68,7 @@ class KuaiTuanTuan extends BusinessClient } else { [$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $activityNo); } - $res = $this->formDataPostRequest($type, $appendParams); + $res = $this->doRequest($type, $appendParams); return $res['ktt_order_list_response']['order_list']; diff --git a/app/Services/Business/MiaoXuan/Goods.php b/app/Services/Business/MiaoXuan/Goods.php index 06ceddf..8276fa6 100644 --- a/app/Services/Business/MiaoXuan/Goods.php +++ b/app/Services/Business/MiaoXuan/Goods.php @@ -19,11 +19,14 @@ class Goods public static function incrQuantity($shopId, $quantity, $businessGoods) { return [ - 'stock' => $quantity, - 'business_sku_id' => $businessGoods['sku_id'], - 'business_goods_id' => $businessGoods['goods_id'], - 'erp_shop_id' => $shopId, - 'erp_sku_id' => $businessGoods['external_sku_id'] + 'data' => [ + 'stock' => $quantity, + 'business_sku_id' => $businessGoods['sku_id'], + 'business_goods_id' => $businessGoods['goods_id'], + 'erp_shop_id' => $shopId, + 'erp_sku_id' => $businessGoods['external_sku_id'], + ], + 'type' => '更新库存', ]; } } diff --git a/app/Services/Business/MiaoXuan/MiaoXuan.php b/app/Services/Business/MiaoXuan/MiaoXuan.php index 3415a33..300b967 100644 --- a/app/Services/Business/MiaoXuan/MiaoXuan.php +++ b/app/Services/Business/MiaoXuan/MiaoXuan.php @@ -29,17 +29,8 @@ class MiaoXuan extends BusinessClient $goodsSku = GoodsSku::query()->find($skuId); $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id', 'external_sku_id'])->toArray(); $appendParams = Goods::incrQuantity($this->shop->id, $goodsSku->stock, $business); - $url = ''; // http://shop.chutang66.com/miaoxuan/stock + $url = 'http://shop.chutang66.com/miaoxuan/stock'; $this->formDataPostRequest($url, $appendParams); - $log = new Log(); - $log->module = 'plat'; - $log->action = 'POST'; - $log->target_type = 'miaoxuan'; - $log->target_id = 0; - $log->target_field = '更新库存'; - $log->user_id = 1; - $log->message = 'success'; - $log->save(); } public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') diff --git a/composer.json b/composer.json index d12ec93..979cd8b 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^7.2.5|^8.0", + "ext-json": "^1.7", "aliyuncs/oss-sdk-php": "^2.5", "beyondcode/laravel-websockets": "^1.13", "fideloper/proxy": "^4.4", diff --git a/composer.lock b/composer.lock index 9b5df2a..1e34c06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0d3d2fbbec4c9922fb38612b6fa05ac0", + "content-hash": "5a01163bdf570af5226c567ad02f45d7", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -9109,7 +9109,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.2.5|^8.0" + "php": "^7.2.5|^8.0", + "ext-json": "^1.7" }, "platform-dev": [], "plugin-api-version": "2.3.0"