实现门店桌面设置相关配置

This commit is contained in:
2025-06-19 18:01:47 +08:00
parent fcdc44b94e
commit a25068154f
35 changed files with 372 additions and 335 deletions

View File

@ -173,57 +173,3 @@ func (s *sStore) GetDesktopSetting(ctx context.Context, in *model.StoreGetDeskto
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
}