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.

80 lines
1.5 KiB

package after
import (
"fmt"
"recook/internal/v2/model/recook/after"
)
var CategoryLogic = &category{}
type category struct {
}
type AssType uint
const (
ATUnshippedAfterSale = iota + 1
ATShippedAfterSale
ATOrderCompensation
)
const (
UnshippedAfterSale = "未发货售后"
ShippedAfterSale = "已发货售后"
OrderCompensation = "订单补偿"
)
type CategoryResp struct {
Name string `json:"name"`
Count uint `json:"count"`
}
type where struct {
name string
query string
}
var categoryMap = map[AssType]where{
ATUnshippedAfterSale: {
name: UnshippedAfterSale,
query: "ass_type = 1",
},
ATShippedAfterSale: {
name: ShippedAfterSale,
query: "ass_type = 2",
},
ATOrderCompensation: {
name: OrderCompensation,
query: "ass_type = 3",
},
}
func (u AssType) getWhere() where {
if v, ok := categoryMap[u]; !ok {
return categoryMap[AssType(ATUnshippedAfterSale)]
} else {
return v
}
}
// GetCateGory 获取售后分类信息.
func (o category) GetCateGory() (result []CategoryResp) {
return o.GetCateGoryByVendor(-1)
}
// GetCateGoryByVendor 获取售后分类信息通过供应商.
func (o category) GetCateGoryByVendor(vendor int) (result []CategoryResp) {
aft := &after.RecookAfterSalesGoodsModel{}
for _, v := range categoryMap {
query := v.query
if vendor >= 0 {
query = fmt.Sprintf("%s AND vendor_id = %d", query, vendor)
}
count := aft.GetCount(query)
c := CategoryResp{Name: v.name, Count: count}
result = append(result, c)
}
return
}