承接 bfatoms/imex 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bfatoms/imex

Composer 安装命令:

composer require bfatoms/imex

包简介

a laravel package for importing and exporting data

README 文档

README

DATA IS PRICELESS

===============

Installation

composer require bfatoms/imex

Publish Config

php artisan vendor:publish bfatoms/imex

Import Documentation

Update Or Create

currently the importer uses the updateOrCreate() model function of laravel, the syntax for finding a certain field is

http://example.com/api/related-products/import?find=product_id,related_product_type_id,related_product_id

the query string above will produce the query below:

Product::updateOrCreate([
    'related_product_id' => 'id in csv or parsed from the database',
    'related_product_type_id' => 'id in csv or parsed from the database',
    'product_id' => 'id in csv or parsed from the database'
],[
    array data parsed from csv or database
]);

Simplest Import

By default after installation you may import a file immediately by visiting this route

api/{model}/import

product_prices.csv

product_id description price
10000001 Lollipop $2000
10000002 Ice Cream $120
10000003 Choco Robot $100
$guzzle->post("http://example.com/api/products/import", ["file" => "product_prices.csv"]);

Complex import:

Sometimes a client hands you a list of products with related products for upselling or cross selling, in database you create something like so.

Database Table: related_products

product_id related_product_id
10000001 10000002

and you receive a file that looks like below

related_products.csv

product_code related_product_code
000-AAA-001 000-AAA-002
000-AAA-001 000-AAA-003
000-AAA-003 000-AAA-004

Problem: you wanted to find all product_code from a table and convert it to its product_id

Solution: Query Params

Legend:
column[field_name_in_csv][model]=ModelInSystem
column[field_name_in_csv][find][field_in_model]=file_data
column[field_name_in_csv][find][organization_id]=b8f7b594-f50d-454f-9b6c-7067b34d3391
column[field_name_in_csv][return]=ReturnSomethingFromModelLikeID
column[field_name_in_csv][field]=service_id

ex. for above related_products.csv

column[product_code][model]=Product
column[product_code][find][product_code]=file_data
column[product_code][find][organization_id]=b8f7b594-f50d-454f-9b6c-7067b34d3391
column[product_code][return]=id
column[product_code][field]=product_id

column[related_product_code][model]=Product
column[related_product_code][find][product_code]=file_data
column[related_product_code][find][organization_id]=b8f7b594-f50d-454f-9b6c-7067b34d3391
column[related_product_code][return]=id
column[related_product_code][field]=related_product_id

Explanation:

the product_code will be converted to product_id because of the query string column[product_code][field]=product_id

the related_product_code will be converted to related_product_id because of the query string column[related_product_code][field]=related_product_id

now you satisfy the field names of your table related_products

then in the database the other column data will create a query like so:

Product::where([
    'product_code' => '000-AAA-001',
    'organization_id'=> 'b8f7b594-f50d-454f-9b6c-7067b34d3391'
])->select('id')->first();

the word file_data is constant meaning, it will get the data from the csv

How to use the Custom Import Service

The import service accepts array for parsing

use BfAtoms\Imex\Import;

class Test{
    public function import()
    {
        $data = [
            'product_id' => 1,
            'product_code' => '000-AAA-0001'
        ];
        $import = new Import();
        $import->model('Product');
        $import->import($data);
    }
}

bfatoms/imex 适用场景与选型建议

bfatoms/imex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.94k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bfatoms/imex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bfatoms/imex 我们能提供哪些服务?
定制开发 / 二次开发

基于 bfatoms/imex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.94k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-20