jbtje / vtiger-laravel
vtiger API 封装器
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4
This package is auto-updated.
Last update: 2024-09-29 05:57:00 UTC
README
此包可能适用于 Vtiger 的旧版本,以及 Laravel 6 或 7。
BerliCRM(基于 Vtiger)有更好的文档,文件已添加到文档文件夹。
在 Laravel 中使用 Vtiger webservice (REST) API 执行以下操作。
- 列表类型
- 创建
- 检索
- 更新
- 删除
- 搜索
- 查询
- 描述
安装、配置和使用
安装
-
为了在 Laravel 项目中安装 Vtiger 包,只需在终端运行 composer require 命令
composer require "jbtje/vtiger-laravel" -
添加 ENV 变量
VTIGER_URL=https://your-crm-domain.com/webservice.php VTIGER_USERNAME= VTIGER_KEY= VTIGER_PERSISTENT=true VTIGER_RETRIES=10
用户名和 访问密钥可以在 Vtiger 的 我的偏好设置 中找到
-
可选:发布配置文件
php artisan vendor:publish --tag="vtiger"
配置
您可以为 API 创建 Vtiger 中的新用户,或者使用现有用户。
使用方法
在控制器中包含 Vtiger 包
use JBtje\VtigerLaravel\Vtiger;
列表类型
列表类型命令提供 Vtiger CRM 所支持的所有可能类型。对于每种类型,您都可以运行 describe() 命令以获取数据结构。
获取所有列表类型
$vtiger = new Vtiger(); $data = $vtiger->listTypes();
对于干净安装,这将返回:(点击展开)
{
"success": true,
"result": {
"types": [
"Campaigns",
"Vendors",
"Faq",
"Quotes",
"PurchaseOrder",
"SalesOrder",
"Invoice",
"PriceBooks",
"Calendar",
"Leads",
"Accounts",
"Contacts",
"Potentials",
"Products",
"Documents",
"Emails",
"HelpDesk",
"Events",
"Users",
"PBXManager",
"ServiceContracts",
"Services",
"Assets",
"ModComments",
"ProjectMilestone",
"ProjectTask",
"Project",
"SMSNotifier",
"Groups",
"Currency",
"DocumentFolders",
"CompanyDetails",
"LineItem",
"Tax",
"ProductTaxes"
],
"information": {
"Campaigns": {
"isEntity": true,
"label": "Campaigns",
"singular": "Campaign"
},
"Vendors": {
"isEntity": true,
"label": "Vendors",
"singular": "Vendor"
},
"Faq": {
"isEntity": true,
"label": "FAQ",
"singular": "FAQ"
},
"Quotes": {
"isEntity": true,
"label": "Quotes",
"singular": "Quote"
},
"PurchaseOrder": {
"isEntity": true,
"label": "Purchase Orders",
"singular": "Purchase Order"
},
"SalesOrder": {
"isEntity": true,
"label": "Sales Orders",
"singular": "Sales Order"
},
"Invoice": {
"isEntity": true,
"label": "Invoices",
"singular": "Invoice"
},
"PriceBooks": {
"isEntity": true,
"label": "Price Books",
"singular": "Price Book"
},
"Calendar": {
"isEntity": true,
"label": "Calendar",
"singular": "Task"
},
"Leads": {
"isEntity": true,
"label": "Leads",
"singular": "Lead"
},
"Accounts": {
"isEntity": true,
"label": "Organizations",
"singular": "Organization"
},
"Contacts": {
"isEntity": true,
"label": "Contacts",
"singular": "Contact"
},
"Potentials": {
"isEntity": true,
"label": "Opportunities",
"singular": "Opportunity"
},
"Products": {
"isEntity": true,
"label": "Products",
"singular": "Product"
},
"Documents": {
"isEntity": true,
"label": "Documents",
"singular": "Document"
},
"Emails": {
"isEntity": true,
"label": "Emails",
"singular": "Email"
},
"HelpDesk": {
"isEntity": true,
"label": "Tickets",
"singular": "Ticket"
},
"Events": {
"isEntity": true,
"label": "Events",
"singular": "Event"
},
"Users": {
"isEntity": true,
"label": "Users",
"singular": "User"
},
"PBXManager": {
"isEntity": true,
"label": "PBX Manager",
"singular": "Call Record"
},
"ServiceContracts": {
"isEntity": true,
"label": "Service Contracts",
"singular": "Service Contract"
},
"Services": {
"isEntity": true,
"label": "Services",
"singular": "Service"
},
"Assets": {
"isEntity": true,
"label": "Assets",
"singular": "Asset"
},
"ModComments": {
"isEntity": true,
"label": "Comments",
"singular": "Comment"
},
"ProjectMilestone": {
"isEntity": true,
"label": "Project Milestones",
"singular": "Project Milestone"
},
"ProjectTask": {
"isEntity": true,
"label": "Project Tasks",
"singular": "Project Task"
},
"Project": {
"isEntity": true,
"label": "Projects",
"singular": "Project"
},
"SMSNotifier": {
"isEntity": true,
"label": "SMS Notifier",
"singular": "SMS Notifier"
},
"Groups": {
"isEntity": false,
"label": "Groups",
"singular": "Groups"
},
"Currency": {
"isEntity": false,
"label": "Currency",
"singular": "Currency"
},
"DocumentFolders": {
"isEntity": false,
"label": "DocumentFolders",
"singular": "DocumentFolders"
},
"CompanyDetails": {
"isEntity": false,
"label": "CompanyDetails",
"singular": "CompanyDetails"
},
"LineItem": {
"isEntity": false,
"label": "LineItem",
"singular": "LineItem"
},
"Tax": {
"isEntity": false,
"label": "Tax",
"singular": "Tax"
},
"ProductTaxes": {
"isEntity": false,
"label": "ProductTaxes",
"singular": "ProductTaxes"
}
}
}
}
描述
要获取 Vtiger 中模块的数据结构,请使用模块名称运行 describe 方法。模块名称可以使用 listTypes() 获取。
$vtiger = new Vtiger(); $data = $vtiger->describe( 'Contacts' );
"联系人"的局部结果:(点击展开)
{
"success": true,
"result": {
"label": "Contacts",
"name": "Contacts",
"createable": true,
"updateable": true,
"deleteable": true,
"retrieveable": true,
"fields": [
{
"name": "firstname",
"label": "First Name",
"mandatory": false,
"type": {
"name": "string"
},
"isunique": false,
"nullable": true,
"editable": true,
"default": ""
},
{
"name": "lastname",
"label": "Last Name",
"mandatory": true,
"type": {
"name": "string"
},
"isunique": false,
"nullable": false,
"editable": true,
"default": ""
},
{
"name": "assigned_user_id",
"label": "Assigned To",
"mandatory": true,
"type": {
"name": "owner"
},
"isunique": false,
"nullable": false,
"editable": true,
"default": ""
},
...
],
"idPrefix": "12",
"isEntity": true,
"allowDuplicates": true,
"labelFields": "firstname,lastname"
}
}
请注意 强制性 字段。
创建
要将记录插入 CRM,首先创建一个要插入的数据数组。使用 describe(),您可以看到哪些字段是强制性的。
$vtiger = new Vtiger(); $data = [ 'assigned_user_id' => '4x1', ... ]; $data = $vtiger->create( $MODULE_NAME, json_encode( $data ) );
检索
要检索 CRM 中的记录,您需要找到要查找的记录的 id(例如 '4x1')。
$vtiger = new Vtiger(); $data = $vtiger->retrieve( '4x1' );
更新
在 CRM 中更新记录的最简单方法是首先检索记录。
$vtiger = new Vtiger(); $obj = $vtiger->retrieve( '4x1' );
然后更新对象
$obj->result->field_name = 'Your new value'; $data = $vtiger->update( $obj->result );
删除
要删除 CRM 中的记录,您需要要删除的记录的 id(例如 '4x1')。
$vtiger = new Vtiger(); $data = $vtiger->delete( '4x1' );
查找
此功能使用 Vtiger 查找 API 端点在 Vtiger 模块的多个列中搜索单个信息。此功能通常比搜索功能快得多。
$dataType = 'phone'; $phoneNumber = '1234567890'; $module = 'Leads'; $columns = ['phone', 'fax']; // Must be an array $vtiger = new Vtiger(); $data = $vtiger->lookup( $dataType, $phoneNumber, $module, $columns );
搜索
此功能是查询函数周围的 sql 查询构建器。接受 laravel QueryBuilder 实例。
$vtiger = new Vtiger(); $query = DB::table( 'Leads' )->select( 'id', 'firstname', 'lastname' )->where( 'firstname', 'John' ); $data = $vtiger->search( $query ); foreach( $data->result as $result ) { // Do something }
默认情况下,该函数将引用但不会转义您的输入,如果您希望您的数据不被引用,请将第二个参数设置为 false
$vtiger = new Vtiger(); $data = $vtiger->search( $query, false );
还要记住,Vtiger 在其 sql 查询功能方面有一些限制。您不能使用条件分组,即 "where (firstname = 'John' AND 'lastname = 'Doe') OR (firstname = 'Jane' AND lastname = 'Smith')" 将失败。
查询
要使用查询操作,您首先需要创建 SQL 查询。
$query = "SELECT * FROM ModuleName;";
然后运行查询...
$vtiger = new Vtiger(); $data = $vtiger->query($query); foreach( $data->result as $result ) { // Do something }
贡献
请将您在问题页面中发现的所有问题报告。欢迎提交拉取请求。
许可证
本项目遵循MIT许可证 - 请参阅LICENSE.md文件以获取详细信息
贡献者
本包基于Clystnet/Vtiger
本项目遵循all-contributors规范。欢迎任何形式的贡献!