|
@@ -10,12 +10,12 @@ import (
|
|
|
"youngee_b_api/util"
|
|
|
)
|
|
|
|
|
|
-// GetFullLocalLifeList 查看所有本地生活列表
|
|
|
+// GetFullLocalLifeList 商单广场-公开本地生活列表
|
|
|
func GetFullLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SLocalLifeCondition) ([]*gorm_model.YounggeeLocalLifeInfo, int64, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
|
|
|
// 根据带货任务状态过滤
|
|
|
- db = db.Debug().Model(gorm_model.YounggeeLocalLifeInfo{}).Where("task_status = 4")
|
|
|
+ db = db.Debug().Model(gorm_model.YounggeeLocalLifeInfo{}).Where("task_status = 4 and local_type = 1")
|
|
|
|
|
|
// 根据Project条件过滤
|
|
|
conditionType := reflect.TypeOf(condition).Elem()
|
|
@@ -64,14 +64,26 @@ func GetLocalLifeDetail(ctx context.Context, localLifeId string) (*gorm_model.Yo
|
|
|
return localLifeInfo, nil
|
|
|
}
|
|
|
|
|
|
+// GetSLocalLifeDetail 服务商本地生活查询
|
|
|
+func GetSLocalLifeDetail(ctx context.Context, sLocalLifeId int) (*gorm_model.YounggeeSLocalLifeInfo, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ var sLocalLifeInfo *gorm_model.YounggeeSLocalLifeInfo
|
|
|
+ whereCondition := gorm_model.YounggeeSLocalLifeInfo{SLocalId: sLocalLifeId}
|
|
|
+ err := db.Model(gorm_model.YounggeeSLocalLifeInfo{}).Where(whereCondition).Find(&sLocalLifeInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return sLocalLifeInfo, nil
|
|
|
+}
|
|
|
+
|
|
|
// CreateSLocalLife 创建服务商加入商单后的本地生活详情
|
|
|
-func CreateSLocalLife(ctx context.Context, newSLocal *gorm_model.YounggeeSLocalLifeInfo) error {
|
|
|
+func CreateSLocalLife(ctx context.Context, newSLocal *gorm_model.YounggeeSLocalLifeInfo) (int, error) {
|
|
|
db := GetWriteDB(ctx)
|
|
|
err := db.Create(&newSLocal).Error
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return 0, err
|
|
|
}
|
|
|
- return nil
|
|
|
+ return newSLocal.SLocalId, nil
|
|
|
}
|
|
|
|
|
|
// FindBriefByLocalId 根据localId查找Brief
|
|
@@ -100,7 +112,7 @@ func FindMaterialByLocalId(ctx context.Context, localId string) ([]gorm_model.Lo
|
|
|
return sProjectInfo, nil
|
|
|
}
|
|
|
|
|
|
-// FindSLocalByLocalIdAndSupplierId 根据LocalId和SupplierId查找SLocal
|
|
|
+// FindSLocalByLocalIdAndSupplierId 根据LocalId和SupplierId查找SLocal数量
|
|
|
func FindSLocalByLocalIdAndSupplierId(ctx context.Context, localId string, supplierId int) (int64, error) {
|
|
|
db := GetWriteDB(ctx)
|
|
|
whereCondition := gorm_model.YounggeeSLocalLifeInfo{
|
|
@@ -115,12 +127,54 @@ func FindSLocalByLocalIdAndSupplierId(ctx context.Context, localId string, suppl
|
|
|
return total, nil
|
|
|
}
|
|
|
|
|
|
-// GetFullSLocalLifeList 查看加入商单后的本地生活列表
|
|
|
+// GetFullSLocalLifeList 商单管理-公开本地生活列表
|
|
|
func GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SLocalLifeCondition) ([]*gorm_model.YounggeeSLocalLifeInfo, int64, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
|
|
|
// 根据带货任务状态过滤
|
|
|
- db = db.Debug().Model(gorm_model.YounggeeSLocalLifeInfo{}).Where("task_status = 4")
|
|
|
+ db = db.Debug().Model(gorm_model.YounggeeSLocalLifeInfo{}).Where("task_status = 4 and local_type = 1")
|
|
|
+
|
|
|
+ // 根据条件过滤
|
|
|
+ conditionType := reflect.TypeOf(condition).Elem()
|
|
|
+ conditionValue := reflect.ValueOf(condition).Elem()
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
+ field := conditionType.Field(i)
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
+ if (tag == "local_id" || tag == "local_name") && !util.IsBlank(value) {
|
|
|
+ db = db.Where(fmt.Sprintf("local_id like '%%%v%%' or local_name like '%%%v%%'", value.Interface(), value.Interface()))
|
|
|
+ } else if tag == "updated_at" && value.Interface() != "0" {
|
|
|
+ db = db.Where(fmt.Sprintf("updated_at like '%s%%'", value.Interface()))
|
|
|
+ } else if !util.IsBlank(value) && tag != "updated_at" {
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询总数
|
|
|
+ var total int64
|
|
|
+ var fullLocals []*gorm_model.YounggeeSLocalLifeInfo
|
|
|
+ if err := db.Count(&total).Error; err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询该页数据
|
|
|
+ limit := pageSize
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
+ err := db.Order("create_time desc").Limit(int(limit)).Offset(int(offset)).Find(&fullLocals).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ return fullLocals, total, nil
|
|
|
+}
|
|
|
+
|
|
|
+// GetSpecialLocalLifeList 商单广场-定向本地生活列表
|
|
|
+func GetSpecialLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SSpecialLocalLifeCondition) ([]*gorm_model.YounggeeSLocalLifeInfo, int64, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+
|
|
|
+ // 根据带货任务状态过滤
|
|
|
+ db = db.Debug().Model(gorm_model.YounggeeSLocalLifeInfo{}).Where("task_status = 4 and local_type = 2")
|
|
|
|
|
|
// 根据Project条件过滤
|
|
|
conditionType := reflect.TypeOf(condition).Elem()
|
|
@@ -149,10 +203,21 @@ func GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, conditi
|
|
|
// 查询该页数据
|
|
|
limit := pageSize
|
|
|
offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
- err := db.Order("updated_at desc").Limit(int(limit)).Offset(int(offset)).Find(&fullLocals).Error
|
|
|
+ err := db.Order("create_time desc").Limit(int(limit)).Offset(int(offset)).Find(&fullLocals).Error
|
|
|
if err != nil {
|
|
|
logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
return fullLocals, total, nil
|
|
|
}
|
|
|
+
|
|
|
+// UpdateSLocal 更新SLocal
|
|
|
+func UpdateSLocal(ctx context.Context, sLocalInfo *gorm_model.YounggeeSLocalLifeInfo) error {
|
|
|
+ db := GetWriteDB(ctx)
|
|
|
+ whereCondition := gorm_model.YounggeeSLocalLifeInfo{SLocalId: sLocalInfo.SLocalId}
|
|
|
+ err := db.Model(&gorm_model.YounggeeSLocalLifeInfo{}).Where(whereCondition).Updates(sLocalInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|