| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package services
- import (
- "app/commons/constant"
- "app/commons/core"
- "app/commons/core/redisclient"
- "app/commons/model/entity"
- "fmt"
- "github.com/demdxx/gocast"
- )
- type TransferParam struct {
- OrderId interface{} `json:"orderId"` // 订单ID 0 表示处理异常订单
- Step interface{} `json:"step"` // 1 通过 非1 驳回
- Desc string `json:"desc"`
- }
- // 处理提现审核
- func (s *CommonService) VerifyWithdrawApply(req *TransferParam) error {
- lockKey := fmt.Sprintf("%s", "VerifyTransferOutApply") // 分布式系统级锁
- lock, err := redisclient.Lock(lockKey)
- if err != nil {
- core.Log.Errorf("转账锁获取锁失败: %v", err)
- return err
- }
- core.Log.Infof("转账锁获取锁成功: %s ", lockKey)
- defer func() {
- err = redisclient.UnlockSafe(lock)
- if err != nil {
- core.Log.Errorf("转账锁解锁失败:%s", err.Error())
- } else {
- core.Log.Infof("转账锁解锁完成 %s UnlockSafe", lockKey)
- }
- }()
- orderId := gocast.ToString(req.OrderId)
- if orderId == "" {
- go s.handleAllWithdraw() // 直接触发转账处理
- return nil
- }
- // 当txId != "" 表示触发审核
- if err = s.verifyWithdrawOrder(req); err != nil {
- return err
- }
- go s.handleAllWithdraw() // 审核完成后 触发转账处理
- return nil
- }
- // 通过或者驳回提现申请
- func (s *CommonService) verifyWithdrawOrder(param *TransferParam) error {
- record, err := s.FirstAssetRwRecord(s.DB().
- Where("order_id = ?", param.OrderId).
- Where("direction", constant.RwDirectionWithdraw).
- Where("status", constant.RwStateWaiting))
- if err != nil {
- return fmt.Errorf("转账状态错误")
- }
- status := constant.RwStateReject // 驳回
- step := gocast.ToInt(param.Step)
- if step == constant.RwStatePass {
- status = constant.RwStatePass // 通过
- }
- record.Describe = fmt.Sprintf("%s\n%s", record.Describe, param.Desc)
- dbTx := s.DB().Begin()
- err = dbTx.Model(&entity.AssetRwRecord{}).
- Where("id", record.Id).
- Where("status", constant.RwStateWaiting).
- Updates(map[string]interface{}{
- "status": status,
- "describe": record.Describe,
- }).Error
- if err != nil {
- dbTx.Rollback()
- core.Log.Error(err.Error())
- return fmt.Errorf("状态修改错误")
- }
- dbTx.Commit()
- return nil
- }
|