feat(rock): 绑定错误可直接改买家 UID,提货号继续留在原订单
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -800,6 +800,91 @@ func (s *RockService) ListTokens(ctx context.Context, page, pageSize int, status
|
||||
return tokens, total, nil
|
||||
}
|
||||
|
||||
// CorrectMismatchExpectedUID 客服修改买家填写的 UID,提货号继续留在原订单上。
|
||||
// 改成当前扫码角色的 UID 时解除阻断并记为已绑定;改成其他 UID 只更新期望值,仍保持阻断。
|
||||
func (s *RockService) CorrectMismatchExpectedUID(ctx context.Context, tokenID uint, expectedUID string) (*model.RockToken, error) {
|
||||
trimmedUID := strings.TrimSpace(expectedUID)
|
||||
if trimmedUID == "" || !isDigits(trimmedUID) || len(trimmedUID) > 15 {
|
||||
return nil, errors.New("请填写 15 位以内的纯数字 UID")
|
||||
}
|
||||
|
||||
var token model.RockToken
|
||||
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&token, tokenID).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.New("提货号不存在")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if token.Status != model.RockStatusMismatch {
|
||||
return errors.New("仅绑定错误的提货号可以修改买家 UID")
|
||||
}
|
||||
if strings.TrimSpace(token.AssignedOrderNo) == "" {
|
||||
return errors.New("该提货号没有关联订单,不能修改 UID")
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
actualUID := strings.TrimSpace(token.ActualRoleID)
|
||||
updates := map[string]interface{}{
|
||||
"expected_uid": trimmedUID,
|
||||
"updated_at": now,
|
||||
}
|
||||
if actualUID != "" && trimmedUID == actualUID {
|
||||
updates["status"] = model.RockStatusBound
|
||||
updates["mismatch_reason"] = ""
|
||||
updates["mismatch_at"] = nil
|
||||
updates["bound_at"] = now
|
||||
token.Status = model.RockStatusBound
|
||||
token.MismatchReason = ""
|
||||
token.MismatchAt = nil
|
||||
token.BoundAt = &now
|
||||
} else if actualUID != "" {
|
||||
updates["mismatch_reason"] = fmt.Sprintf("预期UID(%s) 与 扫码UID(%s/%s) 不一致", trimmedUID, token.ActualRoleName, actualUID)
|
||||
token.MismatchReason = updates["mismatch_reason"].(string)
|
||||
}
|
||||
if err := tx.Model(&token).Updates(updates).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
token.ExpectedUID = trimmedUID
|
||||
|
||||
var order model.FulfillmentOrder
|
||||
if err := tx.Where("order_no = ?", token.AssignedOrderNo).First(&order).Error; err == nil {
|
||||
data := resultDataMap(order.ResultData)
|
||||
data["expected_uid"] = trimmedUID
|
||||
raw, marshalErr := json.Marshal(data)
|
||||
if marshalErr != nil {
|
||||
return marshalErr
|
||||
}
|
||||
if err := tx.Model(&order).Update("result_data", string(raw)).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return writeAudit(tx, nil, nil, nil, "rock_token.correct_expected_uid", "rock_token", fmt.Sprintf("%d", token.ID), map[string]interface{}{
|
||||
"assigned_order_no": token.AssignedOrderNo,
|
||||
"expected_uid": trimmedUID,
|
||||
"actual_role_id": actualUID,
|
||||
"status": token.Status,
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
func isDigits(value string) bool {
|
||||
if value == "" {
|
||||
return false
|
||||
}
|
||||
for _, r := range value {
|
||||
if r < '0' || r > '9' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ResetMismatchToken 客服人工重置解冻绑定错误的 Token
|
||||
func (s *RockService) ResetMismatchToken(ctx context.Context, tokenID uint) error {
|
||||
var token model.RockToken
|
||||
|
||||
Reference in New Issue
Block a user