添加游戏充值商户后台代码

This commit is contained in:
kongyuebin 2021-05-16 15:21:52 +08:00
parent a56fa52493
commit 8bd7067c2f
35 changed files with 1921 additions and 246 deletions

View File

@ -77,7 +77,7 @@
<thead class="thead-dark">
<tr>
<th>序列号</th>
<th>用户名称</th>
<th>商户名称(UID)</th>
<th>银行名称</th>
<th>银行编码</th>
<th>对账卡类型</th>
@ -121,8 +121,9 @@
<div class="col-md-4">
<input type="hidden" value="" class="bank-card-uid">
<div>
<span>用户名称</span>
<input type="text" value="" class="user-name">
<span>商户名称</span>
<select name="" class="user-name" id="select-self-name">
</select>
</div>
<div>
<span>银行编码</span>
@ -442,6 +443,27 @@
}
});
});
function setAccount() {
$.ajax({
url: "/get/all/account",
success: function (res) {
if (res.Code == 404) {
window.parent.location = "/login.html";
} else {
let str = '<option value="' + "" + '">' + "请选择" + '</option>';
for (let i = 0; i < res.AccountList.length; i ++) {
let account = res.AccountList[i];
str = str + '<option value="' + account.AccountUid + '">' + account.AccountName + '</option>';
}
$("#select-self-name").html(str);
}
}
});
}
$(function () {
setAccount();
});
</script>
</body>
</html>

View File

@ -219,6 +219,7 @@
});
}
function merchantList(dataJSON) {
if (JSONIsEmpty(dataJSON)) {
dataJSON = getCutPagesValues();
}

View File

@ -1,7 +1,7 @@
package base
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"legend/models/fast"
)
@ -21,8 +21,8 @@ func (c *BasicController) Prepare() {
userInfo := fast.GetMerchantInfoByUserName(userName)
if userInfo.LoginAccount != "" {
c.Data["nickName"] = userInfo.MerchantName
c.Data["merchantUid"] = userInfo.MerchantUid
}
} else {
c.Data["nickName"] = "史蒂芬-库里"
}
}

View File

@ -1,7 +1,7 @@
package controllers
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
)

View File

@ -48,28 +48,34 @@ func (c *ShowPageController) MerchantKeyPage() {
userName := c.GetSession("userName").(string)
merchantService := new(service.MerchantService)
userInfo, bankInfo, payConfigInfo := merchantService.GetMerchantBankInfo(userName)
userInfo, bankInfo := merchantService.GetMerchantBankInfo(userName)
c.Data["currentTime"] = utils.GetNowTime()
c.Data["userName"] = userName
c.Data["userInfo"] = userInfo
c.Data["bankInfo"] = bankInfo
c.Data["payConfigInfo"] = payConfigInfo
c.TplName = "merchant-key.html"
}
/**
** 比例模板
*/
func (c *ShowPageController) ScaleTempletePage() {
c.TplName = "scale-templete.html"
func (c *ShowPageController) ScaleTemplatePage() {
c.TplName = "scale-template.html"
}
/**
** 增加模板
*/
func (c *ShowPageController) TempleteAdd() {
c.TplName = "templete-add.html"
func (c *ShowPageController) TemplateAdd() {
c.TplName = "template-add.html"
}
func (c *ShowPageController) TemplateEdit() {
templateName := c.GetString("templateName")
fmt.Println(templateName)
c.Data["scaleTemplateName"] = templateName
c.TplName = "template-edit.html"
}
/**

View File

@ -0,0 +1,86 @@
package controllers
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"legend/controllers/base"
"legend/request"
"legend/service"
"legend/utils"
"strings"
)
type TemplateController struct {
base.BasicController
}
func (c *TemplateController) TemplateAdd() {
addTemplate := new(request.AddTemplateReq)
if err := c.ParseForm(addTemplate); err != nil {
logs.Error("错误:", err)
}
addTemplate.FixPrices = utils.StringToFloats(c.GetString("fixPrices"))
addTemplate.PresentFixMoneys = utils.StringToFloats(c.GetString("presentFixMoneys"))
addTemplate.PresentFixPresentMoneys = utils.StringToFloats(c.GetString("presentFixPresentMoneys"))
addTemplate.PresentScaleMoneys = utils.StringToFloats(c.GetString("presentScaleMoneys"))
addTemplate.PresentScales = utils.StringToFloats(c.GetString("presentScales"))
addTemplate.FixUids = strings.Split(c.GetString("fixUids"), ",")
addTemplate.GoodsNames = strings.Split(c.GetString("goodsNames"), ",")
addTemplate.GoodsNos = strings.Split(c.GetString("goodsNos"), ",")
addTemplate.PresentFixUids = strings.Split(c.GetString("presentFixUids"), ",")
addTemplate.PresentScaleUids = strings.Split(c.GetString("presentScaleUids"), ",")
addTemplate.Limits = utils.StringToInt(c.GetString("limits"))
se := new(service.TemplateService)
merchantUid := c.Data["merchantUid"].(string)
t := c.GetString("type")
if t == "edit" {
c.Data["json"] = se.UpdateTemplate(addTemplate, merchantUid)
} else {
c.Data["json"] = se.AddTemplate(addTemplate, merchantUid)
}
_ = c.ServeJSON()
}
func (c *TemplateController) TemplateList() {
page, _ := c.GetInt("page")
limit, _ := c.GetInt("limit")
se := new(service.TemplateService)
list := se.GetTemplateList(page, limit)
c.Data["json"] = list
_ = c.ServeJSON()
}
func (c *TemplateController) TemplateDelete() {
templateName := c.GetString("TemplateName")
logs.Debug("template TemplateName ", templateName)
se := new(service.TemplateService)
baseResp := se.DeleteTemplate(templateName)
c.Data["json"] = baseResp
_ = c.ServeJSON()
}
func (c *TemplateController) TemplateAllInfo() {
templateName := c.GetString("scaleTemplateName")
logs.Debug("获取到的scaleTemplateName", templateName)
se := new(service.TemplateService)
allInfo := se.AllTemplateInfo(templateName)
logs.Debug("scale template all info", fmt.Sprintf("%+v", allInfo))
c.Data["json"] = allInfo
_ = c.ServeJSON()
}

View File

@ -14,10 +14,14 @@ var LoginFilter = func(ctx *context.Context) {
_, ok := ctx.Input.Session("userName").(string)
if !ok {
if ctx.Request.RequestURI == "/login.html" {
return
}
if !strings.Contains(ctx.Request.RequestURI, "/login") {
ctx.Redirect(302, "/login.html")
} else {
logs.Info("该用户没有登录.......")
logs.Error("该用户没有登录.......")
}
}

View File

@ -5,7 +5,6 @@ go 1.13
require github.com/beego/beego/v2 v2.0.1
require (
github.com/astaxie/beego v1.12.3
github.com/go-sql-driver/mysql v1.5.0
github.com/smartystreets/goconvey v1.6.4
)

View File

@ -1,8 +1,8 @@
package fast
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type AccountInfo struct {

View File

@ -0,0 +1,39 @@
package fast
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type BankCardInfo struct {
Id string `orm:"pk;column(id)"`
Uid string
UserName string
BankName string
BankCode string
BankAccountType string
AccountName string
BankNo string
IdentifyCard string
CertificateNo string
PhoneNo string
BankAddress string
CreateTime string
UpdateTime string
}
const BANKCARDINFO = "bank_card_info"
func (c *BankCardInfo) TableName() string {
return BANKCARDINFO
}
func GetBankCardInfoByUserNo(merchantNo string) *BankCardInfo {
o := orm.NewOrm()
bankCardInfo := new(BankCardInfo)
if _, err := o.QueryTable(BANKCARDINFO).Filter("user_name", merchantNo).Limit(1).All(bankCardInfo); err != nil {
logs.Error("获取用户银行卡信息失败:", err)
}
return bankCardInfo
}

View File

@ -0,0 +1,32 @@
package fast
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type MerchantDeployInfo struct {
Id string `orm:"pk;column(id)"`
Status string
MerchantUid string
PayType string
SingleRoadUid string
SingleRoadName string
}
const MERCHANTDEPLOYINFO = "merchant_deploy_info"
func (c *MerchantDeployInfo) TableName() string {
return MERCHANTDEPLOYINFO
}
func GetUserPayConfigByUserNo(userNo string) *MerchantDeployInfo {
o := orm.NewOrm()
userPayConfig := new(MerchantDeployInfo)
_, err := o.QueryTable(MERCHANTDEPLOYINFO).Filter("user_no", userNo).All(userPayConfig)
if err != nil {
logs.Error("获取用户支付配置错误:", err)
}
return userPayConfig
}

View File

@ -1,8 +1,8 @@
package fast
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type MerchantInfo struct {

View File

@ -1,44 +0,0 @@
package fast
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/client/orm"
)
type RpUserBankAccount struct {
Id string `orm:"pk;column(id)"`
CreateTime string
EditTime string
Version string
Remark string
Status string
UserNo string
BankName string
BankCode string
BankAccountName string
BankAccountNo string
CardType string
CardNo string
MobileNo string
IsDefault string
Province string
City string
Areas string
Street string
BankAccountType string
}
func (c *RpUserBankAccount) TableName() string {
return "rp_user_bank_account"
}
func GetBankInfoByUserNo(userNo string) *RpUserBankAccount {
o := orm.NewOrm()
userBankAccount := new(RpUserBankAccount)
if _, err := o.QueryTable("rp_user_bank_account").
Filter("user_no", userNo).
All(userBankAccount); err != nil {
logs.Error("获取用户银行卡信息失败:", err)
}
return userBankAccount
}

View File

@ -1,34 +0,0 @@
package fast
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/client/orm"
)
type RpUserPayConfig struct {
Id string `orm:"pk;column(id)"`
UserNo string
UserName string
Status string
PayKey string
PaySecret string
}
func (c *RpUserPayConfig) TableName() string {
return "rp_user_pay_config"
}
func getTableName() string {
return "rp_user_pay_config"
}
func GetUserPayConfigByUserNo(userNo string) *RpUserPayConfig {
o := orm.NewOrm()
userPayConfig := new(RpUserPayConfig)
_, err := o.QueryTable(getTableName()).Filter("user_no", userNo).All(userPayConfig)
if err != nil {
logs.Error("获取用户支付配置错误:", err)
}
return userPayConfig
}

View File

@ -7,6 +7,7 @@ import (
"github.com/beego/beego/v2/server/web"
_ "github.com/go-sql-driver/mysql"
"legend/models/fast"
"legend/models/legend"
"os"
)
@ -43,11 +44,18 @@ func initLegend() {
orm.SetMaxIdleConns("default", 30)
orm.RegisterModel(new(fast.MerchantInfo))
orm.RegisterModel(new(fast.RpUserPayConfig))
orm.RegisterModel(new(fast.RpUserBankAccount))
orm.RegisterModel(new(fast.MerchantDeployInfo))
orm.RegisterModel(new(fast.BankCardInfo))
orm.RegisterModel(new(fast.AccountInfo))
orm.RegisterModel(new(fast.OrderInfo))
orm.RegisterModel(new(legend.AnyMoney))
orm.RegisterModel(new(legend.FixMoney))
orm.RegisterModel(new(legend.FixPresent))
orm.RegisterModel(new(legend.ScalePresent))
orm.RegisterModel(new(legend.ScaleTemplate))
orm.RegisterModel(new(legend.Group))
logs.Info("init legend success ......")
}

View File

@ -0,0 +1,62 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type AnyMoney struct {
Id int `orm:"pk;column(id)"`
TemplateName string
GameMoneyName string
GameMoneyScale int
LimitLow float64
UpdateTime string
CreateTime string
}
const ANYMONEY = "legend_any_money"
func (c *AnyMoney) TableName() string {
return ANYMONEY
}
func InsertAnyMoney(anyMoney *AnyMoney) bool {
o := orm.NewOrm()
if _, err := o.Insert(anyMoney); err != nil {
logs.Error("insert any money info err: ", err)
return false
}
return true
}
func GetAnyMoneyByName(name string) *AnyMoney {
o := orm.NewOrm()
anyMoney := new(AnyMoney)
if _, err := o.QueryTable(ANYMONEY).Filter("template_name", name).Limit(1).All(anyMoney); err != nil {
logs.Error("get any money err", err)
}
return anyMoney
}
func DeleteAnyMoney(templateName string) bool {
o := orm.NewOrm()
_, err := o.QueryTable(ANYMONEY).Filter("template_name", templateName).Delete()
if err != nil {
logs.Error("delete any money err", err)
return false
}
return true
}
func UpdateAnyMoney(anyMoney *AnyMoney) bool {
o := orm.NewOrm()
if _, err := o.Update(anyMoney); err != nil {
logs.Error("update any money err: ", err)
return false
}
return true
}

View File

@ -0,0 +1,84 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type FixMoney struct {
Id int `orm:"pk;column(id)"`
Uid string
TemplateName string
Price float64
GoodsName string
GoodsNo string
BuyTimes int
UpdateTime string
CreateTime string
}
const FIXMONEY = "legend_fix_money"
func (c *FixMoney) TableName() string {
return FIXMONEY
}
func InsertFixMoney(fixMoney *FixMoney) bool {
o := orm.NewOrm()
if _, err := o.Insert(fixMoney); err != nil {
logs.Error("insert fix money err: ", err)
return false
}
return true
}
func GetFixMoneyByName(name string) []FixMoney {
o := orm.NewOrm()
var fixMoneys []FixMoney
if _, err := o.QueryTable(FIXMONEY).Filter("template_name", name).Limit(-1).All(&fixMoneys); err != nil {
logs.Error("get fix money err", err)
}
return fixMoneys
}
func GetFixMoneyByUid(uid string) *FixMoney {
o := orm.NewOrm()
fixMoney := new(FixMoney)
if _, err := o.QueryTable(FIXMONEY).Filter("uid", uid).Limit(1).All(fixMoney); err != nil {
logs.Error("get fix Money by uid err", err)
}
return fixMoney
}
func DeleteFixMoney(templateName string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(FIXMONEY).Filter("template_name", templateName).Delete(); err != nil {
logs.Error("delete fix money err", err)
return false
}
return true
}
func DeleteFixMoneyByUid(uid string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(FIXMONEY).Filter("uid", uid).Delete(); err != nil {
logs.Error("delete fix money err", err)
return false
}
return true
}
func UpdateFixMoney(fixMoney *FixMoney) bool {
o := orm.NewOrm()
if _, err := o.Update(fixMoney); err != nil {
logs.Error("update fix money err: ", err)
return false
}
return true
}

View File

@ -0,0 +1,82 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type FixPresent struct {
Id int `orm:"pk;column(id)"`
Uid string
TemplateName string
Money float64
PresentMoney float64
UpdateTime string
CreateTime string
}
const FIXPRESENT = "legend_fix_present"
func (c *FixPresent) TableName() string {
return FIXPRESENT
}
func InsertFixPresent(fixPresnet *FixPresent) bool {
o := orm.NewOrm()
if _, err := o.Insert(fixPresnet); err != nil {
logs.Error("insert fix present err", err)
return false
}
return true
}
func GetFixPresentsByName(name string) []FixPresent {
o := orm.NewOrm()
var fixPresents []FixPresent
if _, err := o.QueryTable(FIXPRESENT).Filter("template_name", name).Limit(-1).All(&fixPresents); err != nil {
logs.Error("get fix presents err", err)
}
return fixPresents
}
func GetFixPresentByUid(uid string) *FixPresent {
o := orm.NewOrm()
fixPresent := new(FixPresent)
if _, err := o.QueryTable(FIXPRESENT).Filter("uid", uid).Limit(1).All(fixPresent); err != nil {
logs.Error("get fix present err", err)
}
return fixPresent
}
func DeleteFixPresent(templateName string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(FIXPRESENT).Filter("template_name", templateName).Delete(); err != nil {
logs.Error("delete fix present err: ", err)
return false
}
return true
}
func DeleteFixPresentByUid(uid string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(FIXPRESENT).Filter("uid", uid).Delete(); err != nil {
logs.Error("delete fix present by uid err", err)
return false
}
return true
}
func UpdatePresentFixMoney(present *FixPresent) bool {
o := orm.NewOrm()
if _, err := o.Update(present); err != nil {
logs.Error("update fix present err: ", err)
return false
}
return true
}

View File

@ -0,0 +1,30 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type Group struct {
Id int `orm:"pk;column(id)"`
GroupName string
Uid string
UpdateTime string
CreateTime string
}
const GROUP = "legend_group"
func (c *Group) TableName() string {
return GROUP
}
func InsertGroup(group *Group) bool {
o := orm.NewOrm()
if _, err := o.Insert(group); err != nil {
logs.Error("insert group err", err)
return false
}
return true
}

View File

@ -0,0 +1,82 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type ScalePresent struct {
Id int `orm:"pk;column(id)"`
Uid string
TemplateName string
Money float64
PresentScale float64
UpdateTime string
CreateTime string
}
const SCALEPRESENT = "legend_scale_present"
func (c *ScalePresent) TableName() string {
return SCALEPRESENT
}
func InsertScalePresent(scalePresent *ScalePresent) bool {
o := orm.NewOrm()
if _, err := o.Insert(scalePresent); err != nil {
logs.Error("insert scale present err", err)
return false
}
return true
}
func GetScalePresentsByName(name string) []ScalePresent {
o := orm.NewOrm()
var scalePresents []ScalePresent
if _, err := o.QueryTable(SCALEPRESENT).Filter("template_name", name).Limit(-1).All(&scalePresents); err != nil {
logs.Error("get scale present err", err)
}
return scalePresents
}
func GetScalePresentByUid(uid string) *ScalePresent {
o := orm.NewOrm()
scalePresent := new(ScalePresent)
if _, err := o.QueryTable(SCALEPRESENT).Filter("uid", uid).Limit(1).All(scalePresent); err != nil {
logs.Error("get scale present err", err)
}
return scalePresent
}
func DeleteScalePresent(templateName string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(SCALEPRESENT).Filter("template_name", templateName).Delete(); err != nil {
logs.Error("delete scale present err", err)
return false
}
return true
}
func DeleteScalePresentByUid(uid string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(SCALEPRESENT).Filter("uid", uid).Delete(); err != nil {
logs.Error("delete scale present by uid err", err)
return false
}
return true
}
func UpdateScalePresent(present *ScalePresent) bool {
o := orm.NewOrm()
if _, err := o.Update(present); err != nil {
logs.Error("update scale present err: ", err)
return false
}
return true
}

View File

@ -0,0 +1,101 @@
package legend
import (
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
)
type ScaleTemplate struct {
Id int `orm:"pk;column(id)"`
MerchantUid string
TemplateName string
UserUid string
UserWarn string
MoneyType string
PresentType string
UpdateTime string
CreateTime string
}
const SCALETMPLETE = "legend_scale_template"
func (c *ScaleTemplate) TableName() string {
return SCALETMPLETE
}
func InsertScaleTemplate(scaleTemplate *ScaleTemplate) bool {
o := orm.NewOrm()
if _, err := o.Insert(scaleTemplate); err != nil {
logs.Error("insert scale template err: ", err)
return false
}
return true
}
func IsExistsScaleTemplateByName(name string) bool {
o := orm.NewOrm()
return o.QueryTable(SCALETMPLETE).Filter("template_name", name).Exist()
}
func GetScaleTemplateList(offset, limit int) []ScaleTemplate {
o := orm.NewOrm()
var scaleTemplates []ScaleTemplate
if _, err := o.QueryTable(SCALETMPLETE).Limit(limit, offset).OrderBy("-create_time").All(&scaleTemplates); err != nil {
logs.Error("get scale template list err : ", err)
}
return scaleTemplates
}
func GetScaleTemplateAll() int {
o := orm.NewOrm()
count, err := o.QueryTable(SCALETMPLETE).Count()
if err != nil {
logs.Error("get scale template all err", err)
}
return int(count)
}
func GetScaleTemplateByName(name string) *ScaleTemplate {
o := orm.NewOrm()
scaleTemplate := new(ScaleTemplate)
if _, err := o.QueryTable(SCALETMPLETE).Filter("template_name", name).Limit(1).All(scaleTemplate); err != nil {
logs.Error("get scale template by name err", err)
}
return scaleTemplate
}
func GetScaleTemplateByNameAndMerchantUid(name, merchantUid string) *ScaleTemplate {
o := orm.NewOrm()
scaleTemplate := new(ScaleTemplate)
if _, err := o.QueryTable(SCALETMPLETE).Filter("template_name", name).
Filter("merchant_uid", merchantUid).Limit(1).All(scaleTemplate); err != nil {
logs.Error("get scale template by name and merchantUid err", err)
}
return scaleTemplate
}
func DeleteScaleTemplate(templateName string) bool {
o := orm.NewOrm()
if _, err := o.QueryTable(SCALETMPLETE).Filter("template_name", templateName).Delete(); err != nil {
logs.Error("delete template err", err)
return false
}
return true
}
func UpdateScaleTemplate(template *ScaleTemplate) bool {
o := orm.NewOrm()
if _, err := o.Update(template); err != nil {
logs.Error("update scale template err: ", err)
return false
}
return true
}

View File

@ -23,8 +23,9 @@ func pageInit() {
web.Router("/welcome.html", &controllers.ShowPageController{}, "*:WelcomePage")
web.Router("/merchantKey.html", &controllers.ShowPageController{}, "*:MerchantKeyPage")
web.Router("/orderList.html", &controllers.ShowPageController{}, "*:OrderListPage")
web.Router("/scaleTemplete.html", &controllers.ShowPageController{}, "*:ScaleTempletePage")
web.Router("/templeteAdd.html", &controllers.ShowPageController{}, "*:TempleteAdd")
web.Router("/scaleTemplate.html", &controllers.ShowPageController{}, "*:ScaleTemplatePage")
web.Router("/templateAdd.html", &controllers.ShowPageController{}, "*:TemplateAdd")
web.Router("/templateEdit.html", &controllers.ShowPageController{}, "*:TemplateEdit")
web.Router("/groupList.html", &controllers.ShowPageController{}, "*:GroupListPage")
web.Router("/areaList.html", &controllers.ShowPageController{}, "*:AreaListPage")
web.Router("/imitateOrder.html", &controllers.ShowPageController{}, "*:ImitateChargePage")
@ -44,5 +45,9 @@ func logicInit() {
web.Router("/logout.html", &controllers.LogoutController{}, "*:Logout")
web.Router("/switch/login", &controllers.LogoutController{}, "*:SwitchLogin")
web.Router("/person/password", &controllers.LoginController{}, "*:PersonPassword")
web.Router("/add/template", &controllers.TemplateController{}, "*:TemplateAdd")
web.Router("/template/list", &controllers.TemplateController{}, "*:TemplateList")
web.Router("/delete/template", &controllers.TemplateController{}, "*:TemplateDelete")
web.Router("/template/info", &controllers.TemplateController{}, "*:TemplateAllInfo")
web.InsertFilter("/*", web.BeforeRouter, filter.LoginFilter)
}

View File

@ -2,6 +2,7 @@ package service
import (
"legend/models/fast"
"legend/utils"
)
type AccountService struct {
@ -16,3 +17,15 @@ func (c *AccountService) GetAccountInfo(userName string) *fast.AccountInfo {
return accountInfo
}
/**
** 获取当天的充值金额
*/
func (c *AccountService) GetTodayIncome() float64 {
startTime := utils.GetNowDate() + " 00:00:00"
endTime := utils.GetNowDate() + " 23:59:59"
todayIncome := fast.GetRangeDateIncome(startTime, endTime)
return todayIncome
}

View File

@ -1,7 +1,7 @@
package service
import (
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/core/logs"
"legend/models/fast"
)
@ -9,19 +9,18 @@ type MerchantService struct {
BaseService
}
func (c *MerchantService) GetMerchantBankInfo(mobile string) (*fast.MerchantInfo, *fast.RpUserBankAccount, *fast.RpUserPayConfig) {
func (c *MerchantService) GetMerchantBankInfo(mobile string) (*fast.MerchantInfo, *fast.BankCardInfo) {
userInfo := fast.GetMerchantInfoByUserName(mobile)
bankInfo := fast.GetBankInfoByUserNo(userInfo.LoginAccount)
userPayConfig := fast.GetUserPayConfigByUserNo(userInfo.LoginAccount)
merchantInfo := fast.GetMerchantInfoByUserName(mobile)
bankInfo := fast.GetBankCardInfoByUserNo(merchantInfo.MerchantUid)
return userInfo, bankInfo, userPayConfig
return merchantInfo, bankInfo
}
/**
** 获取商户的密钥等信息
*/
func (c *MerchantService) UserPayConfig(userName string) map[string]string {
/*func (c *MerchantService) UserPayConfig(userName string) map[string]string {
merchantMapData := make(map[string]string)
@ -39,7 +38,7 @@ func (c *MerchantService) UserPayConfig(userName string) map[string]string {
}
return merchantMapData
}
}*/
/**
** 获取商户信息

View File

@ -0,0 +1,516 @@
package service
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"legend/models/legend"
"legend/request"
"legend/response"
"legend/utils"
)
type TemplateService struct {
BaseService
}
/**
** 添加比例模板
*/
func (c *TemplateService) AddTemplate(req *request.AddTemplateReq, merchantUid string) *response.AddTemplateResp {
template := new(legend.ScaleTemplate)
template.MerchantUid = merchantUid
template.TemplateName = req.ScaleTemplateName
template.UserUid = req.ScaleUserName
template.UserWarn = req.ScaleUserNamePoint
template.MoneyType = req.MoneyType
template.PresentType = req.PresentType
template.UpdateTime = utils.GetNowTime()
template.CreateTime = utils.GetNowTime()
addTemplateResp := new(response.AddTemplateResp)
addTemplateResp.Code = -1
if template.TemplateName == "" {
addTemplateResp.Msg = "模板名称不能为空"
return addTemplateResp
}
if legend.IsExistsScaleTemplateByName(template.TemplateName) {
addTemplateResp.Msg = "模板名称重复,请换一个名称!"
return addTemplateResp
}
if legend.InsertScaleTemplate(template) {
addTemplateResp.Code = 0
addTemplateResp.Msg = "添加比例模板成功"
if !c.AddRandMoney(req) {
addTemplateResp.Code = -1
addTemplateResp.Msg = "随机金额添加失败,请检查参数是否合理"
}
if !c.AddFixMoney(req) {
addTemplateResp.Code = -1
addTemplateResp.Msg = "添加固定金额失败,请检查参数是否合理"
}
if !c.AddPresentFixMoney(req) {
addTemplateResp.Code = -1
addTemplateResp.Msg = "添加固定金额赠送失败,请检查参数是否合理"
}
if !c.AddPresentScaleMoney(req) {
addTemplateResp.Code = -1
addTemplateResp.Msg = "添加金额比例赠送失败,请检查参数是否合理"
}
// 只要有一个添加失败,全部删除
if addTemplateResp.Code == -1 {
legend.DeleteScaleTemplate(template.TemplateName)
legend.DeleteAnyMoney(template.TemplateName)
legend.DeleteFixMoney(template.TemplateName)
legend.DeleteFixPresent(template.TemplateName)
legend.DeleteScalePresent(template.TemplateName)
}
} else {
addTemplateResp.Msg = "添加比例模板失败"
}
return addTemplateResp
}
/**
** 编辑比例模板逻辑
*/
func (c *TemplateService) UpdateTemplate(req *request.AddTemplateReq, merchantUid string) *response.BaseResp {
resp := new(response.BaseResp)
resp.Code = -1
resp.Msg = "更新失败"
template := legend.GetScaleTemplateByNameAndMerchantUid(req.ScaleTemplateName, merchantUid)
template.UserUid = req.ScaleUserName
template.UserWarn = req.ScaleUserNamePoint
template.MoneyType = req.MoneyType
template.PresentType = req.PresentType
template.UpdateTime = utils.GetNowTime()
if !legend.UpdateScaleTemplate(template) {
logs.Error("更新比例模板基础数据失败")
return resp
}
if !c.updateAnyMoney(req) {
logs.Error("更新任意金额数据失败")
return resp
}
if !c.updateFixMoney(req) {
logs.Error("更新固定金额数据失败")
return resp
}
if !c.updateFixPresent(req) {
logs.Error("更新赠送固定金额失败")
return resp
}
if !c.updateScalePresent(req) {
logs.Error("更新赠送比例数据失败")
return resp
}
resp.Code = 0
resp.Msg = "更新成功"
return resp
}
/**
** 更新任意金额
*/
func (c *TemplateService) updateAnyMoney(req *request.AddTemplateReq) bool {
if req.GameMoneyScale <= 0 && req.LimitLowMoney <= 0 {
logs.Debug("任意金额的2个关键参数均小于等于0")
anyMoney := legend.GetAnyMoneyByName(req.ScaleTemplateName)
if anyMoney != nil && anyMoney.TemplateName != "" {
return legend.DeleteAnyMoney(req.ScaleTemplateName)
} else {
logs.Error("不存在这样的任意金额")
return false
}
} else {
anyMoney := legend.GetAnyMoneyByName(req.ScaleTemplateName)
anyMoney.GameMoneyScale = req.GameMoneyScale
anyMoney.GameMoneyName = req.GameMoneyName
anyMoney.LimitLow = req.LimitLowMoney
anyMoney.UpdateTime = utils.GetNowTime()
anyMoney.CreateTime = utils.GetNowTime()
return legend.UpdateAnyMoney(anyMoney)
}
}
/**
** 更新固定金额
*/
func (c *TemplateService) updateFixMoney(req *request.AddTemplateReq) bool {
for _, fixMoney := range legend.GetFixMoneyByName(req.ScaleTemplateName) {
if !c.isExist(fixMoney.Uid, req.FixUids) {
// 假如不存在了,那么需要删除这条记录
legend.DeleteFixMoneyByUid(fixMoney.Uid)
}
}
for i, _ := range req.FixUids {
if req.FixUids[i] == "" {
continue
}
fixMoney := legend.GetFixMoneyByUid(req.FixUids[i])
fixMoney.UpdateTime = utils.GetNowTime()
fixMoney.Uid = req.FixUids[i]
fixMoney.Price = req.FixPrices[i]
fixMoney.GoodsName = req.GoodsNames[i]
fixMoney.GoodsNo = req.GoodsNos[i]
fixMoney.BuyTimes = req.Limits[i]
if fixMoney.TemplateName == "" {
fixMoney.CreateTime = utils.GetNowTime()
fixMoney.TemplateName = req.ScaleTemplateName
legend.InsertFixMoney(fixMoney)
} else {
legend.UpdateFixMoney(fixMoney)
}
}
return true
}
/**
** 更新固定金额赠送参数
*/
func (c *TemplateService) updateFixPresent(req *request.AddTemplateReq) bool {
for _, fixPresentMoney := range legend.GetFixPresentsByName(req.ScaleTemplateName) {
if !c.isExist(fixPresentMoney.Uid, req.PresentFixUids) {
legend.DeleteFixPresentByUid(fixPresentMoney.Uid)
}
}
for i, _ := range req.PresentFixUids {
if req.PresentFixUids[i] == "" {
continue
}
fixPresent := legend.GetFixPresentByUid(req.PresentFixUids[i])
fixPresent.UpdateTime = utils.GetNowTime()
fixPresent.Uid = req.PresentFixUids[i]
fixPresent.Money = req.PresentFixMoneys[i]
fixPresent.PresentMoney = req.PresentFixPresentMoneys[i]
if fixPresent.TemplateName == "" {
fixPresent.CreateTime = utils.GetNowTime()
fixPresent.TemplateName = req.ScaleTemplateName
legend.InsertFixPresent(fixPresent)
} else {
legend.UpdatePresentFixMoney(fixPresent)
}
}
return true
}
/**
** 更新比例赠送参数
*/
func (c *TemplateService) updateScalePresent(req *request.AddTemplateReq) bool {
for _, scalePresent := range legend.GetScalePresentsByName(req.ScaleTemplateName) {
if !c.isExist(scalePresent.Uid, req.PresentScaleUids) {
legend.DeleteScalePresentByUid(scalePresent.Uid)
}
}
for i, _ := range req.PresentScaleUids {
if req.PresentScaleUids[i] == "" {
continue
}
scalePresent := legend.GetScalePresentByUid(req.PresentScaleUids[i])
scalePresent.UpdateTime = utils.GetNowTime()
scalePresent.Uid = req.PresentScaleUids[i]
scalePresent.Money = req.PresentScaleMoneys[i]
scalePresent.PresentScale = req.PresentScales[i]
if scalePresent.TemplateName == "" {
scalePresent.TemplateName = req.ScaleTemplateName
scalePresent.CreateTime = utils.GetNowTime()
legend.InsertScalePresent(scalePresent)
} else {
legend.UpdateScalePresent(scalePresent)
}
}
return true
}
func (c *TemplateService) isExist(j string, ss []string) bool {
for _, s := range ss {
if s == j {
return true
}
}
return false
}
/**
** 添加随机金额
*/
func (c *TemplateService) AddRandMoney(req *request.AddTemplateReq) bool {
if req.LimitLowMoney < 0 {
logs.Error("随机金额中的最低充值金额不能小于0")
return false
}
if req.GameMoneyName == "" && req.GameMoneyScale <= 0 {
logs.Info("不需要添加随机金额选项")
return true
}
anyMoney := new(legend.AnyMoney)
anyMoney.TemplateName = req.ScaleTemplateName
anyMoney.GameMoneyName = req.GameMoneyName
anyMoney.GameMoneyScale = req.GameMoneyScale
anyMoney.LimitLow = req.LimitLowMoney
anyMoney.UpdateTime = utils.GetNowTime()
anyMoney.CreateTime = utils.GetNowTime()
if legend.InsertAnyMoney(anyMoney) {
logs.Info("添加随机金额成功!")
} else {
return false
}
return true
}
/**
**添加固定金额
*/
func (c *TemplateService) AddFixMoney(req *request.AddTemplateReq) bool {
l := len(req.FixUids)
if l == 0 || (l == 1 && req.FixUids[0] == "") {
logs.Error("该模板没有添加固定金额选项")
return true
}
if l != len(req.GoodsNames) || l != len(req.FixPrices) || l != len(req.GoodsNos) || l != len(req.Limits) {
logs.Error("固定金额参数有误,长度不一致")
return false
}
for i := 0; i < l; i++ {
fixUid := req.FixUids[i]
fixPrice := req.FixPrices[i]
goodName := req.GoodsNames[i]
goodNo := req.GoodsNos[i]
limit := req.Limits[i]
if fixUid == "0" && fixPrice <= 0 && goodName == "0" && goodNo == "0" && limit <= 0 {
logs.Error("固定金额4个参数都为空")
continue
}
if fixUid == "0" || fixPrice <= 0 || goodName == "0" || goodNo == "0" || limit <= 0 {
logs.Error("固定金额参数中有一个缺失: ", fmt.Sprintf("fixUid = %s, fixPrice = %f, goodName = %s, goodNo = %s, limit = %d",
fixUid, fixPrice, goodName, goodNo, limit))
return false
}
fixMoney := new(legend.FixMoney)
fixMoney.Uid = fixUid
fixMoney.TemplateName = req.ScaleTemplateName
fixMoney.Price = fixPrice
fixMoney.GoodsName = goodName
fixMoney.GoodsNo = goodNo
fixMoney.BuyTimes = limit
fixMoney.UpdateTime = utils.GetNowTime()
fixMoney.CreateTime = utils.GetNowTime()
if !legend.InsertFixMoney(fixMoney) {
logs.Error("该次固定金额插入数据库失败")
}
}
return true
}
/**
** 添加赠送固定金额赠送
*/
func (c *TemplateService) AddPresentFixMoney(req *request.AddTemplateReq) bool {
l := len(req.PresentFixUids)
if l == 0 || (l == 1 && req.PresentScaleUids[0] == "") {
logs.Error("该模板没有添加固定金额赠送选项")
return true
}
if l != len(req.PresentFixMoneys) || l != len(req.PresentFixPresentMoneys) {
logs.Error("固定金额赠送选项参数个数不一致")
return false
}
for i := 0; i < l; i++ {
uid := req.PresentFixUids[i]
fixMoney := req.PresentFixMoneys[i]
presentMoney := req.PresentFixPresentMoneys[i]
if uid == "0" && fixMoney <= 0 && presentMoney <= 0 {
continue
}
if uid == "0" || fixMoney <= 0 || presentMoney <= 0 {
logs.Error("固定金额参数中有一个缺失: ", fmt.Sprintf("fixUid = %s, fixPrice = %f, presentMoney = %f",
uid, fixMoney, presentMoney))
return false
}
fixPresent := new(legend.FixPresent)
fixPresent.Uid = uid
fixPresent.TemplateName = req.ScaleTemplateName
fixPresent.Money = fixMoney
fixPresent.PresentMoney = presentMoney
fixPresent.UpdateTime = utils.GetNowTime()
fixPresent.CreateTime = utils.GetNowTime()
if !legend.InsertFixPresent(fixPresent) {
logs.Error("该次固定金额赠送插入数据库失败")
}
}
return true
}
/**
** 添加赠送金额比例
*/
func (c *TemplateService) AddPresentScaleMoney(req *request.AddTemplateReq) bool {
l := len(req.PresentScaleUids)
if l == 0 || (l == 1 && req.PresentScaleUids[0] == "") {
logs.Error("该模板没有添加按百分比赠送")
return true
}
if l != len(req.PresentScaleMoneys) || l != len(req.PresentScales) {
logs.Error("按百分比赠送选项参数个数不一致")
return false
}
for i := 0; i < l; i++ {
uid := req.PresentScaleUids[i]
money := req.PresentScaleMoneys[i]
scale := req.PresentScales[i]
if money <= 0 {
logs.Error("金额不能等于0")
return false
}
if uid == "0" && money <= 0 && scale <= 0 {
continue
}
if uid == "0" || money <= 0 || scale <= 0 {
logs.Error("百分比赠送缺失参数: ", fmt.Sprintf("uid = %s, money = %f, scale = %f",
uid, money, scale))
return false
}
scalePresent := new(legend.ScalePresent)
scalePresent.Uid = uid
scalePresent.TemplateName = req.ScaleTemplateName
scalePresent.Money = money
scalePresent.PresentScale = scale
scalePresent.UpdateTime = utils.GetNowTime()
scalePresent.CreateTime = utils.GetNowTime()
if !legend.InsertScalePresent(scalePresent) {
logs.Error("该次固定金额赠送插入数据库失败")
}
}
return true
}
func (c *TemplateService) GetTemplateList(page, limit int) *response.TemplateListResp {
offset := utils.CountOffset(page, limit)
count := legend.GetScaleTemplateAll()
scaleTemplates := legend.GetScaleTemplateList(offset, limit)
for i, _ := range scaleTemplates {
scaleTemplates[i].Id = offset + i + 1
}
templateListResp := new(response.TemplateListResp)
templateListResp.Count = count
templateListResp.Code = 0
templateListResp.Data = scaleTemplates
return templateListResp
}
/**
** 删除比例模板的所有内容
*/
func (c *TemplateService) DeleteTemplate(templateName string) *response.BaseResp {
baseResp := new(response.BaseResp)
baseResp.Code = -1
b := true
if !legend.DeleteScaleTemplate(templateName) {
b = false
}
if !legend.DeleteAnyMoney(templateName) {
b = false
}
if !legend.DeleteFixMoney(templateName) {
b = false
}
if !legend.DeleteFixPresent(templateName) {
b = false
}
if !legend.DeleteFixPresent(templateName) {
b = false
}
if b {
baseResp.Msg = "删除成功"
baseResp.Code = 0
} else {
baseResp.Msg = "删除失败"
}
return baseResp
}
func (c *TemplateService) AllTemplateInfo(templateName string) *response.TemplateAllInfoResp {
templateAllInfo := new(response.TemplateAllInfoResp)
templateAllInfo.TemplateInfo = legend.GetScaleTemplateByName(templateName)
templateAllInfo.AnyMoneyInfo = legend.GetAnyMoneyByName(templateName)
templateAllInfo.FixMoneyInfos = legend.GetFixMoneyByName(templateName)
templateAllInfo.PresentFixMoneyInfos = legend.GetFixPresentsByName(templateName)
templateAllInfo.PresentScaleMoneyInfos = legend.GetScalePresentsByName(templateName)
return templateAllInfo
}

View File

@ -1,11 +1,12 @@
{
"code":0,"msg":"",
"code":0,
"msg":"",
"count":10,
"data":[
{
"id": 1,
"areaname": "狗日的1-2区",
"usetemplete": "狗日",
"usetemplate": "狗日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -14,7 +15,7 @@
{
"id": 2,
"areaname": "猪日1-2区",
"usetemplete": "猪日",
"usetemplate": "猪日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -23,7 +24,7 @@
{
"id": 3,
"areaname": "牛日1-2区",
"usetemplete": "牛日",
"usetemplate": "牛日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -32,7 +33,7 @@
{
"id": 4,
"areaname": "鸡日1-2区",
"usetemplete": "鸡日",
"usetemplate": "鸡日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -41,7 +42,7 @@
{
"id": 5,
"areaname": "鸭日1-2区",
"usetemplete": "鸭日",
"usetemplate": "鸭日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -50,7 +51,7 @@
{
"id": 6,
"areaname": "蚯蚓1-2区",
"usetemplete": "蚯蚓日",
"usetemplate": "蚯蚓日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -59,7 +60,7 @@
{
"id": 7,
"areaname": "蛇日1-2区",
"usetemplete": "蛇日",
"usetemplate": "蛇日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -68,7 +69,7 @@
{
"id": 8,
"areaname": "人日1-2区",
"usetemplete": "人日",
"usetemplate": "人日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -77,7 +78,7 @@
{
"id": 9,
"areaname": "苍蝇1-2区",
"usetemplete": "苍蝇日",
"usetemplate": "苍蝇日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",
@ -86,7 +87,7 @@
{
"id": 10,
"areaname": "蚊子1-2区",
"usetemplete": "蚊子日",
"usetemplate": "蚊子日",
"currencyname": "元宝",
"rechargescale": 10,
"areastatus": "开放",

View File

@ -0,0 +1,47 @@
package utils
import (
"github.com/beego/beego/v2/core/logs"
"strconv"
"strings"
)
func StringToFloats(s string) []float64 {
fs := make([]float64, 0)
if s == "" || len(s) == 0 {
return fs
}
str := strings.Split(s, ",")
for i := 0; i < len(str); i++ {
s := str[i]
logs.Debug("string to float", s)
if f, err := strconv.ParseFloat(s, 64); err != nil {
logs.Error("string to float64 err", err)
fs = append(fs, 0)
} else {
fs = append(fs, f)
}
}
return fs
}
func StringToInt(s string) []int {
is := make([]int, 0)
if s == "" || len(s) == 0 {
return is
}
ss := strings.Split(s, ",")
for i := 0; i < len(ss); i++ {
if a, err := strconv.Atoi(ss[i]); err != nil {
logs.Error("string to int err", err)
is = append(is, 0)
} else {
is = append(is, a)
}
}
return is
}

12
legend/utils/tableTool.go Normal file
View File

@ -0,0 +1,12 @@
package utils
/**
** 计算偏移量
*/
func CountOffset(page, limit int) int {
if page > 0 {
return (page - 1) * limit
} else {
return limit
}
}

View File

@ -56,7 +56,7 @@
<div class="layui-form-item">
<label class="layui-form-label">选择模板</label>
<div class="layui-input-inline">
<select name="selecttemplete" lay-verify="required">
<select name="selecttemplate" lay-verify="required">
<option value=""></option>
<option value="xingsha">星沙二区</option>
<option value="dongguan">东莞</option>

View File

@ -62,7 +62,7 @@
,cols: [[ //表头
{field: 'id', title: 'ID', sort: true, fixed: 'left'}
,{field: 'areaname', title: '分区名称'}
,{field: 'usetemplete', title: '使用模板', sort: true}
,{field: 'usetemplate', title: '使用模板', sort: true}
,{field: 'currencyname', title: '货币名称', sort:false}
,{field: 'rechargescale', title: '充值比例', sort: true}
,{field: 'areastatus', title: '分区状态', sort: true}

View File

@ -66,7 +66,7 @@
</li>
<li>
<a onclick="xadmin.add_tab('比例模板', './scaleTemplete.html')">
<a onclick="xadmin.add_tab('比例模板', './scaleTemplate.html')">
<i class="layui-icon layui-icon-template"></i>
<cite><strong>比例模板</strong></cite>
</a>

View File

@ -33,36 +33,34 @@
<td><h3>{{.userName}}</h3></td></tr>
<tr>
<th><h3>商户账户号</h3></th>
<td>{{.userInfo.UserNo}}</td></tr>
<td>{{.userInfo.MerchantUid}}</td></tr>
<tr>
<th><h3>商户密钥</h3></th>
<td><h3 id="copy-key" style="float:left;">{{.payConfigInfo.PaySecret}} </h3>
<td><h3 id="copy-key" style="float:left;">{{.userInfo.MerchantSecret}} </h3>
<button style="float:left; margin-left: 20px;" class="layui-btn layui-btn-normal layui-btn-sm" onclick="copy();">点击复制</button>
</td>
</tr>
<tr>
<th><h3>商户KEY</h3></th>
<td><h3 id="copy-pay" style="float:left;">{{.payConfigInfo.PayKey}}</h3>
<td><h3 id="copy-pay" style="float:left;">{{.userInfo.MerchantKey}}</h3>
<button style="float: left; margin-left: 20px;" class="layui-btn layui-btn-normal layui-btn-sm" onclick="copy(1);">点击复制</button></td></tr>
<tr>
<th><h3>邮箱地址</h3></th>
<td><h3>{{.userInfo.Email}}</h3></td></tr>
<tr>
<th><h3>银行开户名</h3></th>
<td><h3>{{.bankInfo.BankAccountName}}</h3></td></tr>
<td><h3>{{.bankInfo.AccountName}}</h3></td></tr>
<tr>
<th><h3>开户银行</h3></th>
<td><h3>{{.bankInfo.BankName}}</h3></td></tr>
<tr>
<th><h3>银行卡号</h3></th>
<td><h3>{{.bankInfo.BankAccountNo}}</h3></td></tr>
<td><h3>{{.bankInfo.BankNo}}</h3></td></tr>
<tr>
<th><h3>银行编码</h3></th>
<td><h3>{{.bankInfo.BankCode}}</h3></td></tr>
<tr>
<th><h3>手机号码</h3></th>
<td><h3>{{.userInfo.Mobile}}</h3></td></tr>
<td><h3>{{.bankInfo.PhoneNo}}</h3></td></tr>
</tbody>
</table>
</div>

View File

@ -15,32 +15,27 @@
<script src="../static/x-admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/x-admin/js/xadmin.js"></script>
<script type="text/javascript" src="../static/js/jquery-3.5.1.min.js"></script>
<!-- 让IE8/9支持媒体查询从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="layui-fluid">
<div class="layui-card">
{{/* <div class="layui-card-header"><strong>首页 / 比例模板</strong></div>*/}}
<div class="layui-card-body">
<table id="demo" lay-filter="test"></table>
<script type="text/html" id="toolbarHead">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="create-templete"><i class="layui-icon layui-icon-add-1"></i>创建模板</button>
<button class="layui-btn layui-btn-sm" lay-event="create-template"><i class="layui-icon layui-icon-add-1"></i>创建模板</button>
</div>
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="edit-templete"><i class="layui-icon layui-icon-edit"></i> 编辑</button>
<button class="layui-btn layui-btn-danger" lay-event="delete-templete"><i class="layui-icon layui-icon-delete"></i>删除</button>
<button class="layui-btn layui-btn-sm" lay-event="edit-template"><i class="layui-icon layui-icon-edit"></i> 编辑</button>
<button class="layui-btn layui-btn-danger" lay-event="delete-template"><i class="layui-icon layui-icon-delete"></i>删除</button>
</div>
</script>
@ -51,21 +46,17 @@
//第一个实例
table.render({
elem: '#demo'
,height: 500
,height: 460
// ,width: 480
,url: '/static/data/json.json' //数据接口
,url: '/template/list' //数据接口
,page: true //开启分页
,limits: [10, 20, 30, 50, 100, 200]
,cols: [[ //表头
{field: 'id', title: 'ID', sort: true, fixed: 'left'}
,{field: 'username', title: '用户名', width:80}
,{field: 'sex', title: '性别', sort: true}
,{field: 'city', title: '城市'}
,{field: 'sign', title: '签名'}
,{field: 'experience', title: '积分', sort: true}
,{field: 'score', title: '评分', sort: true}
,{field: 'classify', title: '职业'}
,{field: 'wealth', title: '财富', sort: true}
{field: 'Id', title: 'ID', sort: true, fixed: 'left'}
,{field: 'TemplateName', title: '模板名称'}
,{field: 'UserUid', title: '用户标识'}
,{field: 'UserWarn', title: '提醒标语'}
,{field: 'CreateTime', title: '创建时间', sort: true}
,{fixed: 'right', title: "操作", width:180, align:'center', toolbar: '#toolbarDemo'}
]]
,toolbar: "#toolbarHead"
@ -75,8 +66,8 @@
table.on('toolbar(test)', function (obj) {
let event = obj.event;
// 头工具栏的监听事件
if (event === "create-templete") {
location.href = "/templeteAdd.html";
if (event === "create-template") {
location.href = "/templateAdd.html"
}
});
@ -87,18 +78,37 @@
let event = obj.event;
// 编辑行内容
if (event === "edit-templete") {
layer.msg("编辑该行的内容");
if (event === "edit-template") {
location.href = "/templateEdit.html?templateName=" + data.TemplateName;
}
// 删除该行
if (event === "delete-templete") {
if (event === "delete-template") {
layer.confirm("确定删除该行?", function (index) {
obj.del();
$.ajax({
url: "/delete/template",
data: {
"TemplateName": data.TemplateName
},
success: function (res) {
console.log(res)
if (res.Code === 0) {
obj.del()
table.reload('demo', {
url: "/template/list"
})
} else {
alert(res.Msg)
}
},
error: function () {
alert("系统异常")
}
})
layer.close(index);
})
}
})
});
});
</script>
</div>

View File

@ -27,29 +27,31 @@
<div class="layui-card-header"><b>配置模板</b></div>
<div class="layui-card-body">
<div class="layui-row">
<form class="layui-form" action="">
<form class="layui-form" action="" method="post">
<div class="layui-collapse">
<div class="layui-colla-item">
<h1 class="layui-colla-title">基础配置</h1>
<div class="layui-colla-content layui-show">
<div class="layui-form-item">
<label class="layui-form-label"><strong>模板名称</strong></label>
<div class="layui-input-inline">
<input type="text" name="scale-templete-name" required lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="scaleTemplateName" required lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">取名保证唯一性</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识</strong></label>
<div class="layui-input-inline">
<input type="text" name="scale-user-name" required lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="scaleUserName" required lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">可填写角色名或者角色ID不可为空</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识提示</strong></label>
<div class="layui-input-inline">
<input type="text" name="scale-user-name-point" required lay-verify="required" placeholder="如通过角色属性面板查看角色ID" autocomplete="off" class="layui-input">
<input type="text" name="scaleUserNamePoint" placeholder="如通过角色属性面板查看角色ID" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">此提示会在充值页面显示提示玩家如何查看用户标识</div>
</div>
@ -57,8 +59,8 @@
<div class="layui-form-item">
<label class="layui-form-label"><strong>金额类型</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="money-type-filter" name="money-type" value="any-money" title="任意金额" checked>
<input type="radio" lay-filter="money-type-filter" name="money-type" value="fixed-money-type" title="固定金额">
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-any-money" title="任意金额" checked>
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-fixed-money" title="固定金额">
</div>
</div>
@ -68,7 +70,7 @@
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币名称</strong></label>
<div class="layui-input-inline">
<input type="text" name="game-money-name" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
<input type="text" name="gameMoneyName" placeholder="" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是元宝也可以是钻石点券</div>
</div>
@ -76,7 +78,7 @@
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币比例</strong></label>
<div class="layui-input-inline">
<input type="text" name="game-money-scale" required lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="gameMoneyScale" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是100既充值1元人命币转为100游戏币</div>
</div>
@ -84,7 +86,7 @@
<div class="layui-form-item">
<label class="layui-form-label"><strong>最低充值金额</strong></label>
<div class="layui-input-inline">
<input type="text" name="limit-low-money" required lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="limitLowMoney" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认最低为10元</div>
</div>
@ -92,24 +94,6 @@
<!-- 固定金额的样式-->
<div id="fixed-money-style" class="layui-row" style="margin-left: 40px;">
<div class="layui-form-item">
<div class="layui-col-md1" style="margin-left: 10px;">
<input type="text" name="limit-low-money" required lay-verify="required" placeholder="售价(元)" autocomplete="off" class="layui-input">
</div>
<div class=" layui-col-md2" style="margin-left: 10px;">
<input type="text" name="limit-low-money" required lay-verify="required" placeholder="商品名称" autocomplete="off" class="layui-input">
</div>
<div class="layui-col-md2" style="margin-left: 10px;">
<input type="text" name="limit-low-money" required lay-verify="required" placeholder="商品编号" autocomplete="off" class="layui-input">
</div>
<div class="layui-col-md1" style="margin-left: 10px;">
<input type="text" name="limit-low-money" required lay-verify="required" placeholder="可够次数" autocomplete="off" class="layui-input">
</div>
<div class="layui-inline" style="margin-left: 10px;">
<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i> </div>
</div>
</div>
<div id="fixed-money-child-style"></div>
<div class="layui-btn" style="margin-left: 10px;" onclick="addFixedMoenyStyle();"><i class="layui-icon layui-icon-add-circle">添加商品</i></div>
@ -126,58 +110,34 @@
<div class="layui-form-item">
<label class="layui-form-label"><strong>赠送方式</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="present-type-filter" name="present-type" value="close-present" title="关闭" checked>
<input type="radio" lay-filter="present-type-filter" name="present-type" value="fixed-money-present" title="固定金额赠送">
<input type="radio" lay-filter="present-type-filter" name="present-type" value="fscale-present" title="按百分比赠送">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="close-present" title="关闭" checked>
<input type="radio" lay-filter="present-type-filter" name="presentType" value="fixed-money-present" title="固定金额赠送">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="scale-present" title="按百分比赠送">
</div>
</div>
<!-- 按金额赠送-->
<div id="present-type-money-style">
<div class="layui-form-item">
<label class="layui-form-label"><strong>充值</strong></label>
<div class="layui-input-inline">
<input type="text" name="scale-user-name" required lay-verify="required" placeholder="金额(元)" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline">
<input type="text" name="scale-user-name" required lay-verify="required" placeholder="赠送金额(元)" autocomplete="off" class="layui-input">
</div>
<div class="layui-inline">
<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div>
</div>
</div>
<div id="present-type-money-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeMoneyStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
<!-- 按百分比赠送-->
<div id="present-type-scale-style">
<div class="layui-form-item">
<label class="layui-form-label"><strong>充值</strong></label>
<div class="layui-input-inline">
<input type="text" name="scale-user-name" required lay-verify="required" placeholder="金额(元)" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline">
<input type="text" name="scale-user-name" required lay-verify="required" placeholder="赠送比例(%" autocomplete="off" class="layui-input">
</div>
<div class="layui-inline">
<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div>
</div>
</div>
<div id="present-type-scale-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeScaleStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<br>
<button class="layui-btn" lay-filter="add" lay-submit="">保存/添加</button>
<div class="layui-btn layui-btn-danger" onclick="back();">返回当前页</div>
</div>
</form>
</div>
<div class="layui-form-item">
<br>
<button class="layui-btn" lay-filter="add">保存/添加</button>
<button class="layui-btn layui-btn-danger" lay-filter="back" lay-submit="">返回当前页</button>
</div>
</div>
</div>
</div>
@ -186,9 +146,12 @@
// 动态添加固定金额赠送input框
function addPresentTypeMoneyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="scale-user-name" required lay-verify="required" placeholder="金额(元)" autocomplete="off" class="layui-input"></div><div class="layui-input-inline">' +
'<input type="text" name="scale-user-name" required lay-verify="required" placeholder="赠送金额(元)" autocomplete="off" class="layui-input">' +
'<input type="text" name="present-fix-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-fix-money">' +
'<input type="hidden" name="present-fix-uid" value="' + s + '" autocomplete="off" class="layui-input present-fix-uid">' +
'</div><div class="layui-input-inline">' +
'<input type="text" name="present-fix-present-money" placeholder="赠送金额(元)" autocomplete="off" class="layui-input present-fix-present-money">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-money-child-style").append(str);
@ -196,9 +159,11 @@
// 动态添加按百分比赠送input框
function addPresentTypeScaleStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="scale-user-name" required lay-verify="required" placeholder="金额(元)" autocomplete="off" class="layui-input">' +
'</div><div class="layui-input-inline"><input type="text" name="scale-user-name" required lay-verify="required" placeholder="赠送比例(%" autocomplete="off" class="layui-input">' +
'<input type="text" name="present-scale-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-scale-money">' +
'<input type="hidden" name="present-scale-uid" value="' + s + '" autocomplete="off" class="layui-input present-scale-uid">' +
'</div><div class="layui-input-inline"><input type="text" name="present-scale" placeholder="赠送比例(%" autocomplete="off" class="layui-input present-scale">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-scale-child-style").append(str);
@ -206,19 +171,22 @@
// 动态添加固定金额的input输入框
function addFixedMoenyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item">' +
'<div class="layui-col-md1" style="margin-left: 10px;">' +
'<input type="text" name="limit-low-money" required lay-verify="required" placeholder="售价(元)" autocomplete="off" class="layui-input">' +
'<input type="text" name="fix-price" placeholder="售价(元)" autocomplete="off" class="layui-input fix-price">' +
'<input type="hidden" name="fix-uid" autocomplete="off" class="layui-input fix-uid" value="' + s + '">' +
'</div><div class=" layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="limit-low-money" required lay-verify="required" placeholder="商品名称" autocomplete="off" class="layui-input">' +
'<input type="text" name="fix-goods-name" placeholder="商品名称" autocomplete="off" class="layui-input fix-goods-name">' +
'</div><div class="layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="limit-low-money" required lay-verify="required" placeholder="商品编号" autocomplete="off" class="layui-input">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="limit-low-money" required lay-verify="required" placeholder="可够次数" autocomplete="off" class="layui-input">' +
'<input type="text" name="fix-goods-no" placeholder="商品编号" autocomplete="off" class="layui-input fix-goods-no">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="fix-limit-low" placeholder="可够次数" autocomplete="off" class="layui-input fix-limit-low">' +
'</div><div class="layui-inline" style="margin-left: 10px;">' +
'<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete"> 删除</i></div></div></div>';
$("#fixed-money-child-style").append(str);
// $(".fix-uid").val(randomString(20))
}
// 删除固金额input
@ -228,14 +196,16 @@
layui.use(['form', 'layer', 'element'], function() {
// 启动element木块
let element = layui.element;
$ = layui.jquery;
var form = layui.form,
let form = layui.form,
layer = layui.layer;
// 进入该页面首先做的事情
$(document).ready(function () {
$("#fixed-money-style").toggle();
// $("#fixed-money-style").toggle();
$("#fixed-money-style").hide();
$("#any-money-style").show();
$("#present-type-money-style").hide();
$("#present-type-scale-style").hide();
})
@ -264,7 +234,7 @@
} else if ("fixed-money-present" === radioValue) {
$("#present-type-money-style").show();
$("#present-type-scale-style").hide();
} else if ("fscale-present" === radioValue) {
} else if ("scale-present" === radioValue) {
$("#present-type-money-style").hide();
$("#present-type-scale-style").show();
}
@ -273,39 +243,99 @@
// 监听金额类型的radio
form.on('radio(money-type-filter)', function (data) {
let value = data.value;
if ("any-monty" === value) {
if ("radio-any-money" === value) {
//处理任何金额
$("#any-money-style").toggle();
$("#fixed-money-style").toggle();
$("#any-money-style").show();
$("#fixed-money-style").hide();
} else {
// 处理固定金额
$("#any-money-style").toggle();
$("#fixed-money-style").toggle();
$("#any-money-style").hide();
$("#fixed-money-style").show();
}
})
//监听提交
form.on('submit(add)', function(data) {
console.log(data);
let jsonObj = {}
jsonObj.scaleTemplateName = data.field.scaleTemplateName
jsonObj.scaleUserName = data.field.scaleUserName
jsonObj.scaleUserNamePoint = data.field.scaleUserNamePoint
jsonObj.moneyType = data.field.moneyType
jsonObj.gameMoneyName = data.field.gameMoneyName
jsonObj.gameMoneyScale = data.field.gameMoneyScale
if (data.field.limitLowMoney === "" || data.field.limitLowMoney === null) {
jsonObj.limitLowMoney = "10"
} else {
jsonObj.limitLowMoney = data.field.limitLowMoney
}
jsonObj.presentType = data.field.presentType
jsonObj.fixPrices = getArrays(".fix-price")
jsonObj.goodsNames = getArrays(".fix-goods-name")
jsonObj.goodsNos = getArrays(".fix-goods-no")
jsonObj.limits = getArrays(".fix-limit-low")
jsonObj.presentFixMoneys = getArrays(".present-fix-money")
jsonObj.presentFixPresentMoneys = getArrays(".present-fix-present-money")
jsonObj.presentScaleMoneys =getArrays(".present-scale-money")
jsonObj.presentScales = getArrays(".present-scale")
jsonObj.fixUids = getArrays(".fix-uid")
jsonObj.presentScaleUids = getArrays(".present-scale-uid")
jsonObj.presentFixUids = getArrays(".present-fix-uid")
console.log(JSON.stringify(jsonObj))
//发异步把数据提交给php
layer.alert("增加成功", {
icon: 6
},
function() {
// 获得frame索引
var index = parent.layer.getFrameIndex(window.name);
//关闭当前frame
parent.layer.close(index);
$.ajax({
url: "/add/template",
data: jsonObj,
success: function (res) {
alert(res.Msg)
if (res.Code === 0) {
window.history.back(-1);
}
},
error: function () {
layer.alert("系统异常")
}
});
return false;
});
form.on('submit(back)',
function () {
window.history.back(-1);
});
});
function getArrays(obj) {
let arrays = []
$(obj).each(function () {
let v = $(this).val();
if (v === null || v.length <=0) {
arrays.push(0)
} else {
arrays.push(v)
}
})
return arrays.join(",")
}
function back() {
window.history.back(-1);
}
function randomString(n) {
let chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
let res = "";
for(let i = 0; i < n ; i ++) {
let id = Math.ceil(Math.random()*35);
res += chars[id];
}
return res;
}
</script>
</body>

View File

@ -0,0 +1,484 @@
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>充值商户后台</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="../static/x-admin/css/font.css">
<link rel="stylesheet" href="../static/x-admin/css/xadmin.css">
<!-- <link rel="stylesheet" href="./css/theme5.css"> -->
<script src="../static/x-admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/x-admin/js/xadmin.js"></script>
<script type="text/javascript" src="../static/js/jquery-3.5.1.min.js"></script>
<!-- 让IE8/9支持媒体查询从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="layui-fluid">
<div class="layui-card">
<div class="layui-card-header"><b>编辑模板</b></div>
<div class="layui-card-body">
<div class="layui-row">
<form class="layui-form" action="" method="post">
<div class="layui-collapse">
<div class="layui-colla-item">
<h1 class="layui-colla-title">基础配置</h1>
<div class="layui-colla-content layui-show">
<div class="layui-form-item">
<label class="layui-form-label"><strong>模板名称</strong></label>
<div class="layui-input-inline">
<input type="text" readonly="readonly" name="scaleTemplateName" value="{{.scaleTemplateName}}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识</strong></label>
<div class="layui-input-inline">
<input type="text" name="scaleUserName" required lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">可填写角色名或者角色ID不可为空</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识提示</strong></label>
<div class="layui-input-inline">
<input type="text" name="scaleUserNamePoint" placeholder="如通过角色属性面板查看角色ID" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">此提示会在充值页面显示提示玩家如何查看用户标识</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>金额类型</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-any-money" title="任意金额" checked>
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-fixed-money" title="固定金额">
</div>
</div>
<!-- 任意金额的样式 -->
<div id="any-money-style">
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币名称</strong></label>
<div class="layui-input-inline">
<input type="text" name="gameMoneyName" placeholder="" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是元宝也可以是钻石点券</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币比例</strong></label>
<div class="layui-input-inline">
<input type="text" name="gameMoneyScale" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是100既充值1元人命币转为100游戏币</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>最低充值金额</strong></label>
<div class="layui-input-inline">
<input type="text" name="limitLowMoney" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认最低为10元</div>
</div>
</div>
<!-- 固定金额的样式-->
<div id="fixed-money-style" class="layui-row" style="margin-left: 40px;">
<div id="fixed-money-child-style"></div>
<div class="layui-btn" style="margin-left: 10px;" onclick="addFixedMoenyStyle();"><i class="layui-icon layui-icon-add-circle">添加</i></div>
<div style="color: red; margin-left: 10px;"><h3><p>说明请根据游戏内设置的商品道具进行设置切勿乱填</p><p>可购次数填0代表不限填1代表一个帐号仅可购买一次依此类推</p></h3></div>
</div>
</div>
</div>
<div class="layui-colla-item">
<h1 class="layui-colla-title">激励赠送</h1>
<div class="layui-colla-content layui-show">
<div class="layui-form-item">
<label class="layui-form-label"><strong>赠送方式</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="close-present" title="关闭" checked>
<input type="radio" lay-filter="present-type-filter" name="presentType" value="fixed-money-present" title="固定金额赠送">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="scale-present" title="按百分比赠送">
</div>
</div>
<!-- 按金额赠送-->
<div id="present-type-money-style">
<div id="present-type-money-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeMoneyStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
<!-- 按百分比赠送-->
<div id="present-type-scale-style">
<div id="present-type-scale-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeScaleStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<br>
<button class="layui-btn" lay-filter="add" lay-submit="">更新</button>
<div class="layui-btn layui-btn-danger" onclick="back();">返回当前页</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
let fixMoneyFlag = true
let presentFixMoneyFlag = true
let presentScaleMoneyFlag = true
// 动态添加固定金额赠送input框
function addPresentTypeMoneyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-fix-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-fix-money">' +
'<input type="hidden" name="present-fix-uid" value="' + s + '" autocomplete="off" class="layui-input present-fix-uid">' +
'</div><div class="layui-input-inline">' +
'<input type="text" name="present-fix-present-money" placeholder="赠送金额(元)" autocomplete="off" class="layui-input present-fix-present-money">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-money-child-style").append(str);
}
// 动态添加按百分比赠送input框
function addPresentTypeScaleStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-scale-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-scale-money">' +
'<input type="hidden" name="present-scale-uid" value="' + s + '" autocomplete="off" class="layui-input present-scale-uid">' +
'</div><div class="layui-input-inline"><input type="text" name="present-scale" placeholder="赠送比例(%" autocomplete="off" class="layui-input present-scale">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-scale-child-style").append(str);
}
// 动态添加固定金额的input输入框
function addFixedMoenyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item">' +
'<div class="layui-col-md1" style="margin-left: 10px;">' +
'<input type="text" name="fix-price" placeholder="售价(元)" autocomplete="off" class="layui-input fix-price">' +
'<input type="hidden" name="fix-uid" autocomplete="off" class="layui-input fix-uid" value="' + s + '">' +
'</div><div class=" layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-name" placeholder="商品名称" autocomplete="off" class="layui-input fix-goods-name">' +
'</div><div class="layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-no" placeholder="商品编号" autocomplete="off" class="layui-input fix-goods-no">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="fix-limit-low" placeholder="可够次数" autocomplete="off" class="layui-input fix-limit-low">' +
'</div><div class="layui-inline" style="margin-left: 10px;">' +
'<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete"> 删除</i></div></div></div>';
$("#fixed-money-child-style").append(str);
}
function renderScaleInfo(res) {
console.log(res)
if (res.Code !== 0) {
alert("获取比例模板信息失败!")
return false
}
let templateInfo = res.TemplateInfo
let anyMoneyInfo = res.AnyMoneyInfo
let fixMoneyInofs = res.FixMoneyInfos
let presentFixMoneyInfos = res.PresentFixMoneyInfos
let presentScaleMoneyInfos = res.PresentScaleMoneyInfos
console.log(anyMoneyInfo)
$('input[name="scaleUserName"]').val(templateInfo.UserUid)
$('input[name="scaleUserNamePoint"]').val(templateInfo.UserWarn)
$('input[name="gameMoneyName"]').val(anyMoneyInfo.GameMoneyName)
$('input[name="gameMoneyScale"]').val(anyMoneyInfo.GameMoneyScale)
$('input[name="limitLowMoney"]').val(anyMoneyInfo.LimitLow)
$('input:radio[name="moneyType"]').each(function() {
if ($(this).index() === 0) {
$(this).attr('checked', "checked");
}
});
}
function showPresentFixMoney(res) {
for (let i = 0; i < res.PresentFixMoneyInfos.length; i ++) {
let presentFixMoneyInfo = res.PresentFixMoneyInfos[i]
console.log(presentFixMoneyInfo)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-fix-money" placeholder="金额(元)" value="' + presentFixMoneyInfo.Money + '" class="layui-input present-fix-money">' +
'<input type="hidden" name="present-fix-uid" value="' + presentFixMoneyInfo.Uid + '" autocomplete="off" class="layui-input present-fix-uid">' +
'</div><div class="layui-input-inline">' +
'<input type="text" name="present-fix-present-money" placeholder="赠送金额(元)" value="' + presentFixMoneyInfo.PresentMoney + '" class="layui-input present-fix-present-money">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-money-child-style").append(str);
}
}
function showPresentScaleMoney(res) {
for (let i = 0; i < res.PresentScaleMoneyInfos.length; i ++) {
let presentScaleMoneyInfo = res.PresentScaleMoneyInfos[i]
console.log(presentScaleMoneyInfo)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-scale-money" placeholder="金额(元)" value="' + presentScaleMoneyInfo.Money + '" class="layui-input present-scale-money">' +
'<input type="hidden" name="present-scale-uid" value="' + presentScaleMoneyInfo.Uid + '" autocomplete="off" class="layui-input present-scale-uid">' +
'</div><div class="layui-input-inline"><input type="text" name="present-scale" placeholder="赠送比例(%" value="' + presentScaleMoneyInfo.PresentScale + '" class="layui-input present-scale">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-scale-child-style").append(str);
}
}
function showFixMoney(res) {
let fixMoneyInfos = res.FixMoneyInfos
for (let i = 0; i < fixMoneyInfos.length; i ++ ) {
let fixMoneyInfo = fixMoneyInfos[i];
console.log(fixMoneyInfo)
let str = '<div class="layui-form-item">' +
'<div class="layui-col-md1" style="margin-left: 10px;">' +
'<input type="text" name="fix-price" placeholder="售价(元)" autocomplete="off" class="layui-input fix-price" value="' + fixMoneyInfo.Price + '">' +
'<input type="hidden" name="fix-uid" autocomplete="off" class="layui-input fix-uid" value="' + fixMoneyInfo.Uid + '">' +
'</div><div class=" layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-name" placeholder="商品名称" autocomplete="off" class="layui-input fix-goods-name" value="' + fixMoneyInfo.GoodsName + '">' +
'</div><div class="layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-no" placeholder="商品编号" autocomplete="off" value="' + fixMoneyInfo.GoodsNo + '" class="layui-input fix-goods-no">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="fix-limit-low" value="' + fixMoneyInfo.BuyTimes + '" placeholder="可够次数" autocomplete="off" class="layui-input fix-limit-low">' +
'</div><div class="layui-inline" style="margin-left: 10px;">' +
'<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete"> 删除</i></div></div></div>';
$("#fixed-money-child-style").append(str);
}
}
layui.use(['form', 'layer', 'element'], function() {
$ = layui.jquery;
let form = layui.form,
layer = layui.layer;
// 进入该页面首先做的事情
$(document).ready(function () {
$("#fixed-money-style").hide();
$("#any-money-style").show();
$("#present-type-money-style").hide();
$("#present-type-scale-style").hide();
// ajax获取比例模板信息
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
renderScaleInfo(res)
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
return false
})
// 监听赠送类型的radio
form.on('radio(present-type-filter)', function (data) {
let radioValue = data.value;
if ("close-present" === radioValue) {
$("#present-type-money-style").hide();
$("#present-type-scale-style").hide();
} else if ("fixed-money-present" === radioValue) {
$("#present-type-money-style").show();
$("#present-type-scale-style").hide();
if (!presentFixMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
showPresentFixMoney(res)
presentFixMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
} else if ("scale-present" === radioValue) {
$("#present-type-money-style").hide();
$("#present-type-scale-style").show();
if (!presentScaleMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
// $("#fixed-money-child-style").remove()
showPresentScaleMoney(res)
presentScaleMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
}
})
// 监听金额类型的radio
form.on('radio(money-type-filter)', function (data) {
let value = data.value;
if ("radio-any-money" === value) {
//处理任何金额
$("#any-money-style").show();
$("#fixed-money-style").hide();
} else {
// 处理固定金额
$("#any-money-style").hide();
$("#fixed-money-style").show();
if (!fixMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
// $("#fixed-money-child-style").remove()
showFixMoney(res)
fixMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
}
})
//监听提交
form.on('submit(add)', function(data) {
let jsonObj = {}
jsonObj.scaleTemplateName = data.field.scaleTemplateName
jsonObj.scaleUserName = data.field.scaleUserName
jsonObj.scaleUserNamePoint = data.field.scaleUserNamePoint
jsonObj.moneyType = data.field.moneyType
jsonObj.gameMoneyName = data.field.gameMoneyName
jsonObj.gameMoneyScale = data.field.gameMoneyScale
if (data.field.limitLowMoney === "" || data.field.limitLowMoney === null) {
jsonObj.limitLowMoney = "10"
} else {
jsonObj.limitLowMoney = data.field.limitLowMoney
}
jsonObj.presentType = data.field.presentType
jsonObj.fixPrices = getArrays(".fix-price")
jsonObj.goodsNames = getArrays(".fix-goods-name")
jsonObj.goodsNos = getArrays(".fix-goods-no")
jsonObj.limits = getArrays(".fix-limit-low")
jsonObj.presentFixMoneys = getArrays(".present-fix-money")
jsonObj.presentFixPresentMoneys = getArrays(".present-fix-present-money")
jsonObj.presentScaleMoneys =getArrays(".present-scale-money")
jsonObj.presentScales = getArrays(".present-scale")
jsonObj.fixUids = getArrays(".fix-uid")
jsonObj.presentScaleUids = getArrays(".present-scale-uid")
jsonObj.presentFixUids = getArrays(".present-fix-uid")
console.log(JSON.stringify(jsonObj))
//发异步把数据提交给php
$.ajax({
url: "/add/template?type=edit",
data: jsonObj,
success: function (res) {
alert(res.Msg)
if (res.Code === 0) {
window.history.back(-1);
}
},
error: function () {
layer.alert("系统异常")
}
});
return false;
});
});
function getArrays(obj) {
let arrays = []
$(obj).each(function () {
let v = $(this).val();
if (v === null || v.length <=0) {
arrays.push(0)
} else {
arrays.push(v)
}
})
return arrays.join(",")
}
// 删除固金额input
$("div").on('click', '.fixed-money-child-del', function () {
$(this).parent().parent().remove();
})
function back() {
window.history.back(-1);
}
function randomString(n) {
let chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
let res = "";
for(let i = 0; i < n ; i ++) {
let id = Math.ceil(Math.random()*35);
res += chars[id];
}
return res;
}
</script>
</body>
</html>