2024-10-27 16:01:55 +00:00
|
|
|
|
package orderservicelogic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/shopspring/decimal"
|
2024-10-27 17:28:25 +00:00
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
2024-10-27 16:01:55 +00:00
|
|
|
|
)
|
|
|
|
|
|
2024-10-27 17:28:25 +00:00
|
|
|
|
func decimalPtrFromString(val string) *decimal.Decimal {
|
|
|
|
|
if val == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
dec, err := decimal.NewFromString(val)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logx.Errorf("Failed to convert string to decimal: %v", err)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &dec
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 17:27:25 +00:00
|
|
|
|
// getInt64Value 將 *int64 的值返回,如果為 nil 則返回 0
|
|
|
|
|
func getInt64Value(val *int64) int64 {
|
|
|
|
|
if val == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2024-10-27 17:54:05 +00:00
|
|
|
|
|
2024-10-27 17:27:25 +00:00
|
|
|
|
return *val
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stringToDecimalPtr 將 *string 轉換為 *decimal.Decimal,如果解析失敗或值為 nil 則返回 nil
|
|
|
|
|
func stringToDecimalPtr(s *string) *decimal.Decimal {
|
|
|
|
|
if s == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dec, err := decimal.NewFromString(*s)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil // 解析失敗時返回 nil,或根據需求記錄錯誤
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &dec
|
|
|
|
|
}
|