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.
294 lines
6.1 KiB
294 lines
6.1 KiB
package withdrawals
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2"
|
|
"path/filepath"
|
|
"recook/internal/model/user"
|
|
"recook/internal/static_path"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
SheetName = "recook"
|
|
|
|
excelColArray = []string{
|
|
//"*提现原始号/25",
|
|
//"*提现账户原始号/25",
|
|
//"*提现记录号/25",
|
|
"*时间/25",
|
|
"商户订单号(非必填)/25",
|
|
"收款账号(个人银行卡号)/30",
|
|
"收款账号(支付宝账号)/30",
|
|
"*收款户名(真实姓名)/20",
|
|
"*身份证号/30",
|
|
"*金额(元)/20",
|
|
"*打款备注(20个字符以内)/30",
|
|
"打款状态/20",
|
|
"*提现金额/20",
|
|
"*平台已交税费(元)/20",
|
|
"*实际打款金额(元)/20",
|
|
}
|
|
|
|
excelLetters = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
|
|
|
|
excelDesc = `说明:
|
|
1.标记为*的栏目不可更改,否则上传文件后系统将会拒绝录入付款信息!
|
|
2.请在付款完成后标记"打款状态"栏目为"是"。`
|
|
)
|
|
|
|
func Create(rows [][]interface{}) *excelize.File {
|
|
f := newExcelFile()
|
|
pointLine := 4
|
|
|
|
for _, v := range rows {
|
|
f.SetCellStyle(SheetName, axis("A", pointLine), axis(excelLetters[len(v)-1], pointLine), commonStyle(f))
|
|
//f.SetCellStyle(SheetName, axis(excelLetters[len(v)], pointLine), axis(excelLetters[len(v)+1], pointLine), dataStyle(f, i))
|
|
|
|
f.SetRowHeight(SheetName, pointLine, 21) // 设置行高度
|
|
for idx, val := range v {
|
|
f.SetCellValue(SheetName, axis(excelLetters[idx], pointLine), val)
|
|
}
|
|
pointLine++
|
|
}
|
|
|
|
return f
|
|
}
|
|
|
|
func MapToPtrArray(d *user.Withdraw, u *user.Information) []interface{} {
|
|
var array []interface{}
|
|
//array = append(array, d.ID)
|
|
//array = append(array, "")
|
|
//array = append(array, "")
|
|
array = append(array, d.CreatedAt.Time.Format("2006-01-02 15:04:05"))
|
|
array = append(array, d.ID)
|
|
if d.Type == 2 {
|
|
array = append(array, d.BankAccount)
|
|
array = append(array, "")
|
|
} else {
|
|
array = append(array, "")
|
|
array = append(array, d.Alipay)
|
|
}
|
|
array = append(array, u.RealName)
|
|
array = append(array, u.IDCard)
|
|
array = append(array, d.Amount)
|
|
array = append(array, "")
|
|
array = append(array, "否")
|
|
array = append(array, d.TaxFee)
|
|
array = append(array, d.ActualAmount)
|
|
return array
|
|
}
|
|
|
|
func Compare(f *excelize.File, filename string) error {
|
|
p := filepath.Join(static_path.Dir.Root, static_path.Dir.Excel, filename)
|
|
origin, err := excelize.OpenFile(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
originRows, _ := origin.GetRows(SheetName)
|
|
originRows = originRows[3:]
|
|
|
|
nowRows, _ := f.GetRows(SheetName)
|
|
nowRows = nowRows[3:]
|
|
|
|
length := len(excelColArray) - 2
|
|
|
|
for index, row := range originRows {
|
|
now := nowRows[index]
|
|
|
|
ok := true
|
|
for point := 0; point < length; point++ {
|
|
ok = row[point] == now[point]
|
|
}
|
|
|
|
if ok == false {
|
|
return errors.New("信息已被篡改")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func axis(letter string, line int) string {
|
|
return fmt.Sprintf("%v%d", letter, line)
|
|
}
|
|
|
|
func newExcelFile() *excelize.File {
|
|
f := excelize.NewFile()
|
|
{
|
|
index := f.NewSheet(SheetName)
|
|
// 设置工作簿的默认工作表
|
|
f.SetActiveSheet(index)
|
|
f.DeleteSheet("Sheet1")
|
|
|
|
f.SetRowHeight(SheetName, 1, 40) // 设置行高度
|
|
f.MergeCell(SheetName, "A1", "Z1")
|
|
f.SetCellStyle(SheetName, "A1", "R1", tableHeaderStyle(f))
|
|
f.SetCellValue(SheetName, "A1", "瑞库客---用户提现记录表")
|
|
|
|
f.SetRowHeight(SheetName, 2, 90)
|
|
f.MergeCell(SheetName, "A2", "Z2")
|
|
f.SetCellStyle(SheetName, "A2", "Z2", tableTipsLineStyle(f))
|
|
f.SetCellValue(SheetName, "A2", excelDesc)
|
|
|
|
f.SetRowHeight(SheetName, 3, 25)
|
|
f.SetCellStyle(SheetName, "A3", "Z3", tableTitleLineStyle(f))
|
|
|
|
for i, v := range excelColArray {
|
|
array := strings.Split(v, "/")
|
|
t := array[0]
|
|
w, _ := strconv.Atoi(array[1])
|
|
f.SetCellValue(SheetName, fmt.Sprintf("%v3", excelLetters[i]), t)
|
|
f.SetColWidth(SheetName, excelLetters[i], excelLetters[i], float64(w))
|
|
}
|
|
}
|
|
return f
|
|
}
|
|
|
|
func tableHeaderStyle(f *excelize.File) int {
|
|
s := `{
|
|
"fill":{
|
|
"type":"pattern",
|
|
"pattern":17,
|
|
"color":["#3CB371"]
|
|
},
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":20,
|
|
"color":"#000000"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
}
|
|
|
|
func tableTipsLineStyle(f *excelize.File) int {
|
|
s := `{
|
|
"fill":{
|
|
"type":"pattern",
|
|
"pattern":2,
|
|
"color":["#FFE4B5"]
|
|
},
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":10,
|
|
"color":"#ea0b1e"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
}
|
|
|
|
func tableTitleLineStyle(f *excelize.File) int {
|
|
s := `{
|
|
"fill":{
|
|
"type":"pattern",
|
|
"pattern":2,
|
|
"color":["#00BFFF"]
|
|
},
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":12,
|
|
"color":"#000000"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
}
|
|
|
|
func commonStyle(f *excelize.File) int {
|
|
s := `{
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":12,
|
|
"color":"#000000"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
}
|
|
|
|
func dataStyle(f *excelize.File, idx int) int {
|
|
d := idx % 2
|
|
if d == 0 {
|
|
s := `{
|
|
"fill":{
|
|
"type":"pattern",
|
|
"pattern":2,
|
|
"color":["#2E8B57"]
|
|
},
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":12,
|
|
"color":"#000000"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
} else {
|
|
s := `{
|
|
"fill":{
|
|
"type":"pattern",
|
|
"pattern":2,
|
|
"color":["#FF3030"]
|
|
},
|
|
"font":{
|
|
"bold":true,
|
|
"italic":false,
|
|
"family":"宋体",
|
|
"size":12,
|
|
"color":"#000000"
|
|
},
|
|
"alignment":{
|
|
"horizontal":"left",
|
|
"vertical":"center",
|
|
"wrap_text":true
|
|
}
|
|
}`
|
|
|
|
style, _ := f.NewStyle(s)
|
|
return style
|
|
}
|
|
}
|