12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package service
- import (
- "context"
- "github.com/sirupsen/logrus"
- "youngee_m_api/db"
- "youngee_m_api/model/http_model"
- )
- var ProjectPay *projectPay
- type projectPay struct {
- }
- func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequest, enterpriseID string) (*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, 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, projectPay.ProjectID)
- if err1 != nil {
- logrus.WithContext(ctx).Errorf("[projectPay service] call CreatePayRecord error,err:%+v", err)
- return nil, err1
- }
- // 支付更新任务状态
- err = db.UpdateTaskSelectAtByProjectId(ctx, projectPay.ProjectID, 2)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
- return nil, err
- }
- err = db.UpdateTaskStageByProjectId(ctx, projectPay.ProjectID, 2, 4)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateTaskStatusPaying error,err:%+v", err)
- return nil, err
- }
- return recordId, nil
- }
|