2024-05-14 20:36:33 +08:00
|
|
|
package productv1
|
|
|
|
|
|
|
|
import (
|
2024-09-01 16:49:35 +08:00
|
|
|
"testing"
|
|
|
|
|
2024-05-14 20:36:33 +08:00
|
|
|
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
|
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpsert(t *testing.T) {
|
|
|
|
db, err := database.InitDatabase(&database.DBOption{
|
|
|
|
Host: "192.168.31.55",
|
|
|
|
User: "timerzz",
|
|
|
|
Password: "zhhg1997",
|
|
|
|
Port: "5432",
|
2024-05-15 13:54:53 +08:00
|
|
|
DBName: "kedaya_dev",
|
2024-05-14 20:36:33 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = db.AutoMigrate(&Product{}, &HistoryPrice{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
db.Clauses(clause.OnConflict{
|
|
|
|
Columns: []clause.Column{{Name: "pid"}},
|
2024-06-15 21:26:42 +08:00
|
|
|
DoUpdates: clause.AssignmentColumns([]string{"name", "color", "link", "orderable", "original_price", "cny_price", "cal_mark", "rate"}),
|
2024-05-14 20:36:33 +08:00
|
|
|
}).Create([]Product{
|
|
|
|
{
|
2024-06-15 16:54:04 +08:00
|
|
|
Name: "test",
|
|
|
|
Pid: "test-3",
|
|
|
|
Color: "green",
|
|
|
|
Link: "www.baidu.com",
|
|
|
|
Image: "image",
|
|
|
|
Orderable: false,
|
|
|
|
OriginalPrice: 123,
|
|
|
|
DWPrice: 3000,
|
|
|
|
Freight: 130,
|
2024-05-14 20:36:33 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2024-05-15 13:54:53 +08:00
|
|
|
|
|
|
|
func TestUpdate(t *testing.T) {
|
|
|
|
db, err := database.InitDatabase(&database.DBOption{
|
|
|
|
Host: "192.168.31.55",
|
|
|
|
User: "timerzz",
|
|
|
|
Password: "zhhg1997",
|
|
|
|
Port: "5432",
|
|
|
|
DBName: "kedaya_dev",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2024-06-15 16:54:04 +08:00
|
|
|
var p = Product{Pid: "CJ575-QBO4G", DWPrice: 3000, Freight: 150, Remark: "test", OriginalPrice: 209.3, ExchangeRate: 7.3}
|
2024-09-01 16:49:35 +08:00
|
|
|
err = db.Model(&p).Where("pid=?", p.Pid).Select("dw_price", "freight", "remark", "rate", "cal_mark", "cny_price").Updates(&p).Error
|
2024-05-15 13:54:53 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2024-05-16 12:52:06 +08:00
|
|
|
|
|
|
|
func TestGetConfig(t *testing.T) {
|
|
|
|
db, err := database.InitDatabase(&database.DBOption{
|
|
|
|
Host: "192.168.31.55",
|
|
|
|
User: "timerzz",
|
|
|
|
Password: "zhhg1997",
|
|
|
|
Port: "5432",
|
|
|
|
DBName: "kedaya_dev",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
var exchangeRate float64
|
2024-09-01 16:49:35 +08:00
|
|
|
db.Table("options").Select("exchange_rate").Where("id=?", 1).Scan(&exchangeRate)
|
2024-05-16 12:52:06 +08:00
|
|
|
t.Log(exchangeRate)
|
|
|
|
}
|
2024-06-15 16:54:04 +08:00
|
|
|
|
|
|
|
func TestCalculateProcess_Calculate(t *testing.T) {
|
|
|
|
p := Product{
|
|
|
|
OriginalPrice: 160.9,
|
|
|
|
Freight: 100,
|
|
|
|
ExchangeRate: 7.3,
|
|
|
|
PriceStatus: 0,
|
|
|
|
}
|
|
|
|
cal := CalculateProcess{
|
|
|
|
Condition: "usPrice >= 150",
|
|
|
|
Process: "(usPrice - 20) * exchangeRate + freight",
|
|
|
|
Name: "满150 - 20",
|
|
|
|
}
|
|
|
|
t.Log(cal.Calculate(p.Env()))
|
|
|
|
}
|