This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
+176
View File
@@ -0,0 +1,176 @@
# Stemcell_Datacollection Module
这是一个Magento2数据收集模块,提供了基本的WebAPI接口,支持多种表单类型的数据收集。
## 功能特性
- 提供POST API接口用于数据收集
- 支持Inquiry表单数据收集
- 支持默认数据收集(保存到日志文件)
- 支持匿名访问
- 数据验证和错误处理
## 安装
第一步:composer require alekseon/custom-forms-builder
第二步:
php bin/magento module:enable Alekseon_AlekseonEav Alekseon_CustomFormsBuilder Alekseon_CustomFormsEmailNotification Alekseon_CustomFormsStatistics
第三步:php bin/magento setup:upgrade
第四步:php bin/magento module:enable Stemcell_Datacollection
第五步:php bin/magento setup:upgrade
## API接口
### 1. 默认数据收集
**URL:** `POST /rest/V1/datacollection/submit`
**参数:**
- `data` (string): 要收集的数据内容
- `formType` (string, 可选): 表单类型,默认为 'default'
**示例请求:**
```bash
curl -X POST "https://your-domain.com/rest/V1/datacollection/submit" \
-H "Content-Type: application/json" \
-d '{"data": "测试数据内容"}'
```
### 2. Inquiry表单数据收集
**URL:** `POST /rest/V1/datacollection/inquiry`
**参数:**
- `data` (string): JSON格式的inquiry表单数据
- `formType` (string): 设置为 'inquiry'
**Inquiry表单字段:**
- `inquiry_company`: 公司名称
- `inquiry_email`: 邮箱地址
- `inquiry_mobile`: 手机号码
- `inquiry_province`: 省份
- `inquiry_subject_group`: 主题组
- `inquiry_username`: 用户名
**示例请求:**
```bash
curl -X POST "https://your-domain.com/rest/V1/datacollection/inquiry" \
-H "Content-Type: application/json" \
-d '{
"data": "{\"inquiry_company\":\"测试公司\",\"inquiry_email\":\"test@example.com\",\"inquiry_mobile\":\"13800138000\",\"inquiry_province\":\"北京\",\"inquiry_subject_group\":\"产品咨询\",\"inquiry_username\":\"张三\",\"inquiry_product_sku\":\"AKD732894723\",\"inquiry_product_name\":\"商品名称123456测试\"}",
"formType": "inquiry"
}'
```
### 3. Lecture表单数据收集
**URL:** `POST /rest/V1/datacollection/lecture`
**参数:**
- `data` (string): JSON格式的lecture表单数据
- `formType` (string): 设置为 'lecture'
**Lecture表单字段:**
- `lecture_username`: 用户名 (varchar)
- `lecture_company`: 公司名称 (varchar)
- `lecture_subject_group`: 主题组 (varchar)
- `lecture_province`: 省份 (varchar)
- `lecture_email`: 邮箱地址 (varchar)
- `lecture_mobile`: 手机号码 (varchar)
- `lecture_species_studied`: 研究物种 (multiselect)
- `lecture_cell_type`: 细胞类型 (select)
- `lecture_apply_topics`: 应用主题 (varchar)
- `lecture_the_way`: 讲座方式 (select)
**示例请求:**
```bash
curl -X POST "https://your-domain.com/rest/V1/datacollection/lecture" \
-H "Content-Type: application/json" \
-d '{
"data": "{\"lecture_username\":\"李四\",\"lecture_company\":\"生物科技公司\",\"lecture_subject_group\":\"细胞生物学\",\"lecture_province\":\"上海\",\"lecture_email\":\"lisi@biotech.com\",\"lecture_mobile\":\"13900139000\",\"lecture_species_studied\":\"人类,小鼠,大鼠\",\"lecture_cell_type\":\"干细胞\",\"lecture_apply_topics\":\"细胞治疗,再生医学\",\"lecture_the_way\":\"线上讲座\"}",
"formType": "lecture"
}'
```
**响应示例:**
```json
"Inquiry data collected successfully (Record ID: 123)"
```
## 数据存储
### Inquiry表单数据
- 表单记录存储在 `alekseon_custom_form_record` 表
- 字段值存储在 `alekseon_custom_form_record_entity_varchar` 表
- 字段定义存储在 `alekseon_custom_form_record_attribute` 表
### Lecture表单数据
- 表单记录存储在 `alekseon_custom_form_record` 表
- varchar类型字段值存储在 `alekseon_custom_form_record_entity_varchar` 表
- select类型字段值存储在 `alekseon_custom_form_record_entity_int` 表(存储option_id)
- multiselect类型字段值存储在 `alekseon_custom_form_record_entity_varchar` 表(存储逗号分隔的option_id)
- 字段定义存储在 `alekseon_custom_form_record_attribute` 表
- 选项值存储在 `alekseon_custom_form_record_attribute_option` 和 `alekseon_custom_form_record_attribute_option_value` 表
### 默认数据
- 接收到的数据会保存在 `var/log/datacollection/` 目录下
- 每个请求会创建一个带时间戳的日志文件
## 安装说明
1. 将模块文件复制到 `app/code/Stemcell/Datacollection/` 目录
2. 运行以下命令启用模块:
```bash
php bin/magento module:enable Stemcell_Datacollection
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush
```
## 文件结构
```
Stemcell_Datacollection/
├── Api/
│ └── DataCollectionInterface.php
├── Model/
│ ├── DataCollection.php
│ └── Type/
│ ├── Inquiry.php
│ └── Lecture.php
├── etc/
│ ├── module.xml
│ ├── webapi.xml
│ └── di.xml
├── composer.json
├── registration.php
└── README.md
```
## 扩展说明
### 添加新的表单类型
1. 在 `Model/Type/` 目录下创建新的表单模型类
2. 在 `DataCollection.php` 中添加新的表单类型处理逻辑
3. 在 `webapi.xml` 中添加新的API路由(可选)
### 表单模型要求
新的表单模型类需要实现以下方法:
- `processData($data)`: 处理表单数据
- `validateData($data)`: 验证表单数据
- `getFieldsConfig()`: 获取字段配置
## 注意事项
- 确保Alekseon_CustomFormsBuilder模块已正确安装
- Inquiry表单必须在后台创建,标识符为 'inquiry'
- Lecture表单必须在后台创建,标识符为 'lecture'
- Inquiry表单所有字段必须是varchar类型
- Lecture表单支持varchar、select和multiselect字段类型
- 生产环境使用前请根据实际需求进行修改
- 默认允许匿名访问,如需权限控制请修改 `webapi.xml` 中的资源配置
## 通过邮件将所有询价表单数据用excel附件的形式发到指定邮箱
- 代码再Stemcell\Datacollection\Cron\FormRecordsNotification
- 需要去管理后台配置Alekseon Extensions->Custom Forms->New Entity Notification Email的Send Email To邮件接收人