feat: 添加租户剩余金额字段及自增更新逻辑
This commit is contained in:
@@ -51,6 +51,7 @@ type TenantEditReq struct {
|
||||
TenantType consts.TenantType `p:"tenantType"`
|
||||
CityCode string `p:"cityCode"`
|
||||
BusinessLicense string `p:"businessLicense"`
|
||||
Surplus float64 `p:"surplus"`
|
||||
commonApi.Author
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ type TenantColumns struct {
|
||||
CityCode string // 城市编码
|
||||
BusinessLicense string // 营业执照
|
||||
TenantSource string // 租户来源
|
||||
Surplus string // 剩余金额
|
||||
}
|
||||
|
||||
// tenantColumns holds the columns for table sys_user.
|
||||
@@ -44,6 +45,7 @@ var tenantColumns = TenantColumns{
|
||||
CityCode: "city_code",
|
||||
BusinessLicense: "business_license",
|
||||
TenantSource: "tenant_source",
|
||||
Surplus: "surplus",
|
||||
}
|
||||
|
||||
// NewTenantDao creates and returns a new DAO object for table data access.
|
||||
|
||||
@@ -258,7 +258,18 @@ func (s *sTenant) Edit(ctx context.Context, req *system.TenantEditReq) (err erro
|
||||
if !g.IsEmpty(req.TenantType) {
|
||||
tenant.TenantType = req.TenantType
|
||||
}
|
||||
_, err = dao.TenantDao.Ctx(ctx).TX(tx).WherePri(req.Id).Update(tenant)
|
||||
_, err = dao.TenantDao.Ctx(ctx).TX(tx).WherePri(req.Id).OmitEmpty().Update(tenant)
|
||||
// 第二步:单独执行 Surplus 自增/自减(纯Counter,官方标准用法)
|
||||
if !g.IsEmpty(req.Surplus) {
|
||||
delta := gconv.Float64(req.Surplus)
|
||||
_, err = dao.TenantDao.Ctx(ctx).TX(tx).WherePri(req.Id).Data(
|
||||
dao.TenantDao.Columns().Surplus,
|
||||
&gdb.Counter{
|
||||
Field: dao.TenantDao.Columns().Surplus,
|
||||
Value: delta,
|
||||
},
|
||||
).Update()
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "修改租户信息失败")
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -23,4 +23,5 @@ type Tenant struct {
|
||||
BusinessLicense interface{} // 营业执照
|
||||
TenantSource interface{} // 租户来源
|
||||
AdminBy interface{} // 管理者
|
||||
Surplus interface{} // 剩余金额
|
||||
}
|
||||
|
||||
@@ -22,4 +22,5 @@ type Tenant struct {
|
||||
BusinessLicense string `json:"businessLicense" description:"营业执照"`
|
||||
TenantSource uint64 `json:"tenantSource" description:"租户来源"`
|
||||
AdminBy uint64 `json:"adminBy" description:"管理者"`
|
||||
Surplus float64 `json:"surplus" description:"剩余金额"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user