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.

122 lines
2.4 KiB

4 years ago
package special_sale
import (
mysql2 "git.oa00.com/go/mysql"
"github.com/gin-gonic/gin"
"recook/internal/back"
"recook/internal/libs/bean"
"recook/internal/v2/logic/manage/special_sale"
special_sale2 "recook/internal/v2/model/special_sale"
"recook/tools"
)
type SpecialSale struct {
}
/*控制层方法部门*/
//新增特卖图标
func (s SpecialSale) Add(c *gin.Context) {
var p special_sale.SpsRe
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
}
err := special_sale.Logic.Add(p)
if err != nil {
back.Fail(c, err.Error())
return
} else {
back.Suc(c, "添加成功", nil)
}
}
//查询显示特卖图标资料全显,或条件搜索
func (s SpecialSale) SearchAll(c *gin.Context) {
var p special_sale.SpecRequest
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
rest, total := special_sale.Logic.Search(p)
back.Suc(c, "ok", bean.ResultLists{
List: rest,
Total: int(total),
})
return
}
type viewOne struct {
Id uint `json:"id"`
}
//显示单个详情
func (s SpecialSale) ViewDetail(c *gin.Context) {
var p viewOne
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
rest := special_sale.Logic.ViewOneDetail(p.Id)
back.Suc(c, "ok", rest)
}
//删除
func (s SpecialSale) DeleteOne(c *gin.Context) {
var p viewOne
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
err := special_sale.Logic.Delete(p.Id)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "ok", nil)
}
type goodsId struct {
GoodsId uint `json:"goods_id"`
SpecId uint `json:"spec_id"`
}
//删除关联表相关记录
func (s SpecialSale) DeleteAssociation(c *gin.Context) {
var g goodsId
if err := tools.Params(&g, c); err != nil {
back.Fail(c, err.Error())
return
}
var spa special_sale2.SpecialSaleAssociationModel
err := mysql2.Db.Table(spa.TableName()).Where("goods_id=? and special_sale_id=?", g.GoodsId, g.SpecId).Delete(spa).Error
if err != nil {
back.Fail(c, err.Error())
return
} else {
back.Suc(c, "ok", nil)
}
}
//新增筛选
func (s SpecialSale) AddNewGoods(c *gin.Context) {
var p special_sale.AccSelect
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
rest, total, err := special_sale.Logic.SearchGoods(p)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "ok", bean.ResultLists{
List: rest,
Total: int(total),
})
}