@@ -0,0 +1,248 @@
|
||||
package productctrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/productbenefitmod"
|
||||
"91porn-server/models/v/productmod"
|
||||
"91porn-server/models/v/productposimod"
|
||||
"91porn-server/web/webg"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// FindVipList doc
|
||||
// @Summary product种类
|
||||
// @Description 所有可购买的product种类
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /product/productTypeList [get]
|
||||
func FindVipList(ctx *gin.Context) {
|
||||
req := productmod.ProductListWeb{}
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
data, err := productmod.FindStd(req)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
positionM, _, _, err := productposimod.FindNamesWithStatusTrue()
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
|
||||
return
|
||||
}
|
||||
for i := range data {
|
||||
data[i].Position = positionM[data[i].Position]
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, data)
|
||||
}
|
||||
|
||||
// Insert doc
|
||||
// @Summary 新增
|
||||
// @Description 新增
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param q body productmod.Product false "请求参数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /product/productType [post]
|
||||
func Insert(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
v := productmod.Product{}
|
||||
if err = ctx.ShouldBind(&v); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
//默认为vip商品
|
||||
if v.ProductType == 0 {
|
||||
v.ProductType = productmod.VIP
|
||||
}
|
||||
m, _, _, err := productposimod.FindNamesWithStatusTrue()
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
for k := range m {
|
||||
if m[k] == v.Position {
|
||||
v.Position = k
|
||||
break
|
||||
}
|
||||
}
|
||||
//组装商品权益信息
|
||||
if len(v.Privilege) > 0 {
|
||||
//查询商品权益配置
|
||||
data, err := productbenefitmod.FindProductBenefitByPrivilege(&v.Privilege)
|
||||
if err != nil {
|
||||
log.Fatal("Insert productBenefitmod.FindProductBenefitByPrivilege err", log.E(err), log.Any("privilege", v.Privilege))
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
if dataLen := len(data); dataLen > 0 {
|
||||
v.NewPrivilege = make([]productmod.PrivilegeInfo, dataLen)
|
||||
for i, vv := range data {
|
||||
v.NewPrivilege[i] = productmod.PrivilegeInfo{
|
||||
Image: vv.Img,
|
||||
Name: vv.PrivilegeName,
|
||||
Desc: vv.PrivilegeDesc,
|
||||
IsCore: vv.IsCore,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = productmod.InsertProduct(&v); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.DataCachKey(productmod.RedisSetKey, "FindProductByType")
|
||||
_, _ = webg.Redis.Del(redisKey)
|
||||
log, _ := json.Marshal(v)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageVIP, constant.Add, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
// Update doc
|
||||
// @Summary 修改producttype
|
||||
// @Description 修改producttype
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param id formData string true "id"
|
||||
// @Param q body productmod.ProductSelector false "请求参数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /product/productType [put]
|
||||
func Update(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
ID string `json:"id" form:"id" bson:"id"`
|
||||
productmod.ProductSelector
|
||||
}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if p.Position != nil {
|
||||
m, _, _, err := productposimod.FindNamesWithStatusTrue()
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
v := *p.Position
|
||||
for k := range m {
|
||||
if m[k] == v {
|
||||
kv := k
|
||||
p.Position = &kv
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
//组装商品权益信息
|
||||
if p.ProductSelector.Privilege != nil {
|
||||
//查询商品权益配置
|
||||
data, err := productbenefitmod.FindProductBenefitByPrivilege(p.ProductSelector.Privilege)
|
||||
if err != nil {
|
||||
log.Fatal("productBenefitmod.FindProductBenefitByPrivilege err", log.E(err), log.Any("privilege", p.ProductSelector.Privilege))
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
//清空NewPrivilege里面的数据
|
||||
if err = productmod.UpdateProductRights(p.ID); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
|
||||
return
|
||||
}
|
||||
if dataLen := len(data); dataLen > 0 {
|
||||
p.ProductSelector.NewPrivilege = make([]*productmod.PrivilegeInfo, dataLen)
|
||||
for i, v := range data {
|
||||
p.ProductSelector.NewPrivilege[i] = &productmod.PrivilegeInfo{
|
||||
Image: v.Img,
|
||||
Name: v.PrivilegeName,
|
||||
Desc: v.PrivilegeDesc,
|
||||
IsCore: v.IsCore,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = productmod.UpdateProduct(p.ID, &p.ProductSelector); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.DataCachKey(productmod.RedisSetKey, "FindProductByType")
|
||||
_, _ = webg.Redis.Del(redisKey)
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageVIP, constant.Modify, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
// Delete doc
|
||||
// @Summary 删除
|
||||
// @Description 删除
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param id formData int true "product等级""
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /product/productType [Delete]
|
||||
func Delete(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
ID string `json:"id" form:"id"`
|
||||
}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
if err = productmod.RemoveProduct(p.ID); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbDeleteError, "")
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.DataCachKey(productmod.RedisSetKey, "FindProductByType")
|
||||
_, _ = webg.Redis.Del(redisKey)
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageVIP, constant.Delete, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
func CheckboxList(c *gin.Context) {
|
||||
var (
|
||||
in productmod.CheckboxListCond
|
||||
data = map[string]interface{}{
|
||||
"data": []interface{}{},
|
||||
}
|
||||
)
|
||||
if err := c.ShouldBindQuery(&in); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
list, err := productmod.CheckboxByType(in.ProductType)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbQueryError, err)
|
||||
return
|
||||
}
|
||||
data["data"] = list
|
||||
common.ServeJSON(c, stderr.Success, data)
|
||||
}
|
||||
Reference in New Issue
Block a user