123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- package http
- import (
- "encoding/json"
- "io/ioutil"
- "net/http"
- "go-common/app/admin/main/creative/model/task"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/http/blademaster/render"
- "go-common/library/xstr"
- )
- func taskList(c *bm.Context) {
- var err error
- v := new(struct {
- Type int8 `form:"type"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- res, err := svc.TaskList(v.Type)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(res, nil)
- }
- func taskPre(c *bm.Context) {
- c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
- "code": 0,
- "message": "0",
- "data": map[string]interface{}{
- "target": task.TargetMap,
- "root_type": task.TaskRootNameMap,
- "group_type": task.TaskGroupNameMap,
- },
- }))
- }
- func viewGroup(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svc.TaskGroup(v.ID)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(res, nil)
- }
- func addGroup(c *bm.Context) {
- var err error
- v := new(task.TaskGroup)
- if err = c.Bind(v); err != nil {
- log.Error("addGroup c.Bind v(%+v) error(%v)", v, err)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs != "" {
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil {
- log.Error("addGroup xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- id, err := svc.AddTaskGroup(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "添加任务组", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func editGroup(c *bm.Context) {
- var err error
- v := new(task.TaskGroup)
- if err = c.Bind(v); err != nil {
- log.Error("editGroup c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs != "" {
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil {
- log.Error("editGroup xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- id, err := svc.EditTaskGroup(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "编辑任务组", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func orderGroup(c *bm.Context) {
- var err error
- v := new(task.OrderTask)
- if err = c.Bind(v); err != nil {
- log.Error("orderGroup c.Bind v(%+v) error(%v)", v, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "移动任务组顺序", OID: v.ID, Content: v})
- c.JSON(nil, svc.OrderTaskGroup(v))
- }
- func upStateGroup(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id" validate:"required"`
- State int8 `form:"state"`
- })
- if err = c.Bind(v); err != nil {
- log.Error("upStateGroup c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "更新任务组状态", OID: v.ID, Content: v})
- c.JSON(nil, svc.UpStateGroup(v.ID, v.State))
- }
- func viewSubtask(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svc.Task(v.ID)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(res, nil)
- }
- func addSubtask(c *bm.Context) {
- var err error
- v := new(task.Task)
- if err = c.Bind(v); err != nil {
- log.Error("addSubtask c.Bind v(%+v) error(%v)", v, err)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs != "" {
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil {
- log.Error("addSubtask xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- id, err := svc.AddSubtask(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "添加子任务", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func editSubtask(c *bm.Context) {
- var err error
- v := new(task.Task)
- if err = c.Bind(v); err != nil {
- log.Error("editSubtask c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- log.Error("editSubtask v.ID(%d)", v.ID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs != "" {
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil {
- log.Error("addSubtask xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- id, err := svc.EditSubtask(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "编辑子任务", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func orderSubtask(c *bm.Context) {
- var err error
- v := new(task.OrderTask)
- if err = c.Bind(v); err != nil {
- log.Error("orderSubtask c.Bind v(%+v) error(%v)", v, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "移动子任务顺序", OID: v.ID, Content: v})
- c.JSON(nil, svc.OrderSubTask(v))
- }
- func upStateSubtask(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id" validate:"required"`
- State int8 `form:"state"`
- })
- if err = c.Bind(v); err != nil {
- log.Error("upStateSubtask c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "更新子任务状态", OID: v.ID, Content: v})
- c.JSON(nil, svc.UpStateSubTask(v.ID, v.State))
- }
- func transferSubtask(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id" validate:"required"`
- GroupID int64 `form:"group_id" validate:"required"`
- })
- if err = c.Bind(v); err != nil {
- log.Error("transferSubtask c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 || v.GroupID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "转移子任务到别的组", OID: v.ID, Content: v})
- c.JSON(nil, svc.TransferSubtask(v.ID, v.GroupID))
- }
- func rewardTree(c *bm.Context) {
- c.JSON(svc.RewardTree(), nil)
- }
- func viewReward(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- rd, err := svc.ViewReward(v.ID)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rd, nil)
- }
- func addReward(c *bm.Context) {
- var err error
- v := new(task.Reward)
- if err = c.Bind(v); err != nil {
- log.Error("addReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- id, err := svc.AddReward(v)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "添加奖励", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func editReward(c *bm.Context) {
- var err error
- v := new(task.Reward)
- if err = c.Bind(v); err != nil {
- log.Error("editReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- id, err := svc.EditReward(v)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "编辑奖励", OID: id, Content: v})
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func upStateReward(c *bm.Context) {
- var err error
- v := new(struct {
- ID int64 `form:"id" validate:"required"`
- State int8 `form:"state"`
- })
- if err = c.Bind(v); err != nil {
- log.Error("upStateReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "更新奖励状态", OID: v.ID, Content: v})
- c.JSON(nil, svc.UpStateReward(v.ID, v.State))
- }
- func listGiftReward(c *bm.Context) {
- res, err := svc.ListGiftReward()
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(res, nil)
- }
- func viewGiftReward(c *bm.Context) {
- var err error
- v := new(task.GiftReward)
- if err = c.Bind(v); err != nil {
- return
- }
- if v.RootType == 0 || v.TaskType == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svc.ViewGiftReward(v)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(res, nil)
- }
- func addGiftReward(c *bm.Context) {
- var err error
- v := new(task.GiftReward)
- if err = c.Bind(v); err != nil {
- log.Error("addGiftReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil || len(rewardsIDs) == 0 { //注意礼包配置,奖励必传
- log.Error("addGiftReward xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- rows, err := svc.AddGiftReward(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "添加礼包", OID: 0, Content: v})
- c.JSON(map[string]interface{}{
- "rows": rows,
- }, nil)
- }
- func editGiftReward(c *bm.Context) {
- var err error
- v := new(task.GiftReward)
- if err = c.Bind(v); err != nil {
- log.Error("editGiftReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.RootType == 0 || v.TaskType == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- var rewardsIDs []int64
- if v.RewardIDs == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if rewardsIDs, err = xstr.SplitInts(v.RewardIDs); err != nil || len(rewardsIDs) == 0 { //注意礼包配置,奖励必传
- log.Error("editGiftReward xstr.SplitInts task v.RewardIDs(%s) rewardsIDs(%+v)|error(%v)", v.RewardIDs, rewardsIDs, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- rows, err := svc.EditGiftReward(v, rewardsIDs)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "编辑礼包", OID: 0, Content: v})
- c.JSON(map[string]interface{}{
- "rows": rows,
- }, nil)
- }
- func upStateGiftReward(c *bm.Context) {
- var err error
- v := new(task.GiftReward)
- if err = c.Bind(v); err != nil {
- log.Error("upStateGiftReward c.Bind v(%+v) error(%v)", v, err)
- return
- }
- if v.RootType == 0 || v.TaskType == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- rows, err := svc.UpGiftReward(v)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "更新礼包状态", OID: 0, Content: v})
- c.JSON(map[string]interface{}{
- "rows": rows,
- }, nil)
- }
- func batchOnline(c *bm.Context) {
- var err error
- bs, err := ioutil.ReadAll(c.Request.Body)
- if err != nil {
- log.Error("batchOnline ioutil.ReadAll error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.Request.Body.Close()
- var v []*task.TaskGroup
- err = json.Unmarshal(bs, &v)
- if err != nil {
- log.Error("batchOnline json.Unmarshal v(%+v) error(%v)", v, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- err = svc.BatchOnline(v)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- uid, uname := getUIDName(c)
- svc.SendTaskLog(c, &task.LogParam{UID: uid, UName: uname, Action: "批量刷新上线", OID: 0, Content: v})
- c.JSON(nil, nil)
- }
|