diff --git a/legend/controllers/areaController.go b/legend/controllers/areaController.go new file mode 100644 index 0000000..44d77b1 --- /dev/null +++ b/legend/controllers/areaController.go @@ -0,0 +1,75 @@ +package controllers + +import ( + "legend/controllers/base" + "legend/request" + "legend/service" +) + +type AreaController struct { + base.BasicController +} + +func (c *AreaController) getRequestPrams() *request.AreaReq { + req := new(request.AreaReq) + req.AreaName = c.GetString("areaName") + req.GroupName = c.GetString("groupName") + req.TemplateName = c.GetString("templateName") + req.NotifyUrl = c.GetString("notifyUrl") + req.AttachParams = c.GetString("attachParams") + return req +} + +func (c *AreaController) AreaAdd() { + + req := c.getRequestPrams() + + se := new(service.AreaService) + area := se.AddArea(req) + + c.Data["json"] = area + _ = c.ServeJSON() +} + +func (c *AreaController) AreaEdit() { + req := c.getRequestPrams() + uid := c.GetString("uid") + + se := new(service.AreaService) + resp := se.EditArea(req, uid) + + c.Data["json"] = resp + + _ = c.ServeJSON() +} + +func (c *AreaController) AreaList() { + page, _ := c.GetInt("page") + limit, _ := c.GetInt("limit") + + se := new(service.AreaService) + list := se.AreaList(page, limit) + + c.Data["json"] = list + _ = c.ServeJSON() +} + +func (c *AreaController) AreaDelete() { + uid := c.GetString("uid") + + se := new(service.AreaService) + resp := se.DeleteArea(uid) + c.Data["json"] = resp + + _ = c.ServeJSON() +} + +func (c *AreaController) AreaGet() { + uid := c.GetString("uid") + + se := new(service.AreaService) + resp := se.GetArea(uid) + + c.Data["json"] = resp + _ = c.ServeJSON() +} diff --git a/legend/controllers/showPageController.go b/legend/controllers/showPageController.go index 1e38e5c..6a7c3d3 100644 --- a/legend/controllers/showPageController.go +++ b/legend/controllers/showPageController.go @@ -92,6 +92,12 @@ func (c *ShowPageController) AreaListPage() { c.TplName = "area-list.html" } +func (c *ShowPageController) AreaEdit() { + uid := c.GetString("uid") + c.Data["uid"] = uid + c.TplName = "area-edit.html" +} + /** ** 充值订单 */ diff --git a/legend/models/init.go b/legend/models/init.go index 4047e6f..c966edf 100644 --- a/legend/models/init.go +++ b/legend/models/init.go @@ -55,6 +55,7 @@ func initLegend() { orm.RegisterModel(new(legend.ScalePresent)) orm.RegisterModel(new(legend.ScaleTemplate)) orm.RegisterModel(new(legend.Group)) + orm.RegisterModel(new(legend.Area)) logs.Info("init legend success ......") diff --git a/legend/models/legend/legendAnyMoneyDao.go b/legend/models/legend/legendAnyMoneyDao.go index 68de7a1..06e1943 100644 --- a/legend/models/legend/legendAnyMoneyDao.go +++ b/legend/models/legend/legendAnyMoneyDao.go @@ -11,8 +11,7 @@ type AnyMoney struct { GameMoneyName string GameMoneyScale int LimitLow float64 - UpdateTime string - CreateTime string + BaseDao } const ANYMONEY = "legend_any_money" diff --git a/legend/models/legend/legendAreaDao.go b/legend/models/legend/legendAreaDao.go new file mode 100644 index 0000000..8c684fa --- /dev/null +++ b/legend/models/legend/legendAreaDao.go @@ -0,0 +1,92 @@ +package legend + +import ( + "github.com/beego/beego/v2/client/orm" + "github.com/beego/beego/v2/core/logs" +) + +type Area struct { + Id int `orm:"pk;column(id)"` + AreaName string + Uid string + GroupName string + TemplateName string + NotifyUrl string + AttachParams string + BaseDao +} + +const AREA = "legend_area" + +func (c *Area) TableName() string { + return AREA +} + +func InsertArea(area *Area) bool { + o := orm.NewOrm() + if _, err := o.Insert(area); err != nil { + logs.Error("insert area err: ", err) + return false + } + return true +} + +func GetAreaByName(name string) *Area { + o := orm.NewOrm() + area := new(Area) + if _, err := o.QueryTable(AREA).Filter("area_name", name).Limit(1).All(area); err != nil { + logs.Error("get area by name err:", err) + } + + return area +} + +func GetAreaAllCount() int { + o := orm.NewOrm() + count, err := o.QueryTable(AREA).Count() + if err != nil { + logs.Error("get area all count err:", err) + } + + return int(count) +} + +func GetAreaList(offset, limit int) []Area { + o := orm.NewOrm() + var areas []Area + if _, err := o.QueryTable(AREA).Limit(limit, offset).OrderBy("-create_time").All(&areas); err != nil { + logs.Error(" get area list err:", err) + } + + return areas +} + +func GetAreaByUid(uid string) *Area { + o := orm.NewOrm() + area := new(Area) + if _, err := o.QueryTable(AREA).Filter("uid", uid).Limit(1).All(area); err != nil { + logs.Error(" get area by uid err : ", err) + } + + return area +} + +func UpdateArea(area *Area) bool { + o := orm.NewOrm() + if _, err := o.Update(area); err != nil { + logs.Error("update area err:", err) + return false + } + + return true +} + +func DeleteAreaByUid(uid string) bool { + o := orm.NewOrm() + if _, err := o.QueryTable(AREA).Filter("uid", uid).Delete(); err != nil { + logs.Error(" delete area by uid err:", err) + return false + } + + return true +} diff --git a/legend/models/legend/legendBaseDao.go b/legend/models/legend/legendBaseDao.go new file mode 100644 index 0000000..7a72f65 --- /dev/null +++ b/legend/models/legend/legendBaseDao.go @@ -0,0 +1,6 @@ +package legend + +type BaseDao struct { + UpdateTime string + CreateTime string +} diff --git a/legend/models/legend/legendFixMoneyDao.go b/legend/models/legend/legendFixMoneyDao.go index c1e3544..2e7d313 100644 --- a/legend/models/legend/legendFixMoneyDao.go +++ b/legend/models/legend/legendFixMoneyDao.go @@ -13,8 +13,7 @@ type FixMoney struct { GoodsName string GoodsNo string BuyTimes int - UpdateTime string - CreateTime string + BaseDao } const FIXMONEY = "legend_fix_money" diff --git a/legend/models/legend/legendFixPresentDao.go b/legend/models/legend/legendFixPresentDao.go index 9ce5237..dbfa4ce 100644 --- a/legend/models/legend/legendFixPresentDao.go +++ b/legend/models/legend/legendFixPresentDao.go @@ -11,8 +11,7 @@ type FixPresent struct { TemplateName string Money float64 PresentMoney float64 - UpdateTime string - CreateTime string + BaseDao } const FIXPRESENT = "legend_fix_present" diff --git a/legend/models/legend/legendGroupDao.go b/legend/models/legend/legendGroupDao.go index 27f2637..0dd69bd 100644 --- a/legend/models/legend/legendGroupDao.go +++ b/legend/models/legend/legendGroupDao.go @@ -6,11 +6,10 @@ import ( ) type Group struct { - Id int `orm:"pk;column(id)"` - GroupName string - Uid string - UpdateTime string - CreateTime string + Id int `orm:"pk;column(id)"` + GroupName string + Uid string + BaseDao } const GROUP = "legend_group" diff --git a/legend/models/legend/legendScalePresentDao.go b/legend/models/legend/legendScalePresentDao.go index 23b8dae..f4c79a7 100644 --- a/legend/models/legend/legendScalePresentDao.go +++ b/legend/models/legend/legendScalePresentDao.go @@ -11,8 +11,7 @@ type ScalePresent struct { TemplateName string Money float64 PresentScale float64 - UpdateTime string - CreateTime string + BaseDao } const SCALEPRESENT = "legend_scale_present" diff --git a/legend/models/legend/legendScaleTempleteDao.go b/legend/models/legend/legendScaleTempleteDao.go index b8e4cf8..2b944e3 100644 --- a/legend/models/legend/legendScaleTempleteDao.go +++ b/legend/models/legend/legendScaleTempleteDao.go @@ -13,8 +13,7 @@ type ScaleTemplate struct { UserWarn string MoneyType string PresentType string - UpdateTime string - CreateTime string + BaseDao } const SCALETMPLETE = "legend_scale_template" diff --git a/legend/request/areaReq.go b/legend/request/areaReq.go new file mode 100644 index 0000000..32f038a --- /dev/null +++ b/legend/request/areaReq.go @@ -0,0 +1,9 @@ +package request + +type AreaReq struct { + AreaName string + GroupName string + TemplateName string + NotifyUrl string + AttachParams string +} diff --git a/legend/request/templateReq.go b/legend/request/templateReq.go new file mode 100644 index 0000000..5a9b162 --- /dev/null +++ b/legend/request/templateReq.go @@ -0,0 +1,23 @@ +package request + +type AddTemplateReq struct { + ScaleTemplateName string `form:"scaleTemplateName"` + ScaleUserName string `form:"scaleUserName"` + ScaleUserNamePoint string `form:"scaleUserNamePoint"` + MoneyType string `form:"moneyType"` + GameMoneyName string `form:"gameMoneyName"` + GameMoneyScale int `form:"gameMoneyScale"` + LimitLowMoney float64 `form:"limitLowMoney"` + PresentType string `form:"presentType"` + FixPrices []float64 `form:"fixPrices"` + GoodsNames []string `form:"goodsNames"` + GoodsNos []string `form:"goodsNos"` + Limits []int `form:"limits"` + PresentFixMoneys []float64 `form:"presentFixMoneys"` + PresentFixPresentMoneys []float64 `form:"presentFixPresentMoneys"` + PresentScaleMoneys []float64 `form:"presentScaleMoneys"` + PresentScales []float64 `form:"presentScales"` + FixUids []string `form:"fixUids"` + PresentScaleUids []string `form:"presentScaleUids"` + PresentFixUids []string `form:"presentFixUids"` +} diff --git a/legend/response/areaResp.go b/legend/response/areaResp.go new file mode 100644 index 0000000..aefa301 --- /dev/null +++ b/legend/response/areaResp.go @@ -0,0 +1,16 @@ +package response + +import "legend/models/legend" + +type AreaListResp struct { + Code int `json:"code"` + Msg string `json:"msg"` + Count int `json:"count"` + Data []legend.Area `json:"data"` +} + +type AreaInfoResp struct { + Code int + Msg string + Area *legend.Area +} diff --git a/legend/routers/router.go b/legend/routers/router.go index ea5025b..29632fe 100644 --- a/legend/routers/router.go +++ b/legend/routers/router.go @@ -35,6 +35,7 @@ func pageInit() { web.Router("/areaChargeCount.html", &controllers.ShowPageController{}, "*:AreaChargePage") web.Router("/person.html", &controllers.ShowPageController{}, "*:PersonPage") web.Router("areaAddOrEdit.html", &controllers.ShowPageController{}, "*:AreaAddOrEdit") + web.Router("/areaEdit.html", &controllers.ShowPageController{}, "*:AreaEdit") } /** @@ -53,5 +54,11 @@ func logicInit() { web.Router("/add/group", &controllers.GroupController{}, "*:AddGroup") web.Router("/delete/group", &controllers.GroupController{}, "*:DeleteGroup") web.Router("/edit/group", &controllers.GroupController{}, "*:EditGroup") + web.Router("/add/area", &controllers.AreaController{}, "*:AreaAdd") + web.Router("/area/list", &controllers.AreaController{}, "*:AreaList") + web.Router("/delete/area", &controllers.AreaController{}, "*:AreaDelete") + web.Router("/get/area", &controllers.AreaController{}, "*:AreaGet") + web.Router("/edit/area", &controllers.AreaController{}, "*:AreaEdit") + web.InsertFilter("/*", web.BeforeRouter, filter.LoginFilter) } diff --git a/legend/service/areaService.go b/legend/service/areaService.go new file mode 100644 index 0000000..3e5d015 --- /dev/null +++ b/legend/service/areaService.go @@ -0,0 +1,98 @@ +package service + +import ( + "github.com/rs/xid" + "legend/models/legend" + "legend/request" + "legend/response" + "legend/utils" +) + +type AreaService struct { + BaseService +} + +func (c *AreaService) AddArea(req *request.AreaReq) *response.BaseResp { + resp := new(response.BaseResp) + + area := new(legend.Area) + area.AreaName = req.AreaName + area.GroupName = req.GroupName + area.TemplateName = req.TemplateName + area.NotifyUrl = req.NotifyUrl + area.AttachParams = req.AttachParams + area.UpdateTime = utils.GetNowTime() + area.CreateTime = utils.GetNowTime() + area.Uid = xid.New().String() + + if legend.InsertArea(area) { + resp.Code = 0 + } else { + resp.Code = -1 + resp.Msg = "添加分区失败" + } + + return resp +} + +func (c *AreaService) AreaList(page, limit int) *response.AreaListResp { + offset := utils.CountOffset(page, limit) + count := legend.GetAreaAllCount() + areas := legend.GetAreaList(offset, limit) + + for i, _ := range areas { + areas[i].Id = offset + i + 1 + } + + areaResp := new(response.AreaListResp) + areaResp.Code = 0 + areaResp.Count = count + areaResp.Data = areas + + return areaResp +} + +func (c *AreaService) DeleteArea(uid string) *response.BaseResp { + resp := new(response.BaseResp) + + if legend.DeleteAreaByUid(uid) { + resp.Code = 0 + } else { + resp.Code = -1 + resp.Msg = "删除分区失败" + } + return resp +} + +func (c *AreaService) GetArea(uid string) *response.AreaInfoResp { + resp := new(response.AreaInfoResp) + resp.Code = 0 + resp.Msg = "请求成功" + + area := legend.GetAreaByUid(uid) + resp.Area = area + + return resp +} + +func (c *AreaService) EditArea(req *request.AreaReq, uid string) *response.BaseResp { + resp := new(response.BaseResp) + resp.Code = -1 + + area := legend.GetAreaByUid(uid) + if area == nil || area.AreaName == "" { + resp.Msg = "更新失败" + } else { + area.UpdateTime = utils.GetNowTime() + area.GroupName = req.GroupName + area.TemplateName = req.TemplateName + area.NotifyUrl = req.NotifyUrl + area.AttachParams = req.AttachParams + + if legend.UpdateArea(area) { + resp.Msg = "更新失败" + } + } + + return resp +} diff --git a/legend/views/area-add.html b/legend/views/area-add.html index 7f79d82..3331fe2 100644 --- a/legend/views/area-add.html +++ b/legend/views/area-add.html @@ -6,7 +6,7 @@
diff --git a/legend/views/area-charge-count.html b/legend/views/area-charge-count.html index 2a30544..114c329 100644 --- a/legend/views/area-charge-count.html +++ b/legend/views/area-charge-count.html @@ -6,7 +6,7 @@
- +{{/* */}} diff --git a/legend/views/area-edit.html b/legend/views/area-edit.html new file mode 100644 index 0000000..a1fac5c --- /dev/null +++ b/legend/views/area-edit.html @@ -0,0 +1,166 @@ + + + +
+ +
+ + + {{/* */}} + + + + + + + + + + + + +
+ +