e74958e17f
Co-authored-by: multica-agent <github@multica.ai>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package log
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// HasRefundCommissionLog 判断指定订单号是否已写入 333 退款佣金日志。
|
||
//
|
||
// 实现细节:
|
||
// 1. type=33 + content LIKE '%"order_no":"<orderNo>"%' 先走索引粗筛;
|
||
// 2. 命中项再用 JSON 反序列化精确比对 content.type==333 与 content.order_no,
|
||
// 避免 order_no 出现在其它字段子串里产生误判。
|
||
func HasRefundCommissionLog(tx *gorm.DB, orderNo string) (bool, error) {
|
||
if orderNo == "" {
|
||
return false, nil
|
||
}
|
||
var logs []SystemLog
|
||
if err := tx.Model(&SystemLog{}).
|
||
Where("type = ? AND content LIKE ?", TypeCommission.Uint8(), fmt.Sprintf("%%\"order_no\":\"%s\"%%", orderNo)).
|
||
Find(&logs).Error; err != nil {
|
||
return false, fmt.Errorf("query refund commission log failed: %w", err)
|
||
}
|
||
for _, item := range logs {
|
||
var content Commission
|
||
if err := content.Unmarshal([]byte(item.Content)); err != nil {
|
||
continue
|
||
}
|
||
if content.Type == CommissionTypeRefund && content.OrderNo == orderNo {
|
||
return true, nil
|
||
}
|
||
}
|
||
return false, nil
|
||
}
|
||
|
||
// HasOrderRefundLog 判断指定订单号是否已写入 24 订单退款审计日志。
|
||
func HasOrderRefundLog(tx *gorm.DB, orderNo string) (bool, error) {
|
||
if orderNo == "" {
|
||
return false, nil
|
||
}
|
||
var logs []SystemLog
|
||
if err := tx.Model(&SystemLog{}).
|
||
Where("type = ? AND content LIKE ?", TypeOrderRefund.Uint8(), fmt.Sprintf("%%\"order_no\":\"%s\"%%", orderNo)).
|
||
Find(&logs).Error; err != nil {
|
||
return false, fmt.Errorf("query order refund log failed: %w", err)
|
||
}
|
||
for _, item := range logs {
|
||
var content OrderRefund
|
||
if err := content.Unmarshal([]byte(item.Content)); err != nil {
|
||
continue
|
||
}
|
||
if content.OrderNo == orderNo {
|
||
return true, nil
|
||
}
|
||
}
|
||
return false, nil
|
||
}
|