mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
91 lines
2.1 KiB
PHP
91 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Business;
|
|
use App\Models\Log;
|
|
use App\Models\Shop;
|
|
use GuzzleHttp\Client;
|
|
|
|
abstract class BusinessClient
|
|
{
|
|
protected $redirectUri = 'http://erp.chutang66.com/callback';
|
|
protected $code;
|
|
protected $shop;
|
|
|
|
abstract public function auth();
|
|
|
|
abstract public function downloadGoods();
|
|
|
|
abstract public function bindGoods($goods);
|
|
|
|
abstract public function incrQuantity($skuId);
|
|
|
|
abstract public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default');
|
|
|
|
abstract public function saveOrders($orders);
|
|
|
|
public function authCallback($code, $shopId)
|
|
{
|
|
$this->setCode($code);
|
|
$this->setShop($shopId);
|
|
$this->auth();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setShopWithId($shopId)
|
|
{
|
|
$this->shop = Shop::query()->find($shopId);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setShop(Shop $shop)
|
|
{
|
|
$this->shop = $shop;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getShop()
|
|
{
|
|
return $this->shop;
|
|
}
|
|
|
|
protected function setCode($code)
|
|
{
|
|
$this->code = $code;
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function getCode()
|
|
{
|
|
return $this->code;
|
|
}
|
|
|
|
public function formDataPostRequest($url, $params)
|
|
{
|
|
$headers = [
|
|
'headers' => ['Content-type' => 'multipart/form-data;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']);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
}
|