You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.0 KiB
114 lines
3.0 KiB
4 years ago
|
package brand
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"recook/internal/libs/bean"
|
||
|
"recook/internal/v2/lib/back"
|
||
|
"recook/internal/v2/logic/manage/brand"
|
||
|
"recook/internal/v2/logic/manage/gys"
|
||
|
"recook/internal/v2/model/gys/enterprise"
|
||
|
"recook/tools"
|
||
|
)
|
||
|
|
||
|
type Brand struct {
|
||
|
}
|
||
|
type argsLists struct {
|
||
|
BrandName string `json:"brandName" form:"brandName"`
|
||
|
bean.Page
|
||
|
}
|
||
|
|
||
|
// @Style 品牌列表
|
||
|
func (b *Brand) Lists(c *gin.Context) {
|
||
|
args := argsLists{}
|
||
|
if err := tools.Params(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
lists, total := brand.BrandLogic.Lists(args.BrandName, args.Page)
|
||
|
back.Suc(c, "操作成功", bean.ResultLists{
|
||
|
List: lists,
|
||
|
Total: total,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
type argsUpdateLogo struct {
|
||
|
BrandId uint `json:"brandId" form:"brandId"`
|
||
|
Logo string `json:"logo" form:"logo"`
|
||
|
}
|
||
|
|
||
|
// @Style 更新logo
|
||
|
func (b *Brand) UpdateLogo(c *gin.Context) {
|
||
|
args := argsUpdateLogo{}
|
||
|
if err := tools.Params(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
if args.BrandId <= 0 || args.Logo == "" {
|
||
|
back.Fail(c, "参数错误")
|
||
|
}
|
||
|
|
||
|
if err := brand.BrandLogic.UpdateLogo(args.BrandId, args.Logo); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
back.Suc(c, "操作成功", "")
|
||
|
}
|
||
|
|
||
|
type argsGysBrand struct {
|
||
|
BrandId uint `json:"brandId" form:"brandId"`
|
||
|
CategoryId uint `json:"categoryId" form:"categoryId"`
|
||
|
EndTimeStart string `json:"endTimeStart" form:"endTimeStart"`
|
||
|
EndTimeEnd string `json:"endTimeEnd" form:"endTimeEnd"`
|
||
|
bean.Page
|
||
|
}
|
||
|
|
||
|
type replyGysBrand struct {
|
||
|
BrandId uint `json:"brandId"`
|
||
|
AdminDate int64 `json:"adminDate"`
|
||
|
Logo string `json:"logo"`
|
||
|
EndTime int64 `json:"endTime"`
|
||
|
CategoryIds string `json:"categoryIds"`
|
||
|
EnterpriseName string `json:"enterpriseName"`
|
||
|
}
|
||
|
|
||
|
// @Style 供应商关联品牌
|
||
|
func (b *Brand) GysBrand(c *gin.Context) {
|
||
|
args := argsGysBrand{}
|
||
|
if err := tools.Params(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
if args.BrandId <= 0 {
|
||
|
back.Fail(c, "参数错误")
|
||
|
return
|
||
|
}
|
||
|
total, lists := gys.BrandLogic.ListByMainId(args.BrandId, args.CategoryId, args.EndTimeStart, args.EndTimeEnd, args.Page)
|
||
|
enterpriseIds := []uint{}
|
||
|
for _, list := range lists {
|
||
|
enterpriseIds = append(enterpriseIds, list.EnterpriseID)
|
||
|
}
|
||
|
gysEnterpriseStateModel := &enterprise.GysEnterpriseStateModel{}
|
||
|
gysEnterpriseStateLists := gysEnterpriseStateModel.FindByIds(enterpriseIds)
|
||
|
gysEnterpriseStateMap := map[uint]enterprise.GysEnterpriseStateModel{}
|
||
|
for _, item := range gysEnterpriseStateLists {
|
||
|
gysEnterpriseStateMap[item.Id] = item
|
||
|
}
|
||
|
|
||
|
result := []replyGysBrand{}
|
||
|
for _, list := range lists {
|
||
|
result = append(result, replyGysBrand{
|
||
|
BrandId: list.Id,
|
||
|
Logo: list.Logo,
|
||
|
EndTime: list.EndTime.Time.Unix(),
|
||
|
CategoryIds: list.CategoryIds,
|
||
|
AdminDate: list.AdminDate.Time.Unix(),
|
||
|
EnterpriseName: gysEnterpriseStateMap[list.EnterpriseID].EnterpriseName,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
back.Suc(c, "操作成功", bean.ResultLists{
|
||
|
List: result,
|
||
|
Total: total,
|
||
|
})
|
||
|
}
|