访问轻易云官网

自定义数据加工厂,源平台队列插入前 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'
                ];
            }
        }
    }
}
说点什么吧...