206 lines
4.8 KiB
Go
206 lines
4.8 KiB
Go
package controllers
|
|
|
|
/***************************************************
|
|
** @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
|
|
****************************************************/
|
|
import (
|
|
"fmt"
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
"github.com/rs/xid"
|
|
"merchant/models"
|
|
"merchant/sys/enum"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Index struct {
|
|
KeepSession
|
|
}
|
|
|
|
// ShowUI 首页
|
|
func (c *Index) ShowUI() {
|
|
us := c.GetSession(enum.UserSession)
|
|
u := us.(models.MerchantInfo)
|
|
|
|
c.Data["userName"] = u.MerchantName
|
|
|
|
payLink, err := beego.AppConfig.String("payLink::url")
|
|
|
|
if err != nil {
|
|
payLink = "http://localhost:12305/"
|
|
}
|
|
|
|
orderParams := models.OrderParams{
|
|
PayKey: u.MerchantKey,
|
|
GeneratedTime: time.Now(),
|
|
Duration: 24,
|
|
}
|
|
|
|
//获取账号数据签名
|
|
c.Data["payLink"] = payLink + "?sign=" + orderParams.Encrypt() + "&orderId=" + xid.New().String()
|
|
|
|
c.TplName = "index.html"
|
|
}
|
|
|
|
// LoadUserAccountInfo 加载用户账户金额信息
|
|
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()
|
|
}
|
|
|
|
// LoadCountOrder 加载总订单信息
|
|
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()
|
|
}
|
|
|
|
// LoadOrderCount 加载总订单数
|
|
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)
|
|
|
|
{
|
|
supplierAll := 0.0
|
|
platformAll := 0.0
|
|
agentAll := 0.0
|
|
allAmount := 0.0
|
|
TadaySuccessNum := 0
|
|
datainfo := models.GetOrderProfitByMap(in, -1, 0)
|
|
|
|
for _, v := range datainfo {
|
|
if v.Status != "success" {
|
|
continue
|
|
}
|
|
allAmount += v.FactAmount
|
|
supplierAll += v.SupplierProfit
|
|
platformAll += v.PlatformProfit
|
|
agentAll += v.AgentProfit
|
|
TadaySuccessNum += 1
|
|
}
|
|
|
|
out["TadaySupplierProfit"], _ = strconv.ParseFloat(fmt.Sprintf("%.3f", supplierAll), 3)
|
|
out["TadayPlatformProfit"], _ = strconv.ParseFloat(fmt.Sprintf("%.3f", platformAll), 3)
|
|
out["TadayAgentProfit"], _ = strconv.ParseFloat(fmt.Sprintf("%.3f", agentAll), 3)
|
|
out["TadayAllAmount"], _ = strconv.ParseFloat(fmt.Sprintf("%.3f", allAmount), 3)
|
|
|
|
out["TadaySuccessNum"] = TadaySuccessNum
|
|
out["TadayAllNum"] = len(datainfo)
|
|
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
// LoadUserPayWayUI 加载用户支付配置
|
|
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()
|
|
}
|