mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
feat: #10000 接口请优化修改
This commit is contained in:
parent
7bd32293a6
commit
d8373b8fc7
@ -10,6 +10,7 @@ abstract class BusinessClient
|
|||||||
protected $redirectUri = 'http://erp.chutang66.com/callback';
|
protected $redirectUri = 'http://erp.chutang66.com/callback';
|
||||||
protected $code;
|
protected $code;
|
||||||
protected $shop;
|
protected $shop;
|
||||||
|
protected $skuId = 0;
|
||||||
|
|
||||||
abstract public function auth();
|
abstract public function auth();
|
||||||
|
|
||||||
@ -51,39 +52,47 @@ abstract class BusinessClient
|
|||||||
return $this->shop;
|
return $this->shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setCode($code)
|
public function setCode($code)
|
||||||
{
|
{
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCode()
|
public function getCode()
|
||||||
{
|
{
|
||||||
return $this->code;
|
return $this->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSkuId($skuId)
|
||||||
|
{
|
||||||
|
$this->skuId = $skuId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSkuId()
|
||||||
|
{
|
||||||
|
return $this->skuId;
|
||||||
|
}
|
||||||
|
|
||||||
public function formDataPostRequest($url, $params)
|
public function formDataPostRequest($url, $params)
|
||||||
{
|
{
|
||||||
$headers = [
|
$headers = [
|
||||||
'headers' => ['Content-type' => 'multipart/form-data;charset=UTF-8'],
|
'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'],
|
||||||
'form_params' => $params
|
'form_params' => $params
|
||||||
];
|
];
|
||||||
$res = (new Client())->request('POST', $url, $headers);
|
$res = (new Client())->request('POST', $url, $headers);
|
||||||
$res = json_decode($res->getBody()->getContents(), true);
|
$res = json_decode($res->getBody()->getContents(), true);
|
||||||
if (isset($res['error_response'])) {
|
$log = new Log();
|
||||||
$log = new Log();
|
$log->module = 'plat';
|
||||||
$log->module = 'plat';
|
$log->action = 'POST';
|
||||||
$log->action = 'POST';
|
$log->target_type = $this->shop->plat_id;
|
||||||
$log->target_type = 'kuaituantuan';
|
$log->target_id = $this->skuId;
|
||||||
$log->target_id = 0;
|
$log->target_field = $params['type'];
|
||||||
$log->target_field = '更新库存';
|
$log->user_id = 1;
|
||||||
$log->user_id = 1;
|
$log->message = json_encode($res, 256);
|
||||||
$log->message = json_encode($res, 256);
|
$log->save();
|
||||||
$log->save();
|
|
||||||
|
|
||||||
throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Services\Business\KuaiTuanTuan;
|
namespace App\Services\Business\KuaiTuanTuan;
|
||||||
|
|
||||||
use App\Listeners\BindBusinessGoods;
|
|
||||||
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;
|
||||||
@ -40,7 +39,7 @@ class KuaiTuanTuan extends BusinessClient
|
|||||||
public function downloadGoods($page = 1)
|
public function downloadGoods($page = 1)
|
||||||
{
|
{
|
||||||
[$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page);
|
[$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'];
|
$goods = $res['ktt_goods_query_list_response']['goods_list'];
|
||||||
$this->bindGoods($goods);
|
$this->bindGoods($goods);
|
||||||
$pageNum = ceil($res['total'] / $appendParams['size']);
|
$pageNum = ceil($res['total'] / $appendParams['size']);
|
||||||
@ -59,16 +58,7 @@ class KuaiTuanTuan extends BusinessClient
|
|||||||
$goodsSku = GoodsSku::query()->find($skuId);
|
$goodsSku = GoodsSku::query()->find($skuId);
|
||||||
$business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']);
|
$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);
|
[$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id);
|
||||||
$this->formDataPostRequest($type, $appendParams);
|
$this->doRequest($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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default')
|
public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default')
|
||||||
@ -78,7 +68,7 @@ class KuaiTuanTuan extends BusinessClient
|
|||||||
} else {
|
} else {
|
||||||
[$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $activityNo);
|
[$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'];
|
return $res['ktt_order_list_response']['order_list'];
|
||||||
|
|||||||
@ -19,11 +19,14 @@ class Goods
|
|||||||
public static function incrQuantity($shopId, $quantity, $businessGoods)
|
public static function incrQuantity($shopId, $quantity, $businessGoods)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'stock' => $quantity,
|
'data' => [
|
||||||
'business_sku_id' => $businessGoods['sku_id'],
|
'stock' => $quantity,
|
||||||
'business_goods_id' => $businessGoods['goods_id'],
|
'business_sku_id' => $businessGoods['sku_id'],
|
||||||
'erp_shop_id' => $shopId,
|
'business_goods_id' => $businessGoods['goods_id'],
|
||||||
'erp_sku_id' => $businessGoods['external_sku_id']
|
'erp_shop_id' => $shopId,
|
||||||
|
'erp_sku_id' => $businessGoods['external_sku_id'],
|
||||||
|
],
|
||||||
|
'type' => '更新库存',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,17 +29,8 @@ class MiaoXuan extends BusinessClient
|
|||||||
$goodsSku = GoodsSku::query()->find($skuId);
|
$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();
|
$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);
|
$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);
|
$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')
|
public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default')
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5|^8.0",
|
"php": "^7.2.5|^8.0",
|
||||||
|
"ext-json": "^1.7",
|
||||||
"aliyuncs/oss-sdk-php": "^2.5",
|
"aliyuncs/oss-sdk-php": "^2.5",
|
||||||
"beyondcode/laravel-websockets": "^1.13",
|
"beyondcode/laravel-websockets": "^1.13",
|
||||||
"fideloper/proxy": "^4.4",
|
"fideloper/proxy": "^4.4",
|
||||||
|
|||||||
5
composer.lock
generated
5
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "0d3d2fbbec4c9922fb38612b6fa05ac0",
|
"content-hash": "5a01163bdf570af5226c567ad02f45d7",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aliyuncs/oss-sdk-php",
|
"name": "aliyuncs/oss-sdk-php",
|
||||||
@ -9109,7 +9109,8 @@
|
|||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "^7.2.5|^8.0"
|
"php": "^7.2.5|^8.0",
|
||||||
|
"ext-json": "^1.7"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.3.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user