由gopath形式改为module

This commit is contained in:
kongyuebin
2021-04-27 15:33:49 +08:00
parent aef4dbb33c
commit 77d895e83a
1117 changed files with 332447 additions and 20 deletions

View File

@@ -0,0 +1,88 @@
/***************************************************
** @Desc : This file for 账户变动
** @Time : 19.12.10 10:42
** @Author : Joker
** @File : account_history
** @Last Modified by : Joker
** @Last Modified time: 19.12.10 10:42
** @Software: GoLand
****************************************************/
package controllers
import (
"merchant/models"
"merchant/sys/enum"
"strconv"
"strings"
)
type History struct {
KeepSession
}
// 账户资产变动列表
func (c *History) ShowHistoryListUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["payType"] = enum.GetHistoryStatus()
c.Data["userName"] = u.MerchantName
c.TplName = "history_record.html"
}
func (c *History) HistoryQueryAndListPage() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 分页参数
page, _ := strconv.Atoi(c.GetString("page"))
limit, _ := strconv.Atoi(c.GetString("limit"))
if limit == 0 {
limit = 15
}
// 查询参数
in := make(map[string]string)
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
status := strings.TrimSpace(c.GetString("status"))
in["type"] = status
in["account_uid"] = u.MerchantUid
if start != "" {
in["create_time__gte"] = start
}
if end != "" {
in["create_time__lte"] = end
}
// 计算分页数
count := models.GetAccountHistoryLenByMap(in)
totalPage := count / limit // 计算总页数
if count%limit != 0 { // 不满一页的数据按一页计算
totalPage++
}
// 数据获取
var list []models.AccountHistoryInfo
if page <= totalPage {
list = models.GetAccountHistoryByMap(in, limit, (page-1)*limit)
}
// 数据回显
out := make(map[string]interface{})
out["limit"] = limit // 分页数据
out["page"] = page
out["totalPage"] = totalPage
out["root"] = list // 显示数据
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}

View File

@@ -0,0 +1,427 @@
/***************************************************
** @Desc : This file for 处理Excel文件
** @Time : 19.12.6 16:25
** @Author : Joker
** @File : deal_excel
** @Last Modified by : Joker
** @Last Modified time: 19.12.6 16:25
** @Software: GoLand
****************************************************/
package controllers
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"github.com/tealeg/xlsx"
"merchant/models"
"merchant/sys/enum"
"merchant/utils"
"os"
"strings"
"time"
)
type DealExcel struct {
KeepSession
}
// 下载模板
func (c *DealExcel) DownloadExcelModel() {
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Ctx.Output.Download(enum.ExcelModelPath, enum.ExcelModelName)
}
// 导出订单记录
func (c *DealExcel) MakeOrderExcel() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 查询参数
in := make(map[string]string)
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
payType := strings.TrimSpace(c.GetString("pay_type"))
status := strings.TrimSpace(c.GetString("status"))
in["pay_type_code"] = payType
in["status"] = status
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["update_time__gte"] = start
}
if end != "" {
in["update_time__lte"] = end
}
var (
msg = enum.FailedString
flag = enum.FailedFlag
fileName = "trade_order-" + pubMethod.GetNowTimeV2() + pubMethod.RandomString(6) + ".xlsx"
file *xlsx.File
sheet *xlsx.Sheet
row *xlsx.Row
cell *xlsx.Cell
err error
)
// 数据获取
list := models.GetOrderProfitByMap(in, -1, 0)
if len(list) <= 0 {
msg = "没有检索到数据!"
goto stopRun
}
// 写入记录
file = xlsx.NewFile()
sheet, err = file.AddSheet("订单记录")
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出订单记录,发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
// 第一行
row = sheet.AddRow()
row.SetHeightCM(1)
cell = row.AddCell()
cell.Value = "平台订单号"
cell = row.AddCell()
cell.Value = "商户订单号"
cell = row.AddCell()
cell.Value = "支付方式"
cell = row.AddCell()
cell.Value = "订单金额"
cell = row.AddCell()
cell.Value = "收入金额"
cell = row.AddCell()
cell.Value = "手续费"
cell = row.AddCell()
cell.Value = "状 态"
cell = row.AddCell()
cell.Value = "成功支付时间"
for _, v := range list {
addRow := sheet.AddRow()
addCell := addRow.AddCell()
addCell.Value = v.BankOrderId
addCell = addRow.AddCell()
addCell.Value = v.MerchantOrderId
addCell = addRow.AddCell()
addCell.Value = v.PayProductName
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.OrderAmount)
var (
st = ""
t string
)
switch v.Status {
case "failed":
st = "交易失败"
case "wait":
st = "等待支付"
case "success":
st = "交易成功"
t = v.UpdateTime
}
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.UserInAmount)
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.AllProfit)
addCell = addRow.AddCell()
addCell.Value = st
addCell = addRow.AddCell()
addCell.Value = t
}
err = file.Save(enum.ExcelDownloadPath + fileName)
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出订单记录,保存文件发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
flag = enum.SuccessFlag
msg = fileName
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 下载excel
func (c *DealExcel) DownloadRecordExcel() {
fileName := c.GetString(":params")
file := enum.ExcelDownloadPath + fileName
defer func() {
if r := recover(); r != nil {
logs.Error(fmt.Sprintf("%s此文件不存在",file))
time.Sleep(3 * time.Second)
}
}()
// 删除临时文件
go func() {
tk := time.NewTicker(5 * time.Minute)
select {
case <-tk.C:
_ = os.Remove(file)
tk.Stop()
}
}()
c.Ctx.Output.Download(file, fileName)
}
// 导出投诉记录
func (c *DealExcel) MakeComplaintExcel() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 查询参数
in := make(map[string]string)
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
payType := strings.TrimSpace(c.GetString("pay_type"))
status := strings.TrimSpace(c.GetString("status"))
in["pay_type_code"] = payType
if strings.Compare("YES", status) == 0 {
in["freeze"] = enum.YES
} else {
in["refund"] = enum.YES
}
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["update_time__gte"] = start
}
if end != "" {
in["update_time__lte"] = end
}
var (
msg = enum.FailedString
flag = enum.FailedFlag
fileName = "complaint_order-" + pubMethod.GetNowTimeV2() + pubMethod.RandomString(6) + ".xlsx"
file *xlsx.File
sheet *xlsx.Sheet
row *xlsx.Row
cell *xlsx.Cell
err error
)
// 数据获取
list := models.GetOrderByMap(in, -1, 0)
if len(list) <= 0 {
msg = "没有检索到数据!"
goto stopRun
}
// 写入记录
file = xlsx.NewFile()
sheet, err = file.AddSheet("投诉记录")
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出投诉记录,发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
// 第一行
row = sheet.AddRow()
row.SetHeightCM(1)
cell = row.AddCell()
cell.Value = "平台流水号"
cell = row.AddCell()
cell.Value = "商户订单号"
cell = row.AddCell()
cell.Value = "支付方式"
cell = row.AddCell()
cell.Value = "订单金额"
cell = row.AddCell()
cell.Value = "状 态"
cell = row.AddCell()
cell.Value = "冻结时间"
for _, v := range list {
addRow := sheet.AddRow()
addCell := addRow.AddCell()
addCell.Value = v.BankOrderId
addCell = addRow.AddCell()
addCell.Value = v.MerchantOrderId
addCell = addRow.AddCell()
addCell.Value = v.PayProductName
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.OrderAmount)
var st = ""
switch v.Freeze {
case "yes":
st = "已冻结"
case "no":
st = "已退款"
}
addCell = addRow.AddCell()
addCell.Value = st
addCell = addRow.AddCell()
addCell.Value = v.UpdateTime
}
err = file.Save(enum.ExcelDownloadPath + fileName)
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出投诉记录,保存文件发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
flag = enum.SuccessFlag
msg = fileName
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 导出提现记录
func (c *DealExcel) MakeWithdrawExcel() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 查询参数
in := make(map[string]string)
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
status := strings.TrimSpace(c.GetString("status"))
in["status"] = status
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["update_time__gte"] = start
}
if end != "" {
in["update_time__lte"] = end
}
var (
msg = enum.FailedString
flag = enum.FailedFlag
fileName = "withdraw_order-" + pubMethod.GetNowTimeV2() + pubMethod.RandomString(6) + ".xlsx"
file *xlsx.File
sheet *xlsx.Sheet
row *xlsx.Row
cell *xlsx.Cell
err error
)
// 数据获取
list := models.GetPayForByMap(in, -1, 0)
if len(list) <= 0 {
msg = "没有检索到数据!"
goto stopRun
}
// 写入记录
file = xlsx.NewFile()
sheet, err = file.AddSheet("提现记录")
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出提现记录,发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
// 第一行
row = sheet.AddRow()
row.SetHeightCM(1)
cell = row.AddCell()
cell.Value = "平台订单号"
cell = row.AddCell()
cell.Value = "商户订单号"
cell = row.AddCell()
cell.Value = "结算金额"
cell = row.AddCell()
cell.Value = "手续费"
cell = row.AddCell()
cell.Value = "银行名称"
cell = row.AddCell()
cell.Value = "开户名"
cell = row.AddCell()
cell.Value = "开户账户"
cell = row.AddCell()
cell.Value = "状 态"
cell = row.AddCell()
cell.Value = "创建时间"
cell = row.AddCell()
cell.Value = "打款时间"
cell = row.AddCell()
cell.Value = "备注"
for _, v := range list {
addRow := sheet.AddRow()
addCell := addRow.AddCell()
addCell.Value = v.BankOrderId
addCell = addRow.AddCell()
addCell.Value = v.MerchantOrderId
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.PayforTotalAmount)
addCell = addRow.AddCell()
addCell.Value = fmt.Sprintf("%f", v.PayforFee)
addCell = addRow.AddCell()
addCell.Value = v.BankName
addCell = addRow.AddCell()
addCell.Value = v.BankAccountName
addCell = addRow.AddCell()
addCell.Value = v.BankAccountNo
var (
st = ""
t string
)
switch v.Status {
case "payfor_confirm":
st = "等待审核"
case "payfor_solving":
st = "系统处理中"
case "payfor_banking":
st = "银行处理中"
case "success":
st = "代付成功"
t = v.UpdateTime
case "failed":
st = "代付失败"
}
addCell = addRow.AddCell()
addCell.Value = st
addCell = addRow.AddCell()
addCell.Value = v.CreateTime
addCell = addRow.AddCell()
addCell.Value = t
addCell = addRow.AddCell()
addCell.Value = v.Remark
}
err = file.Save(enum.ExcelDownloadPath + fileName)
if err != nil {
utils.LogError(fmt.Sprintf("商户:%s 导出提现记录,保存文件发生错误:%v", u.MerchantName, err))
msg = enum.FailedToAdmin
goto stopRun
}
flag = enum.SuccessFlag
msg = fileName
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}

View File

@@ -0,0 +1,156 @@
/***************************************************
** @Desc : This file for 首页
** @Time : 19.11.30 11:49
** @Author : Joker
** @File : index
** @Last Modified by : Joker
** @Last Modified time: 19.11.30 11:49
** @Software: GoLand
****************************************************/
package controllers
import (
"fmt"
"merchant/models"
"merchant/sys/enum"
)
type Index struct {
KeepSession
}
// 首页
func (c *Index) ShowUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
c.Data["userName"] = u.MerchantName
c.TplName = "index.html"
}
// 加载用户账户金额信息
func (c *Index) LoadUserAccountInfo() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ac := models.GetAccountByUid(u.MerchantUid)
info := make(map[string]interface{})
// 账户余额
info["balanceAmt"] = pubMethod.FormatFloat64ToString(ac.Balance)
// 可用余额
info["settAmount"] = pubMethod.FormatFloat64ToString(ac.WaitAmount)
// 冻结金额
info["freezeAmt"] = pubMethod.FormatFloat64ToString(ac.FreezeAmount)
// 押款金额
info["amountFrozen"] = pubMethod.FormatFloat64ToString(ac.LoanAmount)
c.Data["json"] = info
c.ServeJSON()
c.StopRun()
}
// 加载总订单信息
func (c *Index) LoadCountOrder() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
md := models.GetMerchantDeployByUid(u.MerchantUid)
type orderInPayWay struct {
PayWayName string // 支付方式名
OrderCount int // 订单数
SucOrderCount int // 成功订单数
SucRate string // 成功率
}
ways := make([]orderInPayWay, len(md))
for k, v := range md {
in := make(map[string]string)
in["merchant_uid"] = u.MerchantUid
ways[k].PayWayName = models.GetRoadInfoByRoadUid(v.SingleRoadUid).ProductName
in["road_uid"] = v.SingleRoadUid
ways[k].OrderCount = models.GetOrderLenByMap(in)
in["status"] = enum.SUCCESS
ways[k].SucOrderCount = models.GetOrderLenByMap(in)
if ways[k].OrderCount == 0 {
ways[k].SucRate = "0"
continue
}
ways[k].SucRate = fmt.Sprintf("%0.4f", float64(ways[k].SucOrderCount)/float64(ways[k].OrderCount))
}
c.Data["json"] = ways
c.ServeJSON()
c.StopRun()
}
// 加载总订单数
func (c *Index) LoadOrderCount() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
out := make(map[string]interface{})
in := make(map[string]string)
in["merchant_uid"] = u.MerchantUid
out["orders"] = models.GetOrderLenByMap(in)
in["status"] = enum.SUCCESS
out["suc_orders"] = models.GetOrderLenByMap(in)
if out["orders"].(int) == 0 {
out["suc_rate"] = 0
} else {
out["suc_rate"] = fmt.Sprintf("%0.4f", float64(out["suc_orders"].(int))/float64(out["orders"].(int)))
}
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}
// 加载用户支付配置
func (c *Index) LoadUserPayWayUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
c.Data["userName"] = u.MerchantName
c.TplName = "pay_way.html"
}
func (c *Index) LoadUserPayWay() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
md := models.GetMerchantDeployByUid(u.MerchantUid)
type payConfig struct {
No string // 通道编号
Name string // 产品名
Rate float64 // 通道费率
}
ways := make([]payConfig, len(md))
for k, v := range md {
road := models.GetRoadInfoByRoadUid(v.SingleRoadUid)
ways[k].No = road.RoadUid
ways[k].Name = road.ProductName
ways[k].Rate = road.BasicFee + v.SingleRoadPlatformRate + v.SingleRoadAgentRate
}
c.Data["json"] = ways
c.ServeJSON()
c.StopRun()
}

View File

@@ -0,0 +1,51 @@
/***************************************************
** @Desc : This file for 保持会话
** @Time : 19.11.29 13:55
** @Author : Joker
** @File : keep_session
** @Last Modified by : Joker
** @Last Modified time: 19.11.29 13:55
** @Software: GoLand
****************************************************/
package controllers
import (
beego "github.com/beego/beego/v2/server/web"
"merchant/sys/enum"
)
type KeepSession struct {
beego.Controller
}
// 生成随机md5值客户端和服务端各保存一份
// 客户端每次请求都将重写md5值
// 若用户在30分钟内没有操作行为或连续操作时间超过3小时则自动退出
func (c *KeepSession) Prepare() {
// 以免session值不是string类型而panic
defer func() {
if err := recover(); err != nil {
c.DelSession(enum.UserSession)
c.Ctx.Redirect(302, "/")
}
}()
us := c.GetSession(enum.UserSession)
uc := c.GetSession(enum.UserCookie)
if us == nil || uc == nil {
c.DelSession(enum.UserSession)
c.Ctx.Redirect(302, "/")
}
if uc.(string) == "" {
c.DelSession(enum.UserSession)
c.Ctx.Redirect(302, "/")
}
_, b := c.Ctx.GetSecureCookie(uc.(string), enum.UserCookie)
//utils.LogNotice(fmt.Sprintf("客户端cookie%s服务端cookie%s", cookie, uc.(string)))
if !b {
c.DelSession(enum.UserSession)
c.Ctx.Redirect(302, "/")
}
}

View File

@@ -0,0 +1,154 @@
/***************************************************
** @Desc : This file for 用户登录
** @Time : 19.11.29 13:52
** @Author : Joker
** @File : login
** @Last Modified by : Joker
** @Last Modified time: 19.11.29 13:52
** @Software: GoLand
****************************************************/
package controllers
import (
"fmt"
beego "github.com/beego/beego/v2/server/web"
"github.com/dchest/captcha"
"merchant/models"
"merchant/sys"
"merchant/sys/enum"
"merchant/utils"
"strconv"
"strings"
)
var pubMethod = sys.PublicMethod{}
var encrypt = utils.Encrypt{}
type Login struct {
beego.Controller
}
func (c *Login) UserLogin() {
captchaCode := c.GetString("captchaCode")
captchaId := c.GetString("captchaId")
userName := strings.TrimSpace(c.GetString("userName"))
password := c.GetString("Password")
var (
flag = enum.FailedFlag
msg = ""
url = "/"
pwdMd5 string
ran string
ranMd5 string
verify bool
u models.MerchantInfo
)
us := c.GetSession(enum.UserSession)
if us != nil {
url = enum.DoMainUrl
flag = enum.SuccessFlag
goto stopRun
}
if userName == "" || password == "" {
msg = "登录账号或密码不能为空!"
goto stopRun
}
verify = captcha.VerifyString(captchaId, captchaCode)
if !verify {
url = strconv.Itoa(enum.FailedFlag)
msg = "验证码不正确!"
goto stopRun
}
u = models.GetMerchantByPhone(userName)
if u.LoginPassword == "" {
msg = "账户信息错误,请联系管理人员!"
goto stopRun
}
if strings.Compare(enum.ACTIVE, u.Status) != 0 {
msg = "登录账号或密码错误!"
goto stopRun
}
//验证密码
pwdMd5 = encrypt.EncodeMd5([]byte(password))
if strings.Compare(strings.ToUpper(pwdMd5), u.LoginPassword) != 0 {
msg = "登录账号或密码错误!"
goto stopRun
}
c.SetSession(enum.UserSession, u)
// 设置客户端用户信息有效保存时间
ran = pubMethod.RandomString(46)
ranMd5 = encrypt.EncodeMd5([]byte(ran))
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
url = enum.DoMainUrl
flag = enum.SuccessFlag
utils.LogNotice(fmt.Sprintf("【%s】用户登录成功请求IP%s", u.MerchantName, c.Ctx.Input.IP()))
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, url)
c.ServeJSON()
c.StopRun()
}
func (c *Login) Index() {
capt := struct {
CaptchaId string
}{
captcha.NewLen(4),
}
c.Data["CaptchaId"] = capt.CaptchaId
c.TplName = "login.html"
}
// 验证输入的验证码
func (c *Login) VerifyCaptcha() {
captchaValue := c.Ctx.Input.Param(":value")
captchaId := c.Ctx.Input.Param(":chaId")
verify := captcha.VerifyString(captchaId, captchaValue)
if verify {
c.Data["json"] = pubMethod.JsonFormat(enum.SuccessFlag, "", "", "")
} else {
c.Data["json"] = pubMethod.JsonFormat(enum.FailedFlag, "", "验证码不匹配!", "")
}
c.ServeJSON()
c.StopRun()
}
// 重绘验证码
func (c *Login) FlushCaptcha() {
capt := struct {
CaptchaId string
}{
captcha.NewLen(4),
}
c.Data["json"] = pubMethod.JsonFormat(enum.SuccessFlag, capt.CaptchaId, "验证码不匹配!", "")
c.ServeJSON()
c.StopRun()
}
// 退出登录
func (c *Login) LoginOut() {
c.DelSession(enum.UserSession)
c.Data["json"] = pubMethod.JsonFormat(enum.FailedFlag, "", "", "/")
c.ServeJSON()
c.StopRun()
}
// 对接文档
func (c *Login) PayDoc() {
c.TplName = "api_doc/pay_doc.html"
}

View File

@@ -0,0 +1,341 @@
/***************************************************
** @Desc : This file for 批量提现
** @Time : 19.12.6 17:07
** @Author : Joker
** @File : multi_withdraw
** @Last Modified by : Joker
** @Last Modified time: 19.12.6 17:07
** @Software: GoLand
****************************************************/
package controllers
import (
"fmt"
"github.com/rs/xid"
"github.com/tealeg/xlsx"
"merchant/common"
"merchant/models"
"merchant/sys/enum"
"merchant/utils"
"path"
"regexp"
"strconv"
"strings"
"time"
)
type MultiWithdraw struct {
KeepSession
}
func (c *MultiWithdraw) ShowMultiWithdrawUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["userName"] = u.MerchantName
c.TplName = "withdraw/multi_withdraw.html"
}
// 发送批量提现短信
func (c *Withdraw) SendMsgForMultiWithdraw() {
file, header, err := c.GetFile("file")
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
//获取客户端ip
ip := strings.TrimSpace(c.Ctx.Input.IP())
var (
msg = enum.FailedString
flag = enum.FailedFlag
smsCookie string
codeCookie string
code string
isSend bool
isContains bool
smsSession interface{}
)
fileName := header.Filename
defer file.Close()
split := strings.Split(fileName, ".")
if len(split) < 2 {
msg = "请选择批量文件!"
goto stopRun
}
if strings.Compare(strings.ToLower(split[1]), "xls") != 0 &&
strings.Compare(strings.ToLower(split[1]), "xlsx") != 0 {
msg = "仅支持“xls”、“xlsx”格式文件!"
goto stopRun
}
if err != nil {
msg = "请上传批量文件! " + err.Error()
goto stopRun
}
isContains = strings.Contains(u.WhiteIps, ip)
if isContains {
msg = "已有IP白名单无需发送验证码输入任意字符即可!"
goto stopRun
}
// 以免cookie失效了但是session还没失效
smsCookie = c.Ctx.GetCookie("do_multi_pay_sms_cookie")
if smsCookie == "" {
c.SetSession("do_multi_pay_sms_cookie", "")
}
smsSession = c.GetSession("do_multi_pay_sms_cookie")
if smsSession != nil {
codeCookie = smsSession.(string)
}
if smsCookie != "" || strings.Compare(smsCookie, codeCookie) != 0 {
msg = fmt.Sprintf("请在%d分钟后送验证码", enum.SmsCookieExpireTime/60)
goto stopRun
}
code = pubMethod.RandomIntOfString(6)
isSend = utils.SendSmsForPay(u.LoginAccount, code)
if !isSend {
msg = fmt.Sprintf("验证码发送失败,请核实预留手机号:%s 是否正确!", u.LoginAccount)
goto stopRun
}
flag = enum.SuccessFlag
msg = fmt.Sprintf("验证码已发送到您的手机号:%s且%d分钟内有效", u.LoginAccount, enum.SmsCookieExpireTime/60)
c.SetSession("do_multi_pay_code", code)
code = pubMethod.RandomString(6)
c.Ctx.SetCookie("do_multi_pay_sms_cookie", code, enum.SmsCookieExpireTime)
c.SetSession("do_multi_pay_sms_cookie", code)
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 申请批量提现
func (c *Withdraw) LaunchMultiWithdraw() {
mobileCode := strings.TrimSpace(c.GetString("mobileCode"))
file, header, err := c.GetFile("file")
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
//获取客户端ip
ip := strings.TrimSpace(c.Ctx.Input.IP())
var (
msg = enum.FailedString
flag = enum.FailedFlag
isContains bool
b bool
smsCookie string
url string
)
fileName := header.Filename
defer file.Close()
split := strings.Split(fileName, ".")
if len(split) < 2 {
msg = "请选择批量文件!"
goto stopRun
}
if strings.Compare(strings.ToLower(split[1]), "xls") != 0 &&
strings.Compare(strings.ToLower(split[1]), "xlsx") != 0 {
msg = "仅支持“xls”、“xlsx”格式文件!"
goto stopRun
}
if err != nil {
msg = "请上传批量文件! " + err.Error()
goto stopRun
}
isContains = strings.Contains(u.WhiteIps, ip)
if !isContains {
code := c.GetSession("do_multi_pay_code")
smsCookie = c.Ctx.GetCookie("do_multi_pay_sms_cookie")
if smsCookie == "" || code == nil {
msg = "请发送提现验证码!"
goto stopRun
}
if strings.Compare(code.(string), mobileCode) != 0 {
msg = "短信验证码输入错误!"
goto stopRun
}
}
u = models.GetMerchantByUid(u.MerchantUid)
if strings.Compare(enum.ACTIVE, u.Status) != 0 {
msg = "商户状态异常,请联系管理人员!"
goto stopRun
}
b, msg = handleFileContent(split[0], u, c)
if b {
flag = enum.SuccessFlag
url = "/withdraw/show_list_ui"
}
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, url)
c.ServeJSON()
c.StopRun()
}
func handleFileContent(name string, u models.MerchantInfo, c *Withdraw) (bool, string) {
// 重命名文件
fileName := name + " - " + pubMethod.GetNowTimeV2() + pubMethod.RandomString(4) + ".xlsx"
// 保存文件
_ = c.SaveToFile("file", path.Join(enum.ExcelPath, fileName))
// 读取文件内容
xlFile, err := xlsx.OpenFile(enum.ExcelPath + fileName)
if err != nil {
msg := "文件内容错误:" + err.Error()
utils.LogInfo(msg)
return false, msg
}
// 只读取文档中第一个工作表,忽略其他工作表
sheet := xlFile.Sheets[0]
line, err := sheet.Row(0).Cells[1].Int()
if err != nil {
msg := "请输入正确的总笔数:" + err.Error()
utils.LogInfo(msg)
return false, msg
}
if line <= 0 {
msg := "请输入正确的总笔数!"
return false, msg
}
if line > 300 {
line = 300
}
ac := models.GetAccountByUid(u.MerchantUid)
if strings.Compare(enum.ACTIVE, ac.Status) != 0 {
msg := "账户状态异常,请联系管理人员!"
return false, msg
}
// 后台处理文件,不让用户等待
go func() {
for k, row := range sheet.Rows {
if k == 0 || k == 1 {
continue
}
// 数据行数不得超过指定行数
if k == line+2 || k == 301 {
break
}
// 出现空行,则忽略后面记录
if row.Cells[0].String() == "" || row.Cells[4].String() == "" {
break
}
bankAccountType := row.Cells[3].String()
ac := models.GetAccountByUid(u.MerchantUid)
b, msg, code := verifyFileContent(row.Cells[0].String(), row.Cells[1].String(), row.Cells[2].String(), bankAccountType,
row.Cells[4].String(), ac)
if !b {
utils.LogInfo(fmt.Sprintf("用户:%s 批量代付中,第 %d 行记录出现错误:%s", u.MerchantName, k+1, msg))
// 账户可用余额不足,终止读取记录
if code == 5009 {
break
}
continue
}
if strings.Compare("对公", bankAccountType) == 0 {
bankAccountType = enum.PublicAccount
} else {
bankAccountType = enum.PrivateDebitAccount
}
money, _ := strconv.ParseFloat(row.Cells[4].String(), 10)
payFor := models.PayforInfo{
PayforUid: "pppp" + xid.New().String(),
MerchantUid: u.MerchantUid,
MerchantName: u.MerchantName,
PhoneNo: u.LoginAccount,
MerchantOrderId: xid.New().String(),
BankOrderId: "4444" + xid.New().String(),
PayforFee: common.PAYFOR_FEE,
Type: common.SELF_MERCHANT,
PayforAmount: money,
PayforTotalAmount: money + common.PAYFOR_FEE,
BankCode: "C",
BankName: row.Cells[2].String(),
IsSend: common.NO,
BankAccountName: row.Cells[0].String(),
BankAccountNo: row.Cells[1].String(),
BankAccountType: bankAccountType,
BankAccountAddress: row.Cells[2].String(),
Status: common.PAYFOR_COMFRIM,
CreateTime: pubMethod.GetNowTime(),
UpdateTime: pubMethod.GetNowTime(),
}
models.InsertPayfor(payFor)
time.Sleep(500 * time.Millisecond)
}
}()
return true, "提交成功,等待审核中,请在结算信息中查询状态!"
}
// 验证文件内容是否规范
func verifyFileContent(accountName, cardNo, bankAccountAddress, bankAccountType, amount string, ac models.AccountInfo) (bool, string, int) {
if accountName == "" || cardNo == "" {
msg := "账户名或卡号不能为空!"
return false, msg, 5001
}
// 账户类型
if strings.Compare("对公", bankAccountType) == 0 {
if bankAccountAddress == "" {
msg := "收款方开户机构名称不能为空!"
return false, msg, 5002
}
}
if amount == "" {
msg := "金额不能为空!"
return false, msg, 5003
}
matched, _ := regexp.MatchString(enum.MoneyReg, amount)
if !matched {
msg := "请输入正确的金额!"
return false, msg, 5004
}
f, err := strconv.ParseFloat(amount, 10)
if err != nil {
msg := "请输入正确的金额! " + err.Error()
return false, msg, 5007
}
if f > enum.WithdrawalMaxAmount || f < enum.WithdrawalMinAmount || f+enum.SettlementFee > ac.WaitAmount {
msg := fmt.Sprintf("单笔提现金额超出限制,提现金额:%f账户可结算余额%f提现最小额%d最大额%d手续费%d",
f, ac.WaitAmount, enum.WithdrawalMinAmount, enum.WithdrawalMaxAmount, enum.SettlementFee)
return false, msg, 5008
}
if f+enum.SettlementFee > ac.Balance || ac.Balance <= 0 {
msg := fmt.Sprintf("账户金额不足,提现金额:%f账户余额%f手续费%d",
f, ac.Balance, enum.SettlementFee)
return false, msg, 5009
}
return true, "", 5000
}

View File

@@ -0,0 +1,169 @@
/***************************************************
** @Desc : This file for 交易记录
** @Time : 19.12.2 16:34
** @Author : Joker
** @File : trade_record
** @Last Modified by : Joker
** @Last Modified time: 19.12.2 16:34
** @Software: GoLand
****************************************************/
package controllers
import (
"merchant/models"
"merchant/sys/enum"
"strconv"
"strings"
)
type TradeRecord struct {
KeepSession
}
func (c *TradeRecord) ShowUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["payType"] = enum.GetPayType()
c.Data["status"] = enum.GetOrderStatus()
c.Data["userName"] = u.MerchantName
c.TplName = "trade_record.html"
}
// 订单记录查询分页
func (c *TradeRecord) TradeQueryAndListPage() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 分页参数
page, _ := strconv.Atoi(c.GetString("page"))
limit, _ := strconv.Atoi(c.GetString("limit"))
if limit == 0 {
limit = 15
}
// 查询参数
in := make(map[string]string)
merchantNo := strings.TrimSpace(c.GetString("MerchantNo"))
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
payType := strings.TrimSpace(c.GetString("pay_type"))
status := strings.TrimSpace(c.GetString("status"))
in["merchant_order_id"] = merchantNo
in["pay_type_code"] = payType
in["status"] = status
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["update_time__gte"] = start
}
if end != "" {
in["update_time_lte"] = end
}
// 计算分页数
count := models.GetOrderProfitLenByMap(in)
totalPage := count / limit // 计算总页数
if count%limit != 0 { // 不满一页的数据按一页计算
totalPage++
}
// 数据获取
var list []models.OrderProfitInfo
if page <= totalPage {
list = models.GetOrderProfitByMap(in, limit, (page-1)*limit)
}
// 数据回显
out := make(map[string]interface{})
out["limit"] = limit // 分页数据
out["page"] = page
out["totalPage"] = totalPage
out["root"] = list // 显示数据
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}
func (c *TradeRecord) ShowComplaintUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["payType"] = enum.GetPayType()
c.Data["status"] = enum.GetComOrderStatus()
c.Data["userName"] = u.MerchantName
c.TplName = "complaint_record.html"
}
// 投诉列表查询分页
func (c *TradeRecord) ComplaintQueryAndListPage() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 分页参数
page, _ := strconv.Atoi(c.GetString("page"))
limit, _ := strconv.Atoi(c.GetString("limit"))
if limit == 0 {
limit = 15
}
// 查询参数
in := make(map[string]string)
merchantNo := strings.TrimSpace(c.GetString("MerchantNo"))
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
payType := strings.TrimSpace(c.GetString("pay_type"))
status := strings.TrimSpace(c.GetString("status"))
in["merchant_order_id"] = merchantNo
in["pay_type_code"] = payType
if strings.Compare("YES", status) == 0 {
in["freeze"] = enum.YES
} else {
in["refund"] = enum.YES
}
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["update_time__gte"] = start
}
if end != "" {
in["update_time__lte"] = end
}
// 计算分页数
count := models.GetOrderLenByMap(in)
totalPage := count / limit // 计算总页数
if count%limit != 0 { // 不满一页的数据按一页计算
totalPage++
}
// 数据获取
var list []models.OrderInfo
if page <= totalPage {
list = models.GetOrderByMap(in, limit, (page-1)*limit)
}
// 数据回显
out := make(map[string]interface{})
out["limit"] = limit // 分页数据
out["page"] = page
out["totalPage"] = totalPage
out["root"] = list // 显示数据
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}

View File

@@ -0,0 +1,135 @@
/***************************************************
** @Desc : This file for 用户信息控制
** @Time : 19.12.3 10:38
** @Author : Joker
** @File : user_info
** @Last Modified by : Joker
** @Last Modified time: 19.12.3 10:38
** @Software: GoLand
****************************************************/
package controllers
import (
"merchant/models"
"merchant/sys/enum"
"regexp"
"strings"
)
type UserInfo struct {
KeepSession
}
func (c *UserInfo) ShowModifyUserInfoUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["userName"] = u.MerchantName
c.TplName = "modify_userInfo.html"
}
// 修改用户信息
func (c *UserInfo) ModifyUserInfo() {
or_pwd := strings.TrimSpace(c.GetString("or_pwd"))
new_pwd := strings.TrimSpace(c.GetString("new_pwd"))
confirm_pwd := strings.TrimSpace(c.GetString("confirm_pwd"))
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
var (
msg = enum.FailedString
flag = enum.FailedFlag
md bool
ud bool
pwdMd5 string
)
if or_pwd == "" ||
new_pwd == "" ||
confirm_pwd == "" {
msg = "密码不能为空!"
goto stopRun
}
pwdMd5 = encrypt.EncodeMd5([]byte(or_pwd))
if strings.Compare(strings.ToUpper(pwdMd5), u.LoginPassword) != 0 {
msg = "原始密码错误!"
}
md, _ = regexp.MatchString(enum.PasswordReg, new_pwd)
if !md {
msg = "密码只能输入6-20个以字母开头、可带数字、“_”、“.”的字串!"
goto stopRun
}
md, _ = regexp.MatchString(enum.PasswordReg, confirm_pwd)
if !md {
msg = "密码只能输入6-20个以字母开头、可带数字、“_”、“.”的字串!"
goto stopRun
}
if strings.Compare(new_pwd, confirm_pwd) != 0 {
msg = "两次密码不匹配!"
goto stopRun
}
u.LoginPassword = strings.ToUpper(encrypt.EncodeMd5([]byte(new_pwd)))
ud = models.UpdateMerchant(u)
if ud {
msg = enum.SuccessString
flag = enum.SuccessFlag
// 退出重新登录
c.DelSession(enum.UserSession)
}
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 验证原始密码
func (c *UserInfo) ConfirmOriginPwd() {
ori := strings.TrimSpace(c.GetString("c"))
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
var (
msg = enum.FailedString
flag = enum.FailedFlag
)
pwdMd5 := encrypt.EncodeMd5([]byte(ori))
if strings.Compare(strings.ToUpper(pwdMd5), u.LoginPassword) != 0 {
msg = "原始密码错误!"
} else {
flag = enum.SuccessFlag
}
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 展示用户信息
func (c *UserInfo) ShowUserInfoUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
c.Data["userName"] = u.MerchantName
c.Data["mobile"] = u.LoginAccount
c.Data["email"] = u.LoginAccount
c.Data["riskDay"] = "1"
//c.Data["key"] = uPayConfig.PayKey
//c.Data["secret"] = uPayConfig.PaySecret
c.TplName = "show_userInfo.html"
}

View File

@@ -0,0 +1,358 @@
/***************************************************
** @Desc : This file for 代付申请和记录
** @Time : 19.12.4 10:50
** @Author : Joker
** @File : withdraw
** @Last Modified by : Joker
** @Last Modified time: 19.12.4 10:50
** @Software: GoLand
****************************************************/
package controllers
import (
"fmt"
"github.com/rs/xid"
"merchant/common"
"merchant/models"
"merchant/sys/enum"
"merchant/utils"
"regexp"
"strconv"
"strings"
)
type Withdraw struct {
KeepSession
}
func (c *Withdraw) ShowWithdrawUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["bankInfo"] = enum.GetBankInfo()
c.Data["userName"] = u.MerchantName
c.TplName = "withdraw/withdraw.html"
}
// 获取账户提现余额
func (c *Withdraw) UserBalance() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ac := models.GetAccountByUid(u.MerchantUid)
balance := ac.Balance
if balance < 0 {
balance = 0
}
out := make(map[string]interface{})
out["fee"] = enum.SettlementFee
out["balance"] = fmt.Sprintf("%0.2f", balance)
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}
// 发送提现短信
func (c *Withdraw) SendMsgForWithdraw() {
bankCode := strings.TrimSpace(c.GetString("bankCode"))
accountName := strings.TrimSpace(c.GetString("accountName"))
cardNo := strings.TrimSpace(c.GetString("cardNo"))
bankAccountType := strings.TrimSpace(c.GetString("bankAccountType"))
province := strings.TrimSpace(c.GetString("province"))
city := strings.TrimSpace(c.GetString("city"))
bankAccountAddress := strings.TrimSpace(c.GetString("bankAccountAddress"))
moblieNo := strings.TrimSpace(c.GetString("moblieNo"))
money := strings.TrimSpace(c.GetString("amount"))
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
//获取客户端ip
ip := strings.TrimSpace(c.Ctx.Input.IP())
var (
msg = enum.FailedString
flag = enum.FailedFlag
smsCookie string
codeCookie string
code string
isSend bool
isContains bool
matched bool
smsSession interface{}
)
ac := models.GetAccountByUid(u.MerchantUid)
matched, msg = verifyAccountAndMoney(bankCode, accountName, cardNo, bankAccountType, province, city,
bankAccountAddress, moblieNo, money, ac)
if !matched {
goto stopRun
}
isContains = strings.Contains(u.WhiteIps, ip)
if isContains {
msg = "已有IP白名单无需发送验证码输入任意字符即可!"
goto stopRun
}
// 以免cookie失效了但是session还没失效
smsCookie = c.Ctx.GetCookie("do_pay_sms_cookie")
if smsCookie == "" {
c.SetSession("do_pay_sms_cookie", "")
}
smsSession = c.GetSession("do_pay_sms_cookie")
if smsSession != nil {
codeCookie = smsSession.(string)
}
if smsCookie != "" || strings.Compare(smsCookie, codeCookie) != 0 {
msg = fmt.Sprintf("请在%d分钟后送验证码", enum.SmsCookieExpireTime/60)
goto stopRun
}
code = pubMethod.RandomIntOfString(6)
isSend = utils.SendSmsForPay(u.LoginAccount, code)
if !isSend {
msg = fmt.Sprintf("验证码发送失败,请核实预留手机号:%s 是否正确!", u.LoginAccount)
goto stopRun
}
flag = enum.SuccessFlag
msg = fmt.Sprintf("验证码已发送到您的手机号:%s且%d分钟内有效", u.LoginAccount, enum.SmsCookieExpireTime/60)
c.SetSession("do_pay_code", code)
code = pubMethod.RandomString(6)
c.Ctx.SetCookie("do_pay_sms_cookie", code, enum.SmsCookieExpireTime)
c.SetSession("do_pay_sms_cookie", code)
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, "")
c.ServeJSON()
c.StopRun()
}
// 验证卡号和金额是否正确
func verifyAccountAndMoney(bankCode, accountName, cardNo, bankAccountType, province, city, bankAccountAddress, moblieNo, amount string, ac models.AccountInfo) (b bool, msg string) {
if bankCode == "" || accountName == "" || cardNo == "" {
msg = "银行名、账户名或卡号不能为空!"
return false, msg
}
if moblieNo == "" || amount == "" {
msg = "手机号或金额不能为空!"
return false, msg
}
matched, _ := regexp.MatchString(enum.MobileReg, moblieNo)
if !matched {
msg = "请输入正确的手机号!"
return false, msg
}
matched, _ = regexp.MatchString(enum.MoneyReg, amount)
if !matched {
msg = "请输入正确的金额!"
return false, msg
}
f, err := strconv.ParseFloat(amount, 10)
if err != nil {
msg = "请输入正确的金额!"
return false, msg
}
if strings.Compare(enum.PublicAccount, bankAccountType) == 0 {
if province == "" || city == "" || bankAccountAddress == "" {
msg = "开户行全称、所在省份或所在城市不能为空!"
return false, msg
}
}
if f > enum.WithdrawalMaxAmount || f < enum.WithdrawalMinAmount || f+enum.SettlementFee > ac.WaitAmount {
utils.LogInfo(fmt.Sprintf("提现金额超出限制,提现金额:%f账户可结算余额%f提现最小额%d最大额%d手续费%d",
f, ac.WaitAmount, enum.WithdrawalMinAmount, enum.WithdrawalMaxAmount, enum.SettlementFee))
msg = "提现金额超出限制!"
return false, msg
}
if f+enum.SettlementFee > ac.Balance || ac.Balance <= 0 {
utils.LogInfo(fmt.Sprintf("账户金额不足,提现金额:%f账户余额%f手续费%d",
f, ac.Balance, enum.SettlementFee))
msg = "账户可用金额不足!"
return false, msg
}
// 由于没有发生错误必须把msg重置为初始值而不是空值
return true, enum.FailedToAdmin
}
// 单笔提现申请
func (c *Withdraw) LaunchSingleWithdraw() {
bankCode := strings.TrimSpace(c.GetString("bankCode"))
accountName := strings.TrimSpace(c.GetString("accountName"))
cardNo := strings.TrimSpace(c.GetString("cardNo"))
bankAccountType := strings.TrimSpace(c.GetString("bankAccountType"))
province := strings.TrimSpace(c.GetString("province"))
city := strings.TrimSpace(c.GetString("city"))
bankAccountAddress := strings.TrimSpace(c.GetString("bankAccountAddress"))
moblieNo := strings.TrimSpace(c.GetString("moblieNo"))
money := strings.TrimSpace(c.GetString("amount"))
mobileCode := strings.TrimSpace(c.GetString("smsVerifyCode"))
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
//获取客户端ip
ip := strings.TrimSpace(c.Ctx.Input.IP())
var (
msg = enum.FailedString
flag = enum.FailedFlag
matched bool
isContains bool
amount float64
ac models.AccountInfo
sett models.PayforInfo
url string
)
isContains = strings.Contains(u.WhiteIps, ip)
if !isContains {
code := c.GetSession("do_pay_code")
smsCookie := c.Ctx.GetCookie("do_pay_sms_cookie")
if smsCookie == "" || code == nil {
msg = "请发送提现验证码!"
goto stopRun
}
if strings.Compare(code.(string), mobileCode) != 0 {
msg = "短信验证码输入错误!"
goto stopRun
}
}
ac = models.GetAccountByUid(u.MerchantUid)
matched, msg = verifyAccountAndMoney(bankCode, accountName, cardNo, bankAccountType, province, city,
bankAccountAddress, moblieNo, money, ac)
if !matched {
goto stopRun
}
u = models.GetMerchantByPhone(u.LoginAccount)
if strings.Compare(enum.ACTIVE, u.Status) != 0 {
msg = "账户状态异常,请联系管理人员!"
goto stopRun
}
amount, _ = strconv.ParseFloat(money, 10)
sett = models.PayforInfo{
PayforUid: "pppp" + xid.New().String(),
MerchantUid: u.MerchantUid,
MerchantName: u.MerchantName,
PhoneNo: u.LoginAccount,
MerchantOrderId: xid.New().String(),
BankOrderId: "4444" + xid.New().String(),
PayforFee: common.PAYFOR_FEE,
Type: common.SELF_MERCHANT,
PayforAmount: amount,
PayforTotalAmount: amount + common.PAYFOR_FEE,
BankCode: bankCode,
BankName: enum.GetBankInfo()[bankCode],
IsSend: common.NO,
BankAccountName: accountName,
BankAccountNo: cardNo,
BankAccountType: bankAccountType,
BankAccountAddress: province + city + bankAccountAddress,
Status: common.PAYFOR_COMFRIM,
CreateTime: pubMethod.GetNowTime(),
UpdateTime: pubMethod.GetNowTime(),
}
matched = models.InsertPayfor(sett)
if matched {
flag = enum.SuccessFlag
msg = "提交成功,等待审核中,请在结算信息中查询状态!"
url = "/withdraw/show_list_ui"
}
stopRun:
c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, url)
c.ServeJSON()
c.StopRun()
}
// 提现列表
func (c *Withdraw) ShowListUI() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46)))
c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime)
c.SetSession(enum.UserCookie, ranMd5)
c.Data["payType"] = enum.GetSettlementStatus()
c.Data["userName"] = u.MerchantName
c.TplName = "withdraw/withdraw_record.html"
}
func (c *Withdraw) WithdrawQueryAndListPage() {
us := c.GetSession(enum.UserSession)
u := us.(models.MerchantInfo)
// 分页参数
page, _ := strconv.Atoi(c.GetString("page"))
limit, _ := strconv.Atoi(c.GetString("limit"))
if limit == 0 {
limit = 15
}
// 查询参数
in := make(map[string]string)
merchantNo := strings.TrimSpace(c.GetString("MerchantNo"))
bankNo := strings.TrimSpace(c.GetString("BankNo"))
start := strings.TrimSpace(c.GetString("start"))
end := strings.TrimSpace(c.GetString("end"))
status := strings.TrimSpace(c.GetString("status"))
in["bank_order_id"] = bankNo
in["merchant_order_id"] = merchantNo
in["status"] = status
in["merchant_uid"] = u.MerchantUid
if start != "" {
in["create_time__gte"] = start
}
if end != "" {
in["create_time__lte"] = end
}
// 计算分页数
count := models.GetPayForLenByMap(in)
totalPage := count / limit // 计算总页数
if count%limit != 0 { // 不满一页的数据按一页计算
totalPage++
}
// 数据获取
var list []models.PayforInfo
if page <= totalPage {
list = models.GetPayForByMap(in, limit, (page-1)*limit)
}
// 数据回显
out := make(map[string]interface{})
out["limit"] = limit // 分页数据
out["page"] = page
out["totalPage"] = totalPage
out["root"] = list // 显示数据
c.Data["json"] = out
c.ServeJSON()
c.StopRun()
}