|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- package hdl
-
- import (
- "applet/app/admin/enum"
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- "applet/app/admin/svc"
- svc2 "applet/app/admin/svc/category"
- "applet/app/admin/svc/goods"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func SchemeList(c *gin.Context) {
- schemeDb := db.SchemeDb{}
- schemeDb.Set()
- schemeList, err := schemeDb.FindScheme()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- schemeEnterpriseDb := db.SchemeEnterpriseDb{}
- schemeEnterpriseDb.Set()
- enterpriseDb := db.EnterpriseDb{}
- enterpriseDb.Set()
- var result []*md.SchemeListResp
- for _, v := range *schemeList {
- var temp md.SchemeListResp
- temp.Data = v
- schemeWithEnterprises, err1 := schemeEnterpriseDb.FindSchemeEnterprise(v.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- for _, schemeWithEnterprise := range *schemeWithEnterprises {
- enterprise, err2 := enterpriseDb.GetEnterprise(schemeWithEnterprise.EnterpriseId)
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- temp.EnterpriseList = append(temp.EnterpriseList, struct {
- Id int `json:"id"`
- Name string `json:"name"`
- }{
- Id: enterprise.Id,
- Name: enterprise.Name,
- })
- }
- result = append(result, &temp)
- }
- e.OutSuc(c, map[string]interface{}{
- "list": result,
- "state": []map[string]interface{}{
- {
- "name": enum.SchemeState(enum.SchemeStateForNormal).String(),
- "value": enum.SchemeStateForNormal,
- },
- {
- "name": enum.SchemeState(enum.SchemeStateForFreeze).String(),
- "value": enum.SchemeStateForFreeze,
- },
- },
- }, nil)
- return
- }
-
- func AddScheme(c *gin.Context) {
- var req md.AddSchemeReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- schemeDb := db.SchemeDb{}
- schemeDb.Set()
- now := time.Now()
- _, err = schemeDb.SchemeInsert(&model.Scheme{
- Name: req.Name,
- State: enum.SchemeStateForNormal,
- Memo: req.Memo,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func UpdateScheme(c *gin.Context) {
- var req md.UpdateSchemeReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- schemeDb := db.SchemeDb{}
- schemeDb.Set()
- scheme, err := schemeDb.GetScheme(req.Id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if scheme == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- scheme.Name = req.Name
- scheme.Memo = req.Memo
- _, err = schemeDb.UpdateScheme(scheme, "name", "memo")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- func SchemeBindEnterprise(c *gin.Context) {
- var req md.SchemeBindEnterpriseReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err = svc.SchemeBindEnterprise(req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func UpdateSchemeState(c *gin.Context) {
- var req md.UpdateSchemeStateReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- schemeDb := db.SchemeDb{}
- schemeDb.Set()
- scheme, err := schemeDb.GetScheme(req.Id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if scheme == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- scheme.State = req.State
- _, err = schemeDb.UpdateScheme(scheme, "state")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- func DeleteScheme(c *gin.Context) {
- id := c.Param("id")
- schemeDb := db.SchemeDb{}
- schemeDb.Set()
- scheme, err := schemeDb.GetScheme(utils.StrToInt(id))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if scheme == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
-
- err = svc.DeleteScheme(utils.StrToInt(id))
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func SchemeGoodsDetail(c *gin.Context) {
- goodsId := c.Query("goods_id")
- if goodsId == "" {
- goodsId = "0"
- }
- schemeId := c.Query("scheme_id")
- if schemeId == "" {
- schemeId = "0"
- }
- resp, err := svc.MallGoodsDetailByScheme(c, utils.StrToInt64(goodsId), utils.StrToInt(schemeId))
- if err != nil {
- e.OutErr(c, 400, err.Error())
- return
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- func SaveSchemeGoods(c *gin.Context) {
- var req md.SaveSchemeGoodsReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- err = svc.SaveSchemeGoods(req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func GoodsList(c *gin.Context) {
- var args md.MallGoodsListReq
- args.Title = c.Query("title")
- args.CategoryId = c.Query("category_id")
- args.SaleState = c.Query("sale_state")
- args.PageId = c.Query("page")
- args.PageSize = c.Query("limit")
- args.SkuCode = c.Query("sku_code")
- tree, err := svc2.GetAllCategory(c)
- data, total, err := goods.GetMallGoodsList(c, &args)
- if err != nil {
- e.OutErr(c, e.ERR_NO_DATA, err)
- return
- }
- var returnData = map[string]interface{}{
- "total": total,
- "cateList": tree,
- // "dataList": data,
- //-1审核拒绝 0审核中 1销售中 2已售罄 3放入仓库 4下架
- "stateList": []map[string]interface{}{
- {"name": "全部", "value": 99},
- {"name": "销售中", "value": 1},
- {"name": "已下架", "value": 2},
- },
- }
-
- if data == nil {
- returnData["dataList"] = []string{}
- } else {
- returnData["dataList"] = data
- }
-
- e.OutSuc(c, returnData, nil)
- return
- }
|