实现了门店员工、员工角色的接口开发
This commit is contained in:
@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"server/internal/consts"
|
||||
"server/internal/dao"
|
||||
"server/internal/model"
|
||||
@ -152,3 +153,77 @@ func (s *sStore) Info(ctx context.Context, in *model.StoreInfoIn) (out *model.St
|
||||
// TODO 获取门店信息等相关信息
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sStore) GetDesktopSetting(ctx context.Context, in *model.StoreGetDesktopSettingIn) (*model.StoreGetDesktopSettingOut, error) {
|
||||
// 检查门店桌面设置是否存在
|
||||
exist, err := dao.StoreDesktopSettings.Ctx(ctx).Where(do.StoreDesktopSettings{StoreId: in.StoreId}).Count()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(ecode.Fail, "查询门店桌面设置出现异常")
|
||||
}
|
||||
if exist == 0 {
|
||||
return &model.StoreGetDesktopSettingOut{}, nil
|
||||
}
|
||||
|
||||
// 查询桌面设置
|
||||
out := &model.StoreGetDesktopSettingOut{}
|
||||
err = dao.StoreDesktopSettings.Ctx(ctx).Where(do.StoreDesktopSettings{StoreId: in.StoreId}).Scan(out)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(ecode.Fail, "查询门店桌面设置出现异常")
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *sStore) SaveDesktopSetting(ctx context.Context, in *model.SaveDesktopSettingIn) (*model.SaveDesktopSettingOut, error) {
|
||||
out := &model.SaveDesktopSettingOut{}
|
||||
err := dao.StoreDesktopSettings.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
// 构建数据,包含所有字段
|
||||
data := do.StoreDesktopSettings{
|
||||
Id: in.Id,
|
||||
StoreId: in.StoreId,
|
||||
BackgroundUrl: in.BackgroundUrl,
|
||||
Resolution: in.Resolution,
|
||||
IsTopWidgetVisible: in.IsTopWidgetVisible,
|
||||
IsRightWidgetVisible: in.IsRightWidgetVisible,
|
||||
}
|
||||
|
||||
// 检查记录是否存在(基于 store_id)
|
||||
exist, err := dao.StoreDesktopSettings.Ctx(ctx).TX(tx).Where(do.StoreDesktopSettings{StoreId: in.StoreId}).Count()
|
||||
if err != nil {
|
||||
return gerror.Wrap(ecode.Fail, "检查门店桌面设置失败")
|
||||
}
|
||||
|
||||
if exist == 0 {
|
||||
// 新增
|
||||
result, err := dao.StoreDesktopSettings.Ctx(ctx).TX(tx).Data(data).Insert()
|
||||
if err != nil {
|
||||
return gerror.Wrap(ecode.Fail, "新增门店桌面设置失败")
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return gerror.Wrap(ecode.Fail, "获取新增记录ID失败")
|
||||
}
|
||||
out.Id = id
|
||||
} else {
|
||||
// 更新(如果提供了 Id,则优先使用 Id 作为条件,否则使用 StoreId)
|
||||
updateWhere := do.StoreDesktopSettings{StoreId: in.StoreId}
|
||||
if in.Id > 0 {
|
||||
updateWhere = do.StoreDesktopSettings{Id: in.Id}
|
||||
}
|
||||
_, err := dao.StoreDesktopSettings.Ctx(ctx).TX(tx).Data(data).Where(updateWhere).Update()
|
||||
if err != nil {
|
||||
return gerror.Wrap(ecode.Fail, "更新门店桌面设置失败")
|
||||
}
|
||||
id, err := dao.StoreDesktopSettings.Ctx(ctx).TX(tx).Where(updateWhere).Fields(dao.StoreDesktopSettings.Columns().Id).Value()
|
||||
if err != nil {
|
||||
return gerror.Wrap(ecode.Fail, "获取更新记录ID失败")
|
||||
}
|
||||
out.Id = id.Int64()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user