初始化仓库
This commit is contained in:
66
common/services/JacErpService.php
Normal file
66
common/services/JacErpService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace common\services;
|
||||
|
||||
use common\helpers\FuncHelper;
|
||||
use EasyWeChat\Factory;
|
||||
use GuzzleHttp\Client;
|
||||
use yii\base\Exception;
|
||||
use yii\helpers\Json;
|
||||
|
||||
class JacErpService
|
||||
{
|
||||
private static $instance = null;
|
||||
public $config;
|
||||
protected static $guzzleOptions = ['verify' => false];
|
||||
|
||||
private function __clone()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function __construct($userid)
|
||||
{
|
||||
$config = \Yii::$app->params['jac_erp'];
|
||||
|
||||
// ... 在应用配置之前初始化
|
||||
if(!$config['secret']){
|
||||
throw new \Exception('江奥川ERP参数配置错误');
|
||||
}
|
||||
if($userid){
|
||||
$config['userid'] = $userid;
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
|
||||
public static function getInstance($userid)
|
||||
{
|
||||
if(empty(self::$instance)){
|
||||
self::$instance = new self($userid);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
public function syncOrder($params){
|
||||
\Yii::info(__METHOD__."——同步订单至江奥川erp接口地址: ".$this->config['url'].'/tis-server/api/addTisApplyMaster');
|
||||
$url = $this->config['url'].'/tis-server/api/addTisApplyMaster';
|
||||
$params['hospital_code'] = $this->config['userid'];
|
||||
$params['apply_no'] = time().rand(100,999);
|
||||
|
||||
$response = (new Client(['http_errors' => false]))->post(
|
||||
$url,
|
||||
[
|
||||
'headers' => ['Content-Type' => 'application/json', 'userid' => $this->config['userid'], 'secret' => $this->config['secret']],
|
||||
\GuzzleHttp\RequestOptions::JSON =>$params
|
||||
]
|
||||
);
|
||||
$result = json_decode($response->getBody(),true);
|
||||
if ($result['code']) {
|
||||
throw new Exception($result['message']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user