|
|
|
@@ -4,26 +4,43 @@ import ( |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/grampus" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/services/admin/operate_log" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
|
func AddResourceSpecification(req models.ResourceSpecificationReq) error { |
|
|
|
func AddResourceSpecification(doerId int64, req models.ResourceSpecificationReq) error { |
|
|
|
if req.Status == 0 { |
|
|
|
req.Status = models.SpecNotVerified |
|
|
|
} |
|
|
|
if _, err := models.InsertResourceSpecification(req.ToDTO()); err != nil { |
|
|
|
spec := req.ToDTO() |
|
|
|
if _, err := models.InsertResourceSpecification(spec); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func UpdateResourceSpecification(specId int64, req models.ResourceSpecificationReq) error { |
|
|
|
if _, err := models.UpdateResourceSpecificationById(specId, models.ResourceSpecification{ |
|
|
|
func UpdateResourceSpecification(doerId int64, specId int64, req models.ResourceSpecificationReq) error { |
|
|
|
oldSpec, err := models.GetResourceSpecification(&models.ResourceSpecification{ID: specId}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if oldSpec == nil { |
|
|
|
return errors.New("specification not exist") |
|
|
|
} |
|
|
|
n, err := models.UpdateResourceSpecificationById(specId, models.ResourceSpecification{ |
|
|
|
UnitPrice: req.UnitPrice, |
|
|
|
}); err != nil { |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if n > 0 { |
|
|
|
newSpec, _ := models.GetResourceSpecification(&models.ResourceSpecification{ID: specId}) |
|
|
|
AddSpecOperateLog(doerId, "edit", newSpec, oldSpec, fmt.Sprintf("修改单价从%d积分到%d积分", oldSpec.UnitPrice, newSpec.UnitPrice)) |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
@@ -108,7 +125,7 @@ func GetResourceSpecificationList(opts models.SearchResourceSpecificationOptions |
|
|
|
return models.NewResourceSpecAndQueueListRes(n, r), nil |
|
|
|
} |
|
|
|
|
|
|
|
func ResourceSpecOnShelf(id int64, req models.ResourceSpecificationReq) error { |
|
|
|
func ResourceSpecOnShelf(doerId int64, id int64, req models.ResourceSpecificationReq) error { |
|
|
|
spec, err := models.GetResourceSpecification(&models.ResourceSpecification{ID: id}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
@@ -120,16 +137,20 @@ func ResourceSpecOnShelf(id int64, req models.ResourceSpecificationReq) error { |
|
|
|
return errors.New("resource queue not available") |
|
|
|
} |
|
|
|
|
|
|
|
_, err = models.ResourceSpecOnShelf(id, models.ResourceSpecification{ |
|
|
|
n, err := models.ResourceSpecOnShelf(id, models.ResourceSpecification{ |
|
|
|
UnitPrice: req.UnitPrice, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if n > 0 { |
|
|
|
newSpec, _ := models.GetResourceSpecification(&models.ResourceSpecification{ID: id}) |
|
|
|
AddSpecOperateLog(doerId, "on-shelf", newSpec, spec, fmt.Sprintf("修改单价从%d积分到%d积分", spec.UnitPrice, newSpec.UnitPrice)) |
|
|
|
} |
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
func ResourceSpecOffShelf(id int64) error { |
|
|
|
func ResourceSpecOffShelf(doerId int64, id int64) error { |
|
|
|
_, err := models.ResourceSpecOffShelf(id) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
@@ -137,3 +158,17 @@ func ResourceSpecOffShelf(id int64) error { |
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func AddSpecOperateLog(doerId int64, operateType string, newSpec, oldSpec *models.ResourceSpecification, comment string) { |
|
|
|
newJson, _ := json.Marshal(newSpec) |
|
|
|
oldJson, _ := json.Marshal(oldSpec) |
|
|
|
operate_log.Log(models.AdminOperateLog{ |
|
|
|
BizType: "SpecOperate", |
|
|
|
OperateType: operateType, |
|
|
|
OldValue: string(newJson), |
|
|
|
NewValue: string(oldJson), |
|
|
|
RelatedId: fmt.Sprint(newSpec.ID), |
|
|
|
Comment: comment, |
|
|
|
CreatedBy: doerId, |
|
|
|
}) |
|
|
|
} |