当谦/phpsdk

该软件包最新版本(dev-master)没有可用的许可证信息。

phpsdk

dev-master 2021-02-03 18:50 UTC

This package is auto-updated.

Last update: 2024-09-29 05:48:57 UTC


README

安装

    composer require bizflycrm/phpsdk

Bizfly CRM

API 密钥

可以在这里获取 api 信息

  • API_KEY: 这是 Bizfly CRM 提供的 api 密钥。
  • API_SECRET: 这是 Bizfly CRM 提供的 secret 密码。
  • API_EMBED: 这是 Bizfly CRM 提供的 embed 代码。
  • PROJECT_TOKEN: 这是 My Bizfly 提供的项目 token。用于 Bizfly 的所有解决方案。可以在这里获取

初始化 Client SDK

    use BizflyCrmSdk\CrmClient;
    $config = [
        'api_key' => API_KEY,
        'api_secret' => API_SECRET,
        'api_embed' => API_EMBED,
        'project_token' => PROJECT_TOKEN,
    ];
    $client = new CrmClient($config);

获取客户对象

    $customer = $client->getTableCustomer();

获取客户列表:find()

     $customer->find([
            'limit' => 100,
            'skip' => 0,
            'select' => ["name", "created_at"],
            'output' => "default",
        ]);

根据 ID 搜索客户:find()

     $customer->find([
            'limit' => 100,
            'skip' => 0,
            'query' => [
                'id' => ['id_ban_ghi']
            ],
            'select' => ["name", "created_at"],
            'output' => "default",
        ]);

添加新客户记录:update()

    $customer->update([
            "data" => [
                [
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Nguyễn Duy Sự"
                        ],
                        [
                            "key" => "emails",
                            "value" => [
                                [
                                    "value" => "su.nguyenduy.api1@gmail.com"
                                ]
                            ]
                        ],
                        [
                            "key" => "phones",
                            "value" => [
                                [
                                    "value" => "0987654321"
                                ],
                                [
                                    "value" => "0987654322"
                                ]
                            ]
                        ]

                    ],
                ]
            ]
    ]);

根据 ID 更新客户记录:id: ''

    $customer->update([
            "data" => [
                [
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Nguyễn Duy Sự"
                        ],
                        [
                            "key" => "emails",
                            "value" => [
                                [
                                    "value" => "su.nguyenduy.api1@gmail.com"
                                ]
                            ]
                        ],
                        [
                            "key" => "phones",
                            "value" => [
                                [
                                    "value" => "0987654321"
                                ],
                                [
                                    "value" => "0987654322"
                                ]
                            ]
                        ]

                    ],
                    "id" => 'id_ban_ghi_can_update'
                ]
            ]
    ]);

更新匹配的客户记录:mapingBy: []

  • 如果记录匹配 email 和 phone,则更新旧记录
    $customer->update([
            "data" => [
                [
                    "mapingBy" => ["emails", "phones"],
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Nguyễn Duy Sự"
                        ],
                        [
                            "key" => "emails",
                            "value" => [
                                [
                                    "value" => "su.nguyenduy.api1@gmail.com"
                                ]
                            ]
                        ],
                        [
                            "key" => "phones",
                            "value" => [
                                [
                                    "value" => "0987654321"
                                ],
                                [
                                    "value" => "0987654322"
                                ]
                            ]
                        ]

                    ],
                    "id" => 'id_ban_ghi_can_update'
                ]
            ]
    ]);

获取客户表中的数据字段:struct()

    $customer->struct();

添加客户表中的数据字段:addFields()

      $customer->addFields([
           "data" => [
           "fields" => [
                   [
                       "key" => "field_1",
                       "type" => "string",
                       "label" => "Trường thứ 1",
                       "description" => "Mô tả trường thứ 1"
                   ],
                   [
                       "key" => "field_2",
                       "type" => "array-object",
                       "label" => "Trường thứ 2",
                       "description" => "Mô tả trường thứ 2"
                   ],
               ]
           ]
       ]);

获取客户表中的 '列表':getLists()

    $customer->getLists([
        'limit' => 100,
        'skip' => 0,
        'output' => "default",
        'sort' => [
            'count' => 1
        ]   
    ]);

添加客户表中的 '列表':addLists()

    $customer->addLists([
        "data" => [
            [
                "value" => "Danh sách 1"
            ],
            [
                "value" => "Danh sách 2"
            ]
        ]
    ]);

获取 Deal 对象

    $deal = $client->getTableDeal();

获取 Deal 列表:find()

     $deal->find([
        'limit' => 100,
        'skip' => 0,
        'select' => ["name", "created_at"],
        'output' => "default",
     ]);

根据 ID 搜索 Deal:find()

     $deal->find([
            'limit' => 100,
            'skip' => 0,
            'query' => [
                'id' => ['id_ban_ghi']
            ],
            'select' => ["name", "created_at"],
            'output' => "default",
        ]);

添加新 Deal 记录:update()

    $deal->update([
            "data" => [
                [
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Deal Test"
                        ],
                        [
                            "key" => "customer",
                            "value" => [
                                    [
                                        "id" => "5e967a9f84f36615d4007365"
                                    ]
                            ]
                        ],
                        [
                            "key" => "code",
                            "value" => "05182020"
                        ],  
                        [
                            "key" => "sale",
                            "value" => [
                                [
                                    "id" => "5e8ed4245adfc61f960fb793"
                                ]           
                            ]
                        ],
                        [
                             "key" => "amount",
                             "value" => 10000000
                        ],
                        [
                            "key" => "rating",
                            "value" => 90
                        ],
                    ],
                ]
            ]
    ]);

根据 ID 更新 Deal 记录:id: ''

    $deal->update([
            "data" => [
                [
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Deal Test"
                        ],
                        [
                            "key" => "customer",
                            "value" => [
                                    [
                                        "id" => "5e967a9f84f36615d4007365"
                                    ]
                            ]
                        ],
                        [
                            "key" => "code",
                            "value" => "05182020"
                        ],  
                        [
                            "key" => "sale",
                            "value" => [
                                [
                                    "id" => "5e8ed4245adfc61f960fb793"
                                ]           
                            ]
                        ],
                        [
                             "key" => "amount",
                             "value" => 10000000
                        ],
                        [
                            "key" => "rating",
                            "value" => 90
                        ],
                    ],
                    "id" => "id_ban_ghi_cap_nhat"
                ]
            ]
    ]);

更新匹配的 Deal 记录:mapingBy: []

  • 如果记录匹配 code,则更新旧记录
    $deal->update([
            "mappingBy" => ["code"],
            "data" => [
                [
                    "fields" => [
                        [
                            "key" => "name",
                            "value" => "Deal Test"
                        ],
                        [
                            "key" => "customer",
                            "value" => [
                                    [
                                        "id" => "5e967a9f84f36615d4007365"
                                    ]
                            ]
                        ],
                        [
                            "key" => "code",
                            "value" => "05182020"
                        ],  
                        [
                            "key" => "sale",
                            "value" => [
                                [
                                    "id" => "5e8ed4245adfc61f960fb793"
                                ]           
                            ]
                        ],
                        [
                             "key" => "amount",
                             "value" => 10000000
                        ],
                        [
                            "key" => "rating",
                            "value" => 90
                        ],
                    ],
                ]
            ]
        ]);

获取 Deal 表中的数据字段:struct()

    $deal->struct();

添加 Deal 表中的数据字段:addFields()

      $deal->addFields([
           "data" => [
           "fields" => [
                   [
                       "key" => "field_1",
                       "type" => "string",
                       "label" => "Trường thứ 1",
                       "description" => "Mô tả trường thứ 1"
                   ],
                   [
                       "key" => "field_2",
                       "type" => "array-object",
                       "label" => "Trường thứ 2",
                       "description" => "Mô tả trường thứ 2"
                   ],
               ]
           ]
       ]);

获取活动对象

    $activity =  $client->getTableActivity();

获取活动列表:find()

     $activity->find([
            'limit' => 100,
            'skip' => 0,
            'select' => ["name", "created_at"],
            'output' => "default",
        ]);

根据 ID 搜索活动:find()

     $activity->find([
            'limit' => 100,
            'skip' => 0,
            'query' => [
                'id' => ['id_ban_ghi']
            ],
            'select' => ["name", "created_at"],
            'output' => "default",
        ]);

添加新活动记录:update()

    $activity->update([
        "data" => [
           'fields' => [
                [
                     "key"  => "name",
                     "value"  => "Khảo sát khách ngày 18-05-2019",
                ],
                [
                     "key" => "customer_id",
                     "value" => "5e8fdfd584f3662b2c003313",
                ],
                [
                    "key" => "emails",
                    "value" => [
                         [
                             "value" => "hieptranmanh@vccorp.vn",
                         ]
                    ]
                ],
                [
                     "key" => "phones",
                     "value" => [
                         [
                             "value" => "+84948981266",
                         ]
                     ]
                ],
                [
                     "key" => "object_name",
                     "value" => "Khảo sát về nhu cầu mua hàng",
                ],
                [
                     "key" => "object_type",
                     "value" => "survey",
                ],
                [
                     "key" => "object_type_label",
                     "value" => "Khảo sát",
                ],
                [
                     "key" => "object_id",
                     "value" => "5e8eb6fc84f3661ef4000668",
                ],
                [
                     "key" => "action",
                     "value" => "input-form",
                ],
                [
                     "key" => "action_label",
                     "value" => "Nhập form online",
                ]
            ]
        ]
    ]);

根据 ID 更新活动记录:id: ''

    $activity->update([
         "data" => [
            "fields" => [
                [
                     "key"  => "name",
                     "value"  => "Khảo sát khách ngày 18-05-2019",
                ],
                [
                     "key" => "customer_id",
                     "value" => "5e8fdfd584f3662b2c003313",
                ],
                [
                    "key" => "emails",
                    "value" => [
                         [
                             "value" => "hieptranmanh@vccorp.vn",
                         ]
                    ]
                ],
                [
                     "key" => "phones",
                     "value" => [
                         [
                             "value" => "+84948981266",
                         ]
                     ]
                ],
                [
                     "key" => "object_name",
                     "value" => "Khảo sát về nhu cầu mua hàng",
                ],
                [
                     "key" => "object_type",
                     "value" => "survey",
                ],
                [
                     "key" => "object_type_label",
                     "value" => "Khảo sát",
                ],
                [
                     "key" => "object_id",
                     "value" => "5e8eb6fc84f3661ef4000668",
                ],
                [
                     "key" => "action",
                     "value" => "input-form",
                ],
                [
                     "key" => "action_label",
                     "value" => "Nhập form online",
                ]
            ],
            "id" => "id_ban_ghi"
        ]
    ]);

获取活动表中的数据字段:struct()

    $activity->struct();