mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-25 14:36:35 +08:00
[区域]可以设置区域-价格项目之间的价格
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -131,3 +133,35 @@ func (this *NodeRegionDAO) UpdateRegionOrders(regionIds []int64) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 修改价格项价格
|
||||
func (this *NodeRegionDAO) UpdateRegionItemPrice(regionId int64, itemId int64, price float32) error {
|
||||
one, err := this.Query().
|
||||
Pk(regionId).
|
||||
Result("prices").
|
||||
Find()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if one == nil {
|
||||
return nil
|
||||
}
|
||||
prices := one.(*NodeRegion).Prices
|
||||
pricesMap := map[string]float32{}
|
||||
if len(prices) > 0 && prices != "null" {
|
||||
err = json.Unmarshal([]byte(prices), &pricesMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
pricesMap[numberutils.FormatInt64(itemId)] = price
|
||||
pricesJSON, err := json.Marshal(pricesMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = this.Query().
|
||||
Pk(regionId).
|
||||
Set("prices", pricesJSON).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user