project_pay.go 1.5 KB

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