You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.2 KiB
124 lines
3.2 KiB
package withdrawals
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/order"
|
|
"recook/internal/model/user"
|
|
"recook/internal/static_path"
|
|
user2 "recook/internal/v2/model/recook/user"
|
|
"strconv"
|
|
|
|
"github.com/golangkit/formatime"
|
|
"github.com/shopspring/decimal"
|
|
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func UploadExcel(c *gin.Context) {
|
|
file, err := c.FormFile("excel")
|
|
if err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
name := filepath.Join(static_path.Dir.Excel, file.Filename)
|
|
dst := filepath.Join(static_path.Dir.Root, name)
|
|
err = c.SaveUploadedFile(file, dst)
|
|
if err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
exl, err := excelize.OpenFile(dst)
|
|
if err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
//if Compare(exl, file.Filename) != nil {
|
|
// http.Fail(c, "表格不可更改信息已被强行篡改!请重新下载表格")
|
|
// return
|
|
//}
|
|
//sheet 由recook excel.SheetName 修改为独立的 批次订单
|
|
allRows, _ := exl.GetRows("批次订单") // 获取所有的行
|
|
|
|
tx := dbc.DB.Begin()
|
|
{
|
|
for _, r := range allRows[1:] {
|
|
//if r[11] != "是" && r[11] != "否" {
|
|
// http.Err(c, "信息不匹配")
|
|
// tx.Rollback()
|
|
// return
|
|
//}
|
|
//
|
|
//if r[11] == "是" {
|
|
// id, _ := strconv.Atoi(r[0])
|
|
// d := user.Withdraw{ID: int64(id)}
|
|
// err = tx.Model(&d).Updates(user.Withdraw{Status: 1}).Error
|
|
// if err != nil {
|
|
// http.Err(c, err.Error())
|
|
// tx.Rollback()
|
|
// return
|
|
// }
|
|
//}
|
|
|
|
if r[17] == "已打款" || r[17] == "已支付" {
|
|
id, _ := strconv.Atoi(r[2])
|
|
if id <= 0 {
|
|
continue
|
|
}
|
|
d := user.Withdraw{ID: int64(id)}
|
|
err = tx.Model(&d).Where("id = ?", id).Updates(user.Withdraw{Status: 2, DoneTime: formatime.NewSecondNow()}).Error
|
|
if err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
} else {
|
|
id, _ := strconv.Atoi(r[2])
|
|
if id <= 0 {
|
|
continue
|
|
}
|
|
d := user.Withdraw{ID: int64(id)}
|
|
if tx.Model(&d).Where("id = ?", id).Where("status = ?", 1).Updates(user.Withdraw{FailReason: r[17], Status: 3}).RowsAffected != 1 {
|
|
back.Err(c, fmt.Sprintf("记录%d已打款,请勿重复提交", id))
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
dbc.DB.Find(&d)
|
|
recookUserWalletBalanceListModel := &user2.RecookUserWalletBalanceListModel{
|
|
UserId: d.UserId,
|
|
IncomeType: user2.RecookUserWalletBalanceListIncomeTypeWithdrawFail, // 提现失败
|
|
Amount: decimal.NewFromFloat(d.Amount),
|
|
Title: d.FailReason,
|
|
Comment: "打款失败",
|
|
}
|
|
recookUserWalletBalanceListModel.SetDb(tx)
|
|
recookUserWalletBalanceListModel.Create(recookUserWalletBalanceListModel)
|
|
if recookUserWalletBalanceListModel.Id == 0 {
|
|
back.Err(c, "系统异常")
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
// 更新profit_id 的记录
|
|
tx.Table((&order.Profit{}).TableName()).Where("is_enterprise = 0").Where("deal_id = ?", id).Update("deal_id = ?", 0)
|
|
|
|
//退回到余额
|
|
var wallet user.Wallet
|
|
tx.First(&wallet, "user_id = ?", d.UserId)
|
|
tx.Model(&wallet).Updates(map[string]interface{}{
|
|
"balance": wallet.Balance.Add(decimal.NewFromFloat(d.Amount)),
|
|
})
|
|
|
|
}
|
|
}
|
|
}
|
|
tx.Commit()
|
|
back.Suc(c, "", nil)
|
|
}
|