package service import ( "context" "youngee_b_api/db" "youngee_b_api/model/http_model" "github.com/issue9/conv" "github.com/sirupsen/logrus" ) var ProjectPay *projectPay type projectPay struct { } func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequest, enterpriseID int64) (*int64, error) { // 修改企业账户金额 balance, err := db.UpdateEnterpriseBalance(ctx, enterpriseID, 0, -projectPay.PaySum, projectPay.PaySum) if err != nil { logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateEnterpriseBalance error,err:%+v", err) return nil, err } // 修改项目状态为执行中 err = db.UpdateProjectStatus(ctx, conv.MustInt64(projectPay.ProjectID), 9) if err != nil { logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateEnterpriseBalance error,err:%+v", err) return nil, err } // 插入支付记录 recordId, err1 := db.CreatePayRecord(ctx, enterpriseID, projectPay.PaySum, *balance, 2, conv.MustInt64(projectPay.ProjectID)) if err1 != nil { logrus.WithContext(ctx).Errorf("[projectPay service] call CreatePayRecord error,err:%+v", err) return nil, err1 } return recordId, nil }