1.首先要新建一个管易商品查询的方案,把方案id记下来(方案id即浏览器连接url的后面一段字符串),后面发货单查询加工厂需要用到。

特别需要注意,含sku的,需要在商品查询的加工厂里把skus移到外面的goods_id。如果管易是多规格不适用此方案。

image.png

skuskus移到外面的goods_id示例代码(可以复制使用):

  1. <?php
  2. class AfterSourceInvoke
  3. {
  4. protected $response;
  5. protected $adapter;
  6. /**
  7. * 构造函数
  8. *
  9. * @param array $response 引用传递,调用接口返回的原始响应数组
  10. * @param Adapter:class $adapter 适配器类
  11. */
  12. public function __construct(&$response, $adapter)
  13. {
  14. $this->response = &$response;
  15. $this->adapter = $adapter;
  16. }
  17. public function run()
  18. {
  19. if ($this->response['success'] == false) {
  20. return;
  21. }
  22. $items = [];
  23. foreach ($this->response['items'] as $item) {
  24. //
  25. if(count($item['skus']) > 0){
  26. foreach($item['skus'] as $sk){
  27. $item['goods_id'] = $sk['goods_id'];
  28. $item['qeasy_remark'] = 'skus id 移到外面的goods_id, 里面的skus 暂时无用';
  29. $items[] = $item;
  30. }
  31. }else{
  32. $items[] = $item;
  33. }
  34. }
  35. $this->response['items'] = $items;
  36. }
  37. }

2.选择发货单查询2.0接口

image.png

3.特别需要注意,新版发货单只返回商品id,需要在加工厂关联查询出商品编码,,以下是加工厂示例代码,可以复制使用,复制后需要替换方案id,即$accountStrategyId = ‘f1e6ac6a-46bf-30ca-80a1-c98aa54be247’; 替换为$accountStrategyId = ‘步骤1中记录的方案id’;。

image.png

关联查询物料编码示例代码:

  1. <?php
  2. use Domain\Datahub\Instance\Storage\LogStatus;
  3. use Domain\Datahub\Instance\Storage\DataStorage;
  4. class AfterSourceInvoke
  5. {
  6. protected $response;
  7. protected $adapter;
  8. /**
  9. * 构造函数
  10. *
  11. * @param array $response 引用传递,调用接口返回的原始响应数组
  12. * @param Adapter:class $adapter 适配器类
  13. */
  14. public function __construct(&$response, $adapter)
  15. {
  16. $this->response = &$response;
  17. $this->adapter = $adapter;
  18. }
  19. /**
  20. * 工厂事件执行函数
  21. *
  22. * @return void
  23. */
  24. public function run()
  25. {
  26. if ($this->response['success'] != true) {
  27. return;
  28. }
  29. foreach ($this->response['details'] as $key=>&$col) {
  30. //$this->adapter->getLogStorage()->insertOne(['text' => 'data', 'data' => $col], LogStatus::NOTICE);
  31. $accountStrategyId = 'f1e6ac6a-46bf-30ca-80a1-c98aa54be247';//此处方案id需替换成对应组户商品查询的方案ID
  32. $storage = new DataStorage($this->adapter->strategy->lessee_id, $accountStrategyId);
  33. $where = ['content.goods_id' => ['$eq' => $col['goods_id']]];
  34. $query = $storage->find($where);
  35. $col['goods_code'] = '';
  36. if ($query) {
  37. $content = $query[0]['content'];
  38. $col['goods_code'] = $content['code'];
  39. }
  40. }
  41. }
  42. }

4.最后再根据新版接口返回的字段完成替换配置,新版接口和旧版接口有些字段不一样,特别需要留意检查,加工厂里面的符号都是要英文符号,如无特殊要求,建议直接复制文档示例做修改。(需留意源平台配置源码是否有condition过滤,或者beatFlat拍扁,或者其他函数,字段记得相应替换新版接口的;目标配置源码同理,是否有merge合并等函数,函数配置里面的字段也要相应替换成新版的字段)