123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package myselfsrv
- import (
- "Cold_Logistic/internal/pkg/common/codex"
- "Cold_Logistic/internal/pkg/common/constant"
- "Cold_Logistic/internal/server/infra/dao"
- "Cold_Logistic/internal/server/infra/models"
- "context"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- // LogisticPage 物流公司列表
- func (srv *MyselfService) LogisticPage(ctx context.Context, req LogisticPageReqVO) (res core.PageListResponse, err error) {
- dto := dao.LogisticCompanyPageDTO{
- Page: req.Page,
- }
- list, total, err := srv.store.LogisticCompany().Page(ctx, dto)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res.Total = total
- res.TotalPage = total / int64(req.Page.Size)
- res.Count = len(list)
- res.List = list
- return res, nil
- }
- // AddLogistic 添加物流公司
- func (srv *MyselfService) AddLogistic(ctx context.Context, req AddLogisticReqVO) (res LogisticIdRespVO, err error) {
- count, err := srv.store.LogisticCompany().CountMyLogistic(ctx, req.Name, req.Pid)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- if count > 0 {
- return res, errors.WithCode(codex.ErrParamValidate, "该物流公司已添加过")
- }
- logistic := models.LogisticCompany{
- Name: req.Name,
- IsDefault: req.IsDefault,
- Pid: req.Pid,
- }
- err = srv.store.InTx(ctx, func(ctx context.Context) error {
- if err = srv.store.LogisticCompany().Create(ctx, &logistic); err != nil {
- return errors.WithStackOnce(err)
- }
- // 只能有一个默认
- if logistic.IsDefault == constant.YES {
- err = srv.store.LogisticCompany().UpdateDefaultByCreateBy(ctx, constant.NO, logistic.Id)
- if err != nil {
- return errors.WithStackOnce(err)
- }
- }
- return nil
- })
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res.LogisticId = logistic.Id
- return res, nil
- }
- // DeleteLogistic 删除物流公司
- func (srv *MyselfService) DeleteLogistic(ctx context.Context, req DeleteLogisticReqVO) error {
- return srv.store.LogisticCompany().DeleteByIds(ctx, req.LogisticId)
- }
|