k.zhang 1 ano atrás
pai
commit
fffff94264
4 arquivos alterados com 92 adições e 4 exclusões
  1. 9 1
      apis/shanghu/pay.go
  2. 67 0
      models/shanghu/pay.go
  3. 13 0
      report/cash.out.go
  4. 3 3
      report/report.go

+ 9 - 1
apis/shanghu/pay.go

@@ -180,7 +180,15 @@ func PayCashOut(c *gin.Context) {
 			app.Error(c, 400, errors.New("账号余额不够"), "账号余额不够")
 			return
 		}
-		cashOut.Fee = inData.Amount.Mul(decimal.NewFromFloat32(0.1))
+		var client shanghu.MerchantClientUser
+		client.Code = "7jb6"
+		clientInfo, _ := client.GetUserInfoByCode()
+		if clientInfo.ClientOpenID == inData.OpenId {
+			cashOut.Fee = decimal.NewFromInt(0)
+		} else {
+			cashOut.Fee = inData.Amount.Mul(decimal.NewFromFloat32(0.05))
+		}
+
 	} else if inData.AccountType == "merchant" {
 		merchantAccountSql.MerchantOpenID = inData.OpenId
 		merchantAccountInfo, err := merchantAccountSql.GetMerchantAccount()

+ 67 - 0
models/shanghu/pay.go

@@ -304,6 +304,73 @@ func (m *ClientPayTrans) SettleAdd(merchantAmount, clientAmount decimal.Decimal,
 
 }
 
+func (m *ClientPayTrans) SettleAddCashOutFee(amount decimal.Decimal, clientOpenId string, cashOutId int64) error {
+	// 使用事务 添加
+	var err error
+	var clientAccount MerchantClientAccount
+	var amountPreClient decimal.Decimal
+	tx := orm.ShMysql.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	err = tx.Table("merchant_client_account").Select("*").Where("client_open_id = ?", clientOpenId).Find(&clientAccount).Error
+	if err != nil && err.Error() != "record not found" {
+		return err
+	}
+
+	if clientAccount.ID == 0 {
+		clientAccount.ClientOpenID = clientOpenId
+		clientAccount.Version = 1
+		clientAccount.UpdatedAt = time.Now()
+		clientAccount.CreatedAt = time.Now()
+		err = tx.Table("merchant_client_account").Create(&clientAccount).Error
+		if err != nil {
+			return err
+		}
+	}
+	amountPreClient = clientAccount.Amount
+
+	clientAmountAdd := clientAccount.Amount.Add(amount)
+	result := tx.Table("merchant_client_account").Model(&clientAccount).Where("client_open_id = ? and version = ?", clientOpenId, clientAccount.Version).Updates(
+		map[string]interface{}{
+			"amount":     clientAmountAdd,
+			"version":    clientAccount.Version + 1,
+			"updated_at": time.Now()})
+	if result.Error != nil {
+		return result.Error
+	}
+
+	if result.RowsAffected <= 0 {
+		err = errors.New("rows is zero")
+		return err
+	}
+
+	var clientAccountLog MerchantClientAccountLog
+
+	clientAccountLog.ClientOpenID = clientOpenId
+	clientAccountLog.UpdatedAt = time.Now()
+	clientAccountLog.AmountPre = amountPreClient
+	clientAccountLog.AmountAfter = clientAmountAdd
+	clientAccountLog.ReviewAmountAfter = clientAccount.ReviewAmount
+	clientAccountLog.ReviewAmountPre = clientAccount.ReviewAmount
+	clientAccountLog.Amount = amount
+	clientAccountLog.PayTransId = cashOutId
+	clientAccountLog.TransType = 3 //服务费
+
+	err = tx.Table("merchant_client_account_log").Create(&clientAccountLog).Error
+	if err != nil {
+		return err
+	}
+
+	return nil
+
+}
+
 func (m *ClientPayTrans) SettleSubClient(clientAmount decimal.Decimal, clientOpenId string, cashOutId int64) error {
 	// 使用事务 添加
 	var err error

+ 13 - 0
report/cash.out.go

@@ -110,6 +110,19 @@ func CashOutAccount() {
 				cashOut.UpdateCashOutAccountStatus()
 				continue
 			}
+
+			//给
+			var client shanghu.MerchantClientUser
+
+			client.Code = "7jb6"
+			clientInfo, _ := client.GetUserInfoByCode()
+			if clientInfo.ClientOpenID == account.ClientOpenID { //超级管理员钱已经有了不需要收服务费
+				continue
+			} else { //服务费加到超级管理员账户
+				var accountClient shanghu.ClientPayTrans
+				accountClient.SettleAddCashOutFee(cashOutInfo.Fee, clientInfo.ClientOpenID, cashOutInfo.ID)
+			}
+
 		} else {
 			continue
 		}

+ 3 - 3
report/report.go

@@ -12,8 +12,8 @@ const (
 
 func SysCronStart() {
 	c := cron.New()
-	c.AddFunc(cronMinuteStart, ClientAccount) //每分钟同步一下订单
-	c.AddFunc(cronMinuteStart, CashOut)       //每分钟同步一下订单
-	c.AddFunc(cronMinuteTwoStart, CashOutAccount)
+	c.AddFunc(cronMinuteStart, ClientAccount)     //每分钟同步一下订单
+	c.AddFunc(cronMinuteStart, CashOut)           //提现
+	c.AddFunc(cronMinuteTwoStart, CashOutAccount) //提现账户扣减
 	c.Start()
 }