报价单

This commit is contained in:
eson 2023-06-26 19:51:59 +08:00
parent 17d1522655
commit d336f757ed
3 changed files with 49 additions and 23 deletions

View File

@ -88,16 +88,18 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
//获取备注模板 //获取备注模板
markList, err := l.svcCtx.AllModels.FsQuotationRemarkTemplate.GetAllSelectContent(l.ctx) markList, err := l.svcCtx.AllModels.FsQuotationRemarkTemplate.GetAllSelectContent(l.ctx)
var productIds = collect.ArrayColumn[int64](CanteenProduct, "product_id") var productIds = collect.ArrayColumnTag[int64](CanteenProduct, "product_id")
productList, err := l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, productIds) productList, err := l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, productIds)
collect.Array2MapByKeyTag[int64](productList, "id") productListMap := collect.Array2MapByKeyTag[int64](productList, "id")
//获取size信息 //获取size信息
var sizeIds = collect.ArrayColumn[int64](CanteenProduct, "SizeId") var sizeIds = collect.ArrayColumnTag[int64](CanteenProduct, "size_id")
sizes, err := l.svcCtx.AllModels.FsProductSize.GetAllSelectIdAndCapacityByIds(l.ctx, sizeIds) sizes, err := l.svcCtx.AllModels.FsProductSize.GetAllSelectIdAndCapacityByIds(l.ctx, sizeIds)
sizesMap := collect.Array2MapByKeyTag[int64](sizes, "id")
//获取价格信息 //获取价格信息
productPrice, err := l.svcCtx.AllModels.FsProductPrice.GetAllSelectBySizeId(l.ctx, sizeIds) productPrice, err := l.svcCtx.AllModels.FsProductPrice.GetAllSelectBySizeId(l.ctx, sizeIds)
productPriceMap := collect.Array2MapByKeyTag[int64](productPrice, "size_id")
// product := []map[string]interface{}{} // product := []map[string]interface{}{}
product := []map[string]interface{}{} product := []map[string]interface{}{}
@ -107,7 +109,7 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
if !qFlag { if !qFlag {
if price, ok := productPrice[parr.Get("size_id").Int()]; !ok { if price, ok := productPriceMap[parr.Get("size_id").Int()]; !ok {
priceList = []map[string]int64{ priceList = []map[string]int64{
{"num": 1, "price": 0}, {"num": 1, "price": 0},
{"num": 1, "price": 0}, {"num": 1, "price": 0},
@ -134,8 +136,6 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
} }
} }
var ( var (
Id any Id any
priceInfo any priceInfo any
@ -185,11 +185,14 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
sid = parr.Get("sid").Int() sid = parr.Get("sid").Int()
} }
productList product := productListMap[parr.Get("product_id").Int()]
name = product.Title
$productList[$parr['product_id']]['title'] size = sizesMap[parr.Get("size_id").Int()].Capacity
cycle = *product.ProduceDays + *product.DeliveryDays
img = ""
mark = []string{}
priceInfo = priceList
num = 1
} }
product = append(product, map[string]interface{}{ product = append(product, map[string]interface{}{
@ -205,18 +208,6 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
"num": num, "num": num,
}) })
// product = append(product, map[string]interface{}{
// "id": qFlag ? parr.ID : nil,
// "sId": parr.SID ? parr.SID : nil,
// "isGift": qFlag && parr.IsGift,
// "name": qFlag ? parr.Name : productList[parr.ProductID].Title,
// "size": qFlag ? parr.Size : sizes[parr.SizeId].Capacity,
// "cycle": qFlag ? parr.Cycle : productList[parr.ProductID].ProduceDays + productList[parr.ProductID].DeliveryDays,
// "img": qFlag ? parr.Img : "",
// "mark": qFlag && parr.Remark ? json.Unmarshal(parr.Remark) : nil,
// "priceList": qFlag ? json.Unmarshal(parr.PriceInfo) : priceList,
// "num": qFlag ? parr.Num : 1,
// })
} }
return resp.SetStatus(basic.CodeOK) return resp.SetStatus(basic.CodeOK)

View File

@ -18,6 +18,31 @@ func ArrayColumn[R any, T any](arr []T, column string) []R {
return result return result
} }
func ArrayColumnTag[R any, T any](arrSrc []T, tag string) []R {
var result []R
arr := reflect.ValueOf(arrSrc)
if arr.Len() == 0 {
return result
}
eleType := arr.Index(0).Elem().Type()
for j := 0; j < eleType.NumField(); j++ {
if value, ok := eleType.Field(j).Tag.Lookup("json"); ok && value == tag {
for i := 0; i < arr.Len(); i++ {
srcv := arr.Index(i)
fv := srcv.Elem().Field(j)
result = append(result, fv.Interface().(R))
}
return result
}
}
return result
}
func ArrayIndex[T any](arr []T, index int) (result T, ok bool) { func ArrayIndex[T any](arr []T, index int) (result T, ok bool) {
if index < len(arr) { if index < len(arr) {
result = arr[index] result = arr[index]

View File

@ -30,3 +30,13 @@ func TestArray2MapByKeyTag(t *testing.T) {
log.Printf("%##v", a) log.Printf("%##v", a)
log.Println(len(a)) log.Println(len(a))
} }
func TestArrayColumnTag(t *testing.T) {
var abcs []*ABC = []*ABC{
{1, "2", 3},
{3, "1", 2},
}
a := ArrayColumnTag[string](abcs, "b")
log.Printf("%##v", a)
log.Println(len(a))
}