project_pay.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "context"
  4. "github.com/caixw/lib.go/conv"
  5. "github.com/sirupsen/logrus"
  6. "youngee_m_api/db"
  7. "youngee_m_api/model/http_model"
  8. )
  9. var ProjectPay *projectPay
  10. type projectPay struct {
  11. }
  12. func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequest, enterpriseID int64) (*int64, error) {
  13. // 修改企业账户金额
  14. balance, err := db.UpdateEnterpriseBalance(ctx, enterpriseID, 0, -projectPay.PaySum, projectPay.PaySum)
  15. if err != nil {
  16. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateEnterpriseBalance error,err:%+v", err)
  17. return nil, err
  18. }
  19. // 修改项目状态为执行中
  20. err = db.UpdateProjectStatus(ctx, conv.MustInt64(projectPay.ProjectID, 0), 9)
  21. if err != nil {
  22. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateEnterpriseBalance error,err:%+v", err)
  23. return nil, err
  24. }
  25. // 插入支付记录
  26. recordId, err1 := db.CreatePayRecord(ctx, enterpriseID, projectPay.PaySum, *balance, 2, conv.MustInt64(projectPay.ProjectID, 0))
  27. if err1 != nil {
  28. logrus.WithContext(ctx).Errorf("[projectPay service] call CreatePayRecord error,err:%+v", err)
  29. return nil, err1
  30. }
  31. // 支付更新任务状态
  32. err = db.UpdateTaskSelectAtByProjectId(ctx, conv.MustInt64(projectPay.ProjectID, 0), 2)
  33. if err != nil {
  34. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  35. return nil, err
  36. }
  37. err = db.UpdateTaskStageByProjectId(ctx, conv.MustInt64(projectPay.ProjectID, 0), 2, 4)
  38. if err != nil {
  39. logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
  40. return nil, err
  41. }
  42. return recordId, nil
  43. }