Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -1,2 +1,31 @@
|
||||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (p *FsCloudPickUpModel) SavePickUpWithTransaction(ctx context.Context, pickUpData *FsCloudPickUp, stockList []FsUserStock, pickUpDetailAddList []FsCloudPickUpDetail) error {
|
||||
return p.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
//保存总提单信息
|
||||
if err := tx.Model(&FsCloudPickUp{}).Create(&pickUpData).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
//更新云仓库存
|
||||
for _, v := range stockList {
|
||||
if err := tx.Model(&FsUserStock{}).Where("`id` = ?", v.Id).Updates(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//添加提单详情
|
||||
for _, v := range pickUpDetailAddList {
|
||||
v.PickId = &pickUpData.Id //外面没赋值在这需要赋值
|
||||
if err := tx.Model(&FsCloudPickUpDetail{}).Create(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +1,42 @@
|
||||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
type GetStockListReq struct {
|
||||
UserId int64
|
||||
Ids []int64
|
||||
Status *int64
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
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 len(req.Ids) > 0 {
|
||||
db = db.Where("`id` in (?)", req.Ids)
|
||||
}
|
||||
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` = ? and `status` = ?", id, userId, 1)
|
||||
if len(lock) != 0 && lock[0] {
|
||||
db = db.Set("gorm:query_option", "FOR UPDATE")
|
||||
}
|
||||
err = db.First(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user