2023-06-19 10:27:31 +00:00
|
|
|
package gmodel
|
2023-06-27 06:25:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-29 10:04:59 +00:00
|
|
|
"fusenapi/constants"
|
|
|
|
"time"
|
2023-06-28 11:32:41 +00:00
|
|
|
|
2023-06-27 06:25:25 +00:00
|
|
|
"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
|
|
|
|
})
|
|
|
|
}
|
2023-06-28 11:32:41 +00:00
|
|
|
|
2023-06-29 10:04:59 +00:00
|
|
|
func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64, cs *FsContactService) (cloudOrder *FsCloudPickUp, err error) {
|
|
|
|
err = p.db.WithContext(ctx).Model(cloudOrder).Transaction(func(tx *gorm.DB) error {
|
|
|
|
err = tx.Model(cloudOrder).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, RelationID).Take(&cloudOrder).Error
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ctime := time.Now().Unix()
|
|
|
|
cs.Ctime = &ctime
|
|
|
|
if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT {
|
|
|
|
*cs.RelationId = 0
|
|
|
|
}
|
2023-06-28 11:32:41 +00:00
|
|
|
|
2023-06-29 10:04:59 +00:00
|
|
|
return tx.Model(cs).Create(cs).Error
|
|
|
|
})
|
2023-06-28 11:32:41 +00:00
|
|
|
return cloudOrder, err
|
|
|
|
}
|
2023-06-29 05:59:55 +00:00
|
|
|
|
|
|
|
type GetPickupListByParamReq struct {
|
|
|
|
UserId *int64
|
|
|
|
Status *int64
|
|
|
|
Ids []int64
|
|
|
|
Page int
|
|
|
|
Limit int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *FsCloudPickUpModel) GetPickupListByParam(ctx context.Context, req GetPickupListByParamReq) (resp []FsCloudPickUp, total int64, err error) {
|
|
|
|
db := p.db.WithContext(ctx).Model(&FsCloudPickUp{})
|
|
|
|
if req.UserId != nil {
|
|
|
|
db = db.Where("`user_id` = ?", *req.UserId)
|
|
|
|
}
|
|
|
|
if req.Status != nil {
|
|
|
|
db = db.Where("`status` = ?", *req.Status)
|
|
|
|
}
|
|
|
|
if len(req.Ids) > 0 {
|
|
|
|
db = db.Where("`id` in (?)", req.Ids)
|
|
|
|
}
|
|
|
|
if err = db.Limit(1).Count(&total).Error; err != nil {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
offset := (req.Page - 1) * req.Limit
|
|
|
|
if err = db.Offset(offset).Limit(req.Limit).Order("id desc").Find(&resp).Error; err != nil {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|