You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.9 KiB
102 lines
2.9 KiB
package freight
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/freight"
|
|
"strconv"
|
|
)
|
|
|
|
type deliveryProvinceResp struct {
|
|
freight.Price
|
|
Children []string `json:"children"`
|
|
}
|
|
|
|
type provinceName struct {
|
|
Name string `gorm:"column:province_name" json:"name"`
|
|
}
|
|
|
|
type freightListResp struct {
|
|
freight.Information
|
|
Provinces []deliveryProvinceResp `json:"provinces"`
|
|
NoProvinces []string `json:"noProvinces"`
|
|
}
|
|
|
|
//判断是否供应商
|
|
func IsCheckGys(c *gin.Context) (where string) {
|
|
//判断是不是供应商
|
|
gys_token := c.Request.Header.Get("X-Recook-GYSToken")
|
|
gysId, _ := dbc.Rds.Get(gys_token).Result()
|
|
myGysId, _ := strconv.Atoi(gysId)
|
|
where = ""
|
|
if myGysId > 0 {
|
|
//说明是供应商
|
|
where = "gys_id=0 or gys_id=" + strconv.Itoa(myGysId)
|
|
|
|
}
|
|
return where
|
|
|
|
}
|
|
|
|
//快递模板列表
|
|
func QueryFreightList(c *gin.Context) {
|
|
//判断是否供应商
|
|
where := IsCheckGys(c)
|
|
|
|
var list []freightListResp
|
|
|
|
dbc.DB.Table((&freight.Information{}).TableName()).Where(where).Find(&list)
|
|
|
|
// 不发货地区处理
|
|
|
|
// 不发货市区
|
|
var noCitys []freight.NoCitys
|
|
dbc.DB.Table((&freight.NoCitys{}).TableName()).Find(&noCitys)
|
|
noCityMap := map[uint][]string{}
|
|
for _, item := range noCitys {
|
|
noCityMap[item.FreightID] = append(noCityMap[item.FreightID], fmt.Sprintf("%s-%s", item.ProvinceName, item.CityName))
|
|
}
|
|
|
|
// 不发货省份
|
|
var noProvinces []freight.NoProvince
|
|
dbc.DB.Table((&freight.NoProvince{}).TableName()).Find(&noProvinces)
|
|
noProvinceMap := map[uint][]string{}
|
|
for _, noProvince := range noProvinces {
|
|
noProvinceMap[noProvince.FreightID] = append(noProvinceMap[noProvince.FreightID], noProvince.ProvinceName)
|
|
}
|
|
|
|
// 有运费处理
|
|
// 地区处理
|
|
cityss := []freight.Citys{}
|
|
dbc.DB.Table((&freight.Citys{}).TableName()).Find(&cityss)
|
|
cityMap := map[uint][]string{}
|
|
for _, item := range cityss {
|
|
cityMap[item.PriceDetailID] = append(cityMap[item.PriceDetailID], fmt.Sprintf("%s-%s", item.ProvinceName, item.CityName))
|
|
}
|
|
// 省份处理
|
|
provinces := []freight.Province{}
|
|
dbc.DB.Table((&freight.Province{}).TableName()).Find(&provinces)
|
|
provinceMap := map[uint][]string{}
|
|
for _, item := range provinces {
|
|
provinceMap[item.PriceDetailID] = append(provinceMap[item.PriceDetailID], item.ProvinceName)
|
|
}
|
|
|
|
// 价格处理
|
|
deliveryProvinceResps := []deliveryProvinceResp{}
|
|
dbc.DB.Table((&freight.Price{}).TableName()).Find(&deliveryProvinceResps)
|
|
deliveryProviceMap := map[uint][]deliveryProvinceResp{}
|
|
for _, item := range deliveryProvinceResps {
|
|
item.Children = append(provinceMap[item.ID], cityMap[item.ID]...)
|
|
deliveryProviceMap[item.FreightID] = append(deliveryProviceMap[item.FreightID], item)
|
|
}
|
|
|
|
for i, item := range list {
|
|
list[i].NoProvinces = append(noProvinceMap[item.ID], noCityMap[item.ID]...)
|
|
list[i].Provinces = deliveryProviceMap[item.ID]
|
|
}
|
|
|
|
back.Suc(c, "操作成功", &list)
|
|
}
|