package marketing

import(
	"spaceofcheng/services/controllers"
	"spaceofcheng/services/service/marketing"
	"spaceofcheng/services/models/model"
)


// CourseController 商品
type MarketingController struct {
	serv *marketing.MarketingServ
	controllers.BaseController
}

// Constructor 初始化 Controller
// @Title Constructor
// @Description 初始化 Controller, 系统自动调用
func (c *MarketingController) Constructor() {
	c.serv = marketing.NewMarketingServ(c.Context)
}

// 获取 营销活动列表
func (c *MarketingController) GetMarketingList(){
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")

	marketings, err := c.serv.GetMarketingList(page,pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(marketings)

}

// SaveMarketing 保存营销活动
func (c *MarketingController) SaveMarketing() {
	marketing := model.SysActivity{}

	// 获取值
	activityName := c.GetString("activityName")
	activityType := c.GetString("activityType")
	resourceDesc := c.GetString("resourceDesc") // 活动描述

	// 赋值
	marketing.ActivityName = activityName
	marketing.ActivityType = activityType

	newInfo,_, err := c.serv.SaveMarketing(marketing,resourceDesc)
	if err != nil {
		c.ResponseError(err)
	}

	c.ResponseJSON(newInfo)
}


// GetMarketingById 根据activityId查询
func (c *MarketingController) GetMarketingById(){
	 activityId := c.GetString("activityId")

	 info,err :=	c.serv.GetMarketingById(activityId)
	 if err != nil {
		c.ResponseError(err)
	}

	c.ResponseJSON(info)
}

// UpdateMarketing 修改数据
func (c *MarketingController) UpdateMarketing(){
	activity := model.SysActivity{}

	// 获取值
	activityName := c.GetString("activityName")
	activityType := c.GetString("activityType")
	
	// 赋值
	activity.ActivityName = activityName
	activity.ActivityType = activityType
	
	err := c.serv.UpdateMarketing(activity)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功!")
}

// DelMarketing 删除
func (c *MarketingController) DelMarketing(){
	activityId := c.GetString("activityId")
	err := c.serv.DelMarketing(activityId)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功!")
}

// DelMarketing 正常
func (c *MarketingController) DelMarketingNormal(){
	activityId := c.GetString("activityId")
	err := c.serv.DelMarketingNormal(activityId)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功!")
}

// DelMarketing 停用
func (c *MarketingController) DelMarketingDisable(){
	activityId := c.GetString("activityId")
	err := c.serv.DelMarketingDisable(activityId)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功!")
}







