coupon/coupon_sync_rules.md

46 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 兑换码状态同步规则
## 数据流
```
远程API根据产品配置的接口地址
▼ 请求参数start_time, end_time, app_id产品code
▼ HeaderAuthorization = md5(start_time + end_time)
▼ 返回数据status=2 已使用的兑换码列表)
▼ 逐条匹配本地 claim_records
▼ 匹配成功 → 更新状态
▼ 匹配失败 → 记录未匹配
```
## 匹配规则
| 步骤 | 说明 |
|------|------|
| 1. 取数据 | 调用产品配置的 API 接口,按使用时间范围查询已使用的兑换码 |
| 2. 过滤 | 只处理 `status=2`(已使用)的记录 |
| 3. 匹配 | 用 `coupon_code` + `product_id` 匹配本地 `claim_records` 表 |
| 4. 更新 | 匹配到的记录如果本地 `status != 2`则更新状态、使用时间、会员ID |
## 未匹配的常见原因
| 原因 | 说明 |
|------|------|
| 该兑换码不是通过本系统领取的 | API 返回的是该产品下所有已使用的码,包含其他渠道发放的 |
| 产品归属不对 | `claim_records.product_id` 与当前产品的 ID 不一致 |
| 领取记录已被删除 | 数据已被清理 |
## 同步方式
### 1. 手动同步
- 位置:后台设置 → 兑换码状态同步
- 选择时间范围,点击"立即同步"
- 结果显示API 总条数、匹配条数、更新条数、已匹配 code 列表、未匹配 code 列表
### 2. 定时任务
- 每天凌晨 2 点执行,同步前一天的数据
- crontab`0 2 * * * php /path/to/cron_sync.php`