|
@@ -2,6 +2,7 @@ package db
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/issue9/conv"
|
|
@@ -11,6 +12,8 @@ import (
|
|
|
"strings"
|
|
|
"youngee_b_api/model/common_model"
|
|
|
"youngee_b_api/model/gorm_model"
|
|
|
+ "youngee_b_api/model/http_model"
|
|
|
+ "youngee_b_api/pack"
|
|
|
"youngee_b_api/util"
|
|
|
)
|
|
|
|
|
@@ -244,3 +247,69 @@ func UpdateSelectionSettleMoney(ctx context.Context, selectionID string, payMone
|
|
|
|
|
|
return true, nil
|
|
|
}
|
|
|
+
|
|
|
+func GetSelectionInfoList(ctx context.Context, pageNum, pageSize int64, conditions http_model.SelectionSquareCondition) ([]*http_model.SelectionBriefInfo, int64, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ db = db.Debug().Model(gorm_model.YounggeeSelectionInfo{})
|
|
|
+
|
|
|
+ conditionType := reflect.TypeOf(&conditions).Elem()
|
|
|
+ conditionValue := reflect.ValueOf(&conditions).Elem()
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
+ field := conditionType.Field(i)
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
+ if tag == "product_type" {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ if value.Interface().(int16) != 0 {
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询总数
|
|
|
+ var total int64
|
|
|
+ var selectionInfos []*gorm_model.YounggeeSelectionInfo
|
|
|
+ if err := db.Count(&total).Error; err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ limit := pageSize
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0\
|
|
|
+ tempList := []*gorm_model.YounggeeSelectionInfo{}
|
|
|
+ if conditions.ProductType == 0 {
|
|
|
+ // 查询该页数据
|
|
|
+ err := db.Order("task_ddl desc").Limit(int(limit)).Offset(int(offset)).Find(&selectionInfos).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ tempList = selectionInfos
|
|
|
+ } else {
|
|
|
+ err := db.Order("task_ddl desc").Find(&selectionInfos).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ total = 0
|
|
|
+ var num int64 = 0
|
|
|
+ //fmt.Println("offset: ", offset)
|
|
|
+ for _, v := range selectionInfos {
|
|
|
+ var p gorm_model.YounggeeProduct
|
|
|
+ _ = json.Unmarshal([]byte(v.ProductSnap), &p)
|
|
|
+ if p.ProductType == int64(conditions.ProductType) {
|
|
|
+ total++
|
|
|
+ //fmt.Println("total++", total)
|
|
|
+ if total > offset && num < pageSize {
|
|
|
+ //fmt.Println("num++", num)
|
|
|
+ num++
|
|
|
+ tempList = append(tempList, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ newSelectionInfos := pack.GormSelectionListToSelectionBriefInfoList(tempList)
|
|
|
+ return newSelectionInfos, total, nil
|
|
|
+}
|