|
|
package gys
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
mysql2 "git.oa00.com/go/mysql"
|
|
|
"recook/internal/libs/bean"
|
|
|
"recook/internal/v2/lib/back"
|
|
|
"recook/internal/v2/lib/common"
|
|
|
"recook/internal/v2/logic/manage/gys"
|
|
|
"recook/internal/v2/model/gys/enterprise"
|
|
|
"recook/internal/v2/model/recook/goods"
|
|
|
"recook/tools"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/golangkit/formatime"
|
|
|
"github.com/jinzhu/gorm"
|
|
|
)
|
|
|
|
|
|
type Brand struct {
|
|
|
}
|
|
|
|
|
|
type argsLists struct {
|
|
|
State uint `json:"state" form:"state"`
|
|
|
BrandName string `json:"brandName" form:"brandName"`
|
|
|
EnterpriseName string `json:"enterpriseName" form:"enterpriseName"`
|
|
|
bean.Page
|
|
|
}
|
|
|
|
|
|
type replyState struct {
|
|
|
BrandId uint `json:"brandId"`
|
|
|
EnterpriseName string `json:"enterpriseName"`
|
|
|
BrandName string `json:"brandName"`
|
|
|
ApplyTime int64 `json:"applyTime"`
|
|
|
AdminId uint `json:"admin_id"`
|
|
|
AdminDate formatime.Second `json:"admin_date"`
|
|
|
AdminUser string `json:"admin_user"`
|
|
|
}
|
|
|
|
|
|
// @Style 品牌列表
|
|
|
func (b *Brand) Lists(c *gin.Context) {
|
|
|
args := argsLists{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.State <= 0 {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
total, lists := gys.BrandLogic.Lists(args.State, args.BrandName, args.EnterpriseName, args.Page)
|
|
|
var enterpriseIds []uint
|
|
|
for _, list := range lists {
|
|
|
enterpriseIds = append(enterpriseIds, list.EnterpriseID)
|
|
|
}
|
|
|
enterpriseMap := map[uint]enterprise.GysEnterpriseStateModel{}
|
|
|
if len(enterpriseIds) > 0 {
|
|
|
enterpriseStates := (&enterprise.GysEnterpriseStateModel{}).FindByIds(enterpriseIds)
|
|
|
for _, state := range enterpriseStates {
|
|
|
enterpriseMap[state.Id] = state
|
|
|
}
|
|
|
}
|
|
|
var result []replyState
|
|
|
for _, list := range lists {
|
|
|
result = append(result, replyState{
|
|
|
BrandId: list.Id,
|
|
|
BrandName: list.Name,
|
|
|
EnterpriseName: enterpriseMap[list.EnterpriseID].EnterpriseName,
|
|
|
ApplyTime: list.ApplyTime.Time.Unix(),
|
|
|
AdminId: list.AdminID,
|
|
|
AdminUser: list.AdminUser,
|
|
|
AdminDate: list.AdminDate,
|
|
|
})
|
|
|
}
|
|
|
back.Suc(c, "操作成功", bean.ResultLists{
|
|
|
List: result,
|
|
|
Total: total,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type argsInfo struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
}
|
|
|
|
|
|
type replyInfo struct {
|
|
|
BrandId uint `json:"brandId"`
|
|
|
BrandName string `json:"brandName"`
|
|
|
Type int `json:"type"`
|
|
|
Logo string `json:"logo"`
|
|
|
QualificationUrls []gys.UrlData `json:"qualificationUrls"`
|
|
|
AuthorizeUrls []gys.UrlData `json:"authorizeUrls"`
|
|
|
OtherUrls []gys.UrlData `json:"otherUrls"`
|
|
|
StateInfo string `json:"stateInfo"`
|
|
|
EndTime int64 `json:"endTime"`
|
|
|
Categories []replyBrandCategory `json:"categorys"`
|
|
|
State int `json:"state"`
|
|
|
EnterpriseName string `json:"enterpriseName"`
|
|
|
}
|
|
|
|
|
|
type replyBrandCategory struct {
|
|
|
CategoryId uint `json:"categoryId"`
|
|
|
CategoryName string `json:"categoryName"`
|
|
|
}
|
|
|
|
|
|
func (b *Brand) Info(c *gin.Context) {
|
|
|
args := argsInfo{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
brandInfo := (&enterprise.GysEnterpriseBrandModel{}).FindById(args.BrandId)
|
|
|
if brandInfo.Id <= 0 {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
brandImages := (&enterprise.GysEnterpriseImgModel{}).GetByBrandId(brandInfo.Id)
|
|
|
|
|
|
var qualificationUrls []gys.UrlData
|
|
|
var authorizeUrls []gys.UrlData
|
|
|
var otherUrls []gys.UrlData
|
|
|
for _, img := range brandImages {
|
|
|
ud := gys.UrlData{Url: img.Url, Start: img.Start, End: img.End}
|
|
|
switch img.Type {
|
|
|
case enterprise.GysEnterpriseImgTypeReg:
|
|
|
qualificationUrls = append(qualificationUrls, ud)
|
|
|
case enterprise.GysEnterpriseImgTypeAuth:
|
|
|
qualificationUrls = append(qualificationUrls, ud)
|
|
|
case enterprise.GysEnterpriseImgTypeOther:
|
|
|
otherUrls = append(otherUrls, ud)
|
|
|
case enterprise.GysEnterpriseImgTypeRecook:
|
|
|
authorizeUrls = append(authorizeUrls, ud)
|
|
|
}
|
|
|
}
|
|
|
var categories []replyBrandCategory
|
|
|
if brandInfo.State == enterprise.GysEnterpriseBrandStateSuc {
|
|
|
brandCategories := (&enterprise.GysEnterpriseBrandCategoryModel{}).GetByBrandId(brandInfo.Id)
|
|
|
var categoryIds []uint
|
|
|
for _, category := range brandCategories {
|
|
|
categoryIds = append(categoryIds, category.CategoryId)
|
|
|
}
|
|
|
goodsCategories := (&goods.RecookGoodsCategoryModel{}).GetByIds(categoryIds)
|
|
|
for _, category := range goodsCategories {
|
|
|
categories = append(categories, replyBrandCategory{
|
|
|
CategoryId: category.Id,
|
|
|
CategoryName: category.Name,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
state := brandInfo.State
|
|
|
if brandInfo.State == 2 {
|
|
|
if brandInfo.EndTime.Time.Unix() <= time.Now().Unix() {
|
|
|
state = 5
|
|
|
}
|
|
|
}
|
|
|
|
|
|
gysEnterpriseStateModel := &enterprise.GysEnterpriseStateModel{}
|
|
|
enterpriseInfo := gysEnterpriseStateModel.FindById(brandInfo.EnterpriseID)
|
|
|
back.Suc(c, "操作成功", replyInfo{
|
|
|
BrandId: brandInfo.Id,
|
|
|
BrandName: brandInfo.Name,
|
|
|
Type: brandInfo.Type,
|
|
|
Logo: brandInfo.Logo,
|
|
|
State: state,
|
|
|
StateInfo: brandInfo.StateInfo,
|
|
|
QualificationUrls: qualificationUrls,
|
|
|
AuthorizeUrls: authorizeUrls,
|
|
|
OtherUrls: otherUrls,
|
|
|
EndTime: brandInfo.EndTime.Time.Unix(),
|
|
|
Categories: categories,
|
|
|
EnterpriseName: enterpriseInfo.EnterpriseName,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type argsUpdate struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
BrandName string `json:"brandName" form:"brandName"`
|
|
|
Logo string `json:"logo" form:"logo"`
|
|
|
}
|
|
|
|
|
|
// @Style 更新品牌信息
|
|
|
func (b *Brand) Update(c *gin.Context) {
|
|
|
args := argsUpdate{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 || args.BrandName == "" || args.Logo == "" {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
row := (&enterprise.GysEnterpriseBrandModel{}).UpdateById(args.BrandId, enterprise.GysEnterpriseBrandModel{
|
|
|
Name: args.BrandName,
|
|
|
Logo: args.Logo,
|
|
|
})
|
|
|
if row <= 0 {
|
|
|
back.Fail(c, "网络异常")
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
type argsUpdateEndDate struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
EndDate string `json:"endDate" form:"endDate"`
|
|
|
}
|
|
|
|
|
|
// @Style 更新品牌有效期
|
|
|
func (b *Brand) UpdateEndDate(c *gin.Context) {
|
|
|
args := argsUpdateEndDate{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 || args.EndDate == "" {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
endTime, _ := time.ParseInLocation("2006-01-02", args.EndDate, time.Local)
|
|
|
row := (&enterprise.GysEnterpriseBrandModel{}).UpdateById(args.BrandId, enterprise.GysEnterpriseBrandModel{
|
|
|
EndTime: formatime.NewSecondFrom(endTime),
|
|
|
})
|
|
|
if row <= 0 {
|
|
|
back.Fail(c, "网络异常")
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
type argsUpdateCategory struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
CategoryIds []uint `json:"categoryIds" form:"categoryIds"`
|
|
|
}
|
|
|
|
|
|
// @Style 更新品牌类目
|
|
|
func (b *Brand) UpdateCategory(c *gin.Context) {
|
|
|
args := argsUpdateCategory{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 || len(args.CategoryIds) <= 0 {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
var data []enterprise.GysEnterpriseBrandCategoryModel
|
|
|
for _, categoryId := range args.CategoryIds {
|
|
|
data = append(data, enterprise.GysEnterpriseBrandCategoryModel{
|
|
|
BrandId: args.BrandId,
|
|
|
CategoryId: categoryId,
|
|
|
})
|
|
|
}
|
|
|
gysEnterpriseBrandCategoryModel := &enterprise.GysEnterpriseBrandCategoryModel{}
|
|
|
if err := gysEnterpriseBrandCategoryModel.Transaction(func(tx *gorm.DB) error {
|
|
|
gysEnterpriseBrandCategoryModel.SetDb(tx)
|
|
|
if err := gysEnterpriseBrandCategoryModel.DeleteByBrandId(args.BrandId); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
row := gysEnterpriseBrandCategoryModel.CreateAll(&data)
|
|
|
if row <= 0 {
|
|
|
return errors.New("网络异常")
|
|
|
}
|
|
|
return nil
|
|
|
}); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
type argsReject struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
RejectInfo string `json:"rejectInfo" form:"rejectInfo"`
|
|
|
}
|
|
|
|
|
|
// @Style 驳回
|
|
|
func (b *Brand) Reject(c *gin.Context) {
|
|
|
args := argsReject{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 || args.RejectInfo == "" {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
if err := gys.BrandLogic.Reject(user, args.BrandId, args.RejectInfo); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
// @Style 补全资料
|
|
|
func (b *Brand) Replenish(c *gin.Context) {
|
|
|
args := argsReject{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if args.BrandId <= 0 || args.RejectInfo == "" {
|
|
|
back.Fail(c, "参数错误")
|
|
|
return
|
|
|
}
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
if err := gys.BrandLogic.Replenish(user, args.BrandId, args.RejectInfo); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
type argsAllow struct {
|
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
|
CategoryIds []uint `json:"categoryIds" form:"categoryIds"`
|
|
|
MainBrandId uint `json:"mainBrandId" form:"mainBrandId"`
|
|
|
MainBrandName string `json:"mainBrandName" form:"mainBrandName"`
|
|
|
MainBrandLogo string `json:"mainBrandLogo" form:"mainBrandLogo"`
|
|
|
}
|
|
|
|
|
|
// @Style 审核通过
|
|
|
func (b *Brand) Allow(c *gin.Context) {
|
|
|
args := argsAllow{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
admin, _ := common.GetManageUser(c)
|
|
|
if err := gys.BrandLogic.Allow(args.BrandId, args.CategoryIds,
|
|
|
args.MainBrandId, args.MainBrandName, args.MainBrandLogo, admin.Id, admin.Name); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ExpirationList(c *gin.Context) {
|
|
|
args := gys.BrandListBaseReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
result, total := gys.GLogic.ExpirationList(&args)
|
|
|
|
|
|
back.Suc(c, "操作成功", bean.ResultLists{
|
|
|
List: result,
|
|
|
Total: total,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ExpirationDetail(c *gin.Context) {
|
|
|
args := gys.BrandDetailReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if result, err := gys.GLogic.ExpirationDetail(&args); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
} else {
|
|
|
back.Suc(c, "操作成功", result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationList(c *gin.Context) {
|
|
|
args := gys.BrandListBaseReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
result, total := gys.GLogic.ModificationList(&args)
|
|
|
|
|
|
back.Suc(c, "操作成功", bean.ResultLists{
|
|
|
List: result,
|
|
|
Total: total,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationDetail(c *gin.Context) {
|
|
|
args := gys.BrandDetailReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if result, err := gys.GLogic.ModificationInfo(&args); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
} else {
|
|
|
back.Suc(c, "操作成功", result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationReject(c *gin.Context) {
|
|
|
args := gys.ModificationNotAllowReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
if err := gys.GLogic.ModificationNotAllow(&args, user, enterprise.GysEnterpriseBrandStateFail); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationReplenish(c *gin.Context) {
|
|
|
args := gys.ModificationNotAllowReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
if err := gys.GLogic.ModificationNotAllow(&args, user, enterprise.GysEnterpriseBrandStateData); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationAllow(c *gin.Context) {
|
|
|
args := gys.ModificationAllowReq{}
|
|
|
if err := tools.Params(&args, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
if err := gys.GLogic.ModificationAllow(&args, user); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "操作成功", "")
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ModificationCount(c *gin.Context) {
|
|
|
if result, err := gys.GLogic.ModificationCount(); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
} else {
|
|
|
back.Suc(c, "操作成功", result)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
type listNum struct {
|
|
|
NeedToAuditNum int64 `json:"need_to_audit_num"`
|
|
|
AuditingNum int64 `json:"auditing_num"`
|
|
|
AuditFailNum int64 `json:"audit_fail_num"`
|
|
|
NeedUpNum int64 `json:"need_up_num"`
|
|
|
}
|
|
|
|
|
|
func (b *Brand) ListsNum(c *gin.Context) {
|
|
|
var bd enterprise.GysEnterpriseBrandModel
|
|
|
//审核状态1,审核中2审核通过3驳回4修改审核
|
|
|
var needToAuditNum int64
|
|
|
mysql2.Db.Table(bd.TableName()).Where("type>0 and state =1").Count(&needToAuditNum)
|
|
|
var auditingNum int64
|
|
|
mysql2.Db.Table(bd.TableName()).Where("type>0 and state =2").Count(&auditingNum)
|
|
|
var auditFailNum int64
|
|
|
mysql2.Db.Table(bd.TableName()).Where("type>0 and state =3").Count(&auditFailNum)
|
|
|
var needUpNum int64
|
|
|
mysql2.Db.Table(bd.TableName()).Where("type>0 and state =4").Count(&needUpNum)
|
|
|
back.Suc(c, "", listNum{
|
|
|
NeedToAuditNum: needToAuditNum,
|
|
|
AuditingNum: auditingNum,
|
|
|
AuditFailNum: auditFailNum,
|
|
|
NeedUpNum: needUpNum,
|
|
|
})
|
|
|
}
|