fix
This commit is contained in:
@@ -23,7 +23,23 @@ func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []i
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *FsProductModel) GetProductListByIdsWithoutStatus(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return
|
||||
}
|
||||
db := p.db.Model(&FsProduct{}).WithContext(ctx).
|
||||
Where("`id` in (?) ", productIds)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
db = db.Order("`sort` ASC")
|
||||
case "sort-desc":
|
||||
db = db.Order("`sort` DESC")
|
||||
}
|
||||
if err = db.Find(&resp).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
|
||||
if len(productTypes) == 0 {
|
||||
return
|
||||
|
||||
@@ -19,6 +19,17 @@ func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, fi
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (d *FsProductModel3dModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3d, err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?)", ids)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (d *FsProductModel3dModel) GetAllByIdsTag(ctx context.Context, ids []int64, tag int64) (resp []FsProductModel3d, err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
|
||||
@@ -32,6 +32,9 @@ func (s *FsProductSizeModel) CountByStatus(ctx context.Context, status int) (tot
|
||||
return
|
||||
}
|
||||
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
@@ -45,6 +48,23 @@ func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *FsProductSizeModel) GetAllByProductIdsWithoutStatus(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?)", productIds)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
db = db.Order("`sort` ASC")
|
||||
case "sort-desc":
|
||||
db = db.Order("`sort` DESC")
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type CapacityId struct {
|
||||
Id int64 `json:"id"`
|
||||
|
||||
@@ -24,6 +24,16 @@ func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64
|
||||
}
|
||||
return
|
||||
}
|
||||
func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsProductTemplateV2, err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) ", ids).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp *FsProductTemplateV2, err error) {
|
||||
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Find(&resp).Error
|
||||
|
||||
@@ -3,19 +3,37 @@ package gmodel
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
type GetStockListReq struct {
|
||||
UserId int64
|
||||
Ids []int64
|
||||
Status *int64
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (s *FsUserStockModel) GetUserAllStockByIds(ctx context.Context, ids []int64, userId int64) (resp []FsUserStock, err error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
func (s *FsUserStockModel) GetStockList(ctx context.Context, req GetStockListReq) (resp []FsUserStock, total int64, err error) {
|
||||
db := s.db.WithContext(ctx).Model(&FsUserStock{})
|
||||
if req.UserId > 0 {
|
||||
db = db.Where("`user_id` = ?", req.UserId)
|
||||
}
|
||||
if userId <= 0 {
|
||||
return nil, nil
|
||||
if len(req.Ids) > 0 {
|
||||
db = db.Where("`id` in (?)", req.Ids)
|
||||
}
|
||||
err = s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` in (?) and `user_id` = ?", ids, userId).Find(&resp).Error
|
||||
return resp, err
|
||||
if req.Status != nil {
|
||||
db = db.Where("`status` = ?", *req.Status)
|
||||
}
|
||||
if err = db.Limit(1).Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *FsUserStockModel) FindOne(ctx context.Context, id int64, userId int64, lock ...bool) (resp *FsUserStock, err error) {
|
||||
db := s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` = ? and `user_id` = ?", id, userId)
|
||||
db := s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` = ? and `user_id` = ? and `status` = ?", id, userId, 1)
|
||||
if len(lock) != 0 && lock[0] {
|
||||
db = db.Set("gorm:query_option", "FOR UPDATE")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user