用法
模版
源平台队列插入前 BeforeSourceJobInsert
<?php
class BeforeSourceJobInsert
{
protected $response;
protected $adapter;
/**
* 构造函数
*
* @param array $response 引用传递,调用接口返回的原始响应数组
* @param Adapter:class $adapter 适配器类
*/
public function __construct(&$response, $adapter)
{
$this->response = &$response;
$this->adapter = $adapter;
}
/**
* 工厂事件执行函数
*
* @return void
*/
public function run()
{
// 如果旺店通响应code大于0,则响应失败,不对数据进行加工
if ($this->response['code'] > 0) {
return;
}
// 开始遍历 stockout_list 单据数组
foreach ($this->response['stockout_list'] as &$item) {
// 如果单据中的 post_fee 运费字段大于0
if (floatval($item['post_fee']) > 0) {
// 向details_list单据体数组追加一行分录,分录定义了五个基本对象 规格码\数量\单价\仓库\备注
$item['details_list'][] = [
'spec_code' => '2222',
'goods_count' => 1,
'price' => floatval($item['post_fee']),
'warehouse_no' => '440001',
'remark' => '运费333'
];
}
}
}
}
源平台调用后 AfterSourceInvoke
<?php
class AfterSourceInvoke
{
protected $response;
protected $adapter;
/**
* 构造函数
*
* @param array $response 引用传递,调用接口返回的原始响应数组
* @param Adapter:class $adapter 适配器类
*/
public function __construct(&$response, $adapter)
{
$this->response = &$response;
$this->adapter = $adapter;
}
public function run()
{
if ($this->response['code'] != 200) {
return;
}
foreach ($this->response['result']['data'] as &$item) {
$product = [];
$material = [];
foreach ($item['stockAssembleDetailsDto'] as $entry) {
if ($entry['inOutType'] == 107) {
$product[] = $entry;
} else {
$material[] = $entry;
}
}
$item['product'] = $product;
$item['material'] = $material;
}
}
}
目标队列生成后 AfterTargetGenerate
<?php
/**
* AfterTargetGenerate class
* 目标队列生成后加工厂
*/
class AfterTargetGenerate
{
/**
* params variable
* 目标队列生成的请求参数内容
* &值引用
* @var array
*/
protected $params = [];
/**
* ids variable
* 目标队列所关联的原始数据 ids (mongodb objectId)
* @var array
*/
protected $ids = [];
public function __construct(&$params, $ids)
{
$this->params = &$params;
$this->ids = $ids;
}
public function run()
{
$paid = 0;
foreach ($this->params['trade_list']['order_list'] as $item) {
$paid += $item['price'] * $item['num'];
}
$this->params['trade_list']['paid'] = $paid;
}
}
目标平台调用前 BeforeTargetInvoke
<?php
class BeforeTargetInvoke
{
protected $request;
protected $adapter;
protected $job;
/**
* 构造函数
*
* @param array $request 引用传递,调用接口请求参数
* @param Adapter:class $adapter 适配器类
* @param MongoDB:object $job 队列任务
*/
public function __construct(&$request, $adapter, $job)
{
$this->request = &$request;
$this->adapter = $adapter;
$this->job = $job;
}
public function run()
{
$unAuditRequest = [];
$unAuditRequest[0] = $this->request[0];
$unAuditRequest[1] = [];
$unAuditRequest[1]['CreateOrgId'] = 0;
$unAuditRequest[1]['Numbers'] = [];
$unAuditRequest[1]['Ids'] = $this->request[1]['Model'][0]['FMATERIALID'];
$unAuditRequest[1]['InterationFlags'] = '';
$unAuditRequest[1]['NetworkCtrl'] = '';
$this->adapter->getLogStorage()->insertOne(['text' => '执行反审核操作前', 'unAuditRequest' => $unAuditRequest], 1);
$res = $this->adapter->SDK->invoke('unAudit', $unAuditRequest);
$this->adapter->getLogStorage()->insertOne(['text' => '执行反审核操作后', 'unAuditRequest' => $res], 1);
}
}
目标平台调用后 AfterTargetInvoke
<?php
class AfterTargetInvoke
{
protected $response;
protected $adapter;
protected $job;
/**
* 构造函数
*
* @param array $response 引用传递,调用接口返回的原始响应数组
* @param Adapter:class $adapter 适配器类
* @param MongoDB:object $job 队列任务
*/
public function __construct(&$response, $adapter, $job)
{
$this->response = &$response;
$this->adapter = $adapter;
$this->job = $job;
}
/**
* 工厂事件执行函数
*
* @return void
*/
public function run()
{
if ($this->response['success'] !== true) {
return;
}
$storage = $this->adapter->getDataStorage();
$data = $storage->collection->findOne(['_id' => $this->job->ids[0]]);
$content = $data['content'];
$content['resultId'] = $this->response['result'];
$storage->collection->updateOne(
['_id' => $data->_id],
[
'$set' =>
[
'content' => $content
]
]
);
}
}