package controllers

import (
	"fmt"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"

	"git.rosy.net.cn/jx-callback/business/jxstore/act"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/model/dao"
	"github.com/astaxie/beego/server/web"
)

type ActController struct {
	web.Controller
}

// @Title 预创建活动
// @Description 预创建活动
// @Param	token			header		string	true	"认证token"
// @Param	name			formData	string	true	"活动名，必须唯一（所以名子上最好带上日期）"
// @Param	type			formData	int		true	"活动类型，3：直降，4：秒杀（美团当前不支持秒杀）"
// @Param	vendorIDs		formData	string	true	"厂商ID，当前只支持，京东：0，京西（用于记录活动信息）：99"
// @Param	beginAt			formData	string	true	"开始日期"
// @Param	endAt			formData	string	true	"结束日期"
// @Param	pricePercentage	formData	int		true	"活动价格比例"
// @Param	advertising		formData	string	true	"广告语"
// @Param	actStoreSkuList	formData	string	true	"活动门店商品信息"
// @Param	overlapRule		formData	int		false	"活动重叠规则"
// @Param	limitDaily		formData	int		false	"是否按日0-不限，>0限购单数（秒杀需填）"
// @Param	limitUser		formData	int		false	"是否用户限购0-不限，1-限购"
// @Param	limitCount		formData	int		false	"限购件数 0-不限，如账号限购、设备限购有一个为1，则限购件数必须大于0的整数"
// @Param	remark			formData	string	false	"备注"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /PreCreateAct [post]
func (c *ActController) PreCreateAct() {
	c.callPreCreateAct(func(params *tActPreCreateActParams) (retVal interface{}, errCode string, err error) {
		var (
			vendorIDs       []int
			actStoreSkuList []*act.ActStoreSkuParam
		)
		timeList, err := jxutils.BatchStr2Time(params.BeginAt, params.EndAt)
		if err == nil {
			if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.ActStoreSkuList, &actStoreSkuList); err == nil {
				actObj := &model.Act{
					Name:        params.Name,
					Type:        params.Type,
					LimitUser:   params.LimitUser,
					LimitDaily:  params.LimitDaily,
					LimitCount:  params.LimitCount,
					OverlapRule: params.OverlapRule,
					// Source:,
					CreateType:      model.ActCreateTypeAPI,
					PricePercentage: params.PricePercentage,
					BeginAt:         timeList[0],
					EndAt:           timeList[1],
					Advertising:     params.Advertising,
					Remark:          params.Remark,
				}
				retVal, err = act.PreCreateAct(params.Ctx, actObj, vendorIDs, nil, actStoreSkuList)
			}
		}
		return retVal, "", err
	})
}

// @Title 创建活动
// @Description 创建活动
// @Param	token			header		string	true	"认证token"
// @Param	name			formData	string	true	"活动名，必须唯一（所以名子上最好带上日期）"
// @Param	type			formData	int		true	"活动类型，3：直降，4：秒杀（美团当前不支持秒杀），5：折扣（京西）"
// @Param	vendorIDs		formData	string	true	"厂商ID，当前只支持，京东：0，京西（用于记录活动信息）：99"
// @Param	vendorOrgCode	formData	string	false	"厂商内组织代码"
// @Param	beginAt			formData	string	true	"开始日期"
// @Param	endAt			formData	string	true	"结束日期"
// @Param	pricePercentage	formData	int		true	"活动价格比例"
// @Param	advertising		formData	string	true	"广告语"
// @Param	actStoreSkuList	formData	string	true	"活动门店商品信息"
// @Param	overlapRule		formData	int		false	"活动重叠规则"
// @Param	discountType	formData	int		false	"折扣类型，当活动类型是折扣的时候传入"
// @Param	discountValue1	formData	int		false	"折扣一档"
// @Param	discountValue2	formData	int		false	"折扣二档"
// @Param	limitDaily		formData	int		false	"是否按日0-不限，>0限购单数（秒杀需填）"
// @Param	limitUser		formData	int		false	"是否用户限购0-不限，1-限购"
// @Param	limitCount		formData	int		false	"限购件数 0-不限，如账号限购、设备限购有一个为1，则限购件数必须大于0的整数"
// @Param	remark			formData	string	false	"备注"
// @Param	isAsync			formData	bool	false	"是否异步，缺省否（暂时只支持同步）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateAct [post]
func (c *ActController) CreateAct() {
	c.callCreateAct(func(params *tActCreateActParams) (retVal interface{}, errCode string, err error) {
		var (
			vendorIDs       []int
			actStoreSkuList []*act.ActStoreSkuParam
		)
		timeList, err := jxutils.BatchStr2Time(params.BeginAt, params.EndAt)
		if err == nil {
			if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.ActStoreSkuList, &actStoreSkuList); err == nil {
				actObj := &model.Act{
					Name:        params.Name,
					Type:        params.Type,
					LimitUser:   params.LimitUser,
					LimitDaily:  params.LimitDaily,
					LimitCount:  params.LimitCount,
					OverlapRule: params.OverlapRule,
					// Source:,
					CreateType:      model.ActCreateTypeAPI,
					PricePercentage: params.PricePercentage,
					BeginAt:         timeList[0],
					EndAt:           timeList[1],
					Advertising:     params.Advertising,
					Remark:          params.Remark,
					DiscountType:    params.DiscountType,
					DiscountValue1:  params.DiscountValue1,
					DiscountValue2:  params.DiscountValue2,
				}
				retVal, err = act.CreateAct(params.Ctx, actObj, vendorIDs, params.VendorOrgCode, nil, actStoreSkuList, params.IsAsync)
			}
		}
		return retVal, "", err
	})
}

// @Title 美团按顺序创建活动
// @Description 美团按顺序创建活动
// @Param	token			header		string	true	"认证token"
// @Param	name			formData	string	true	"活动名，必须唯一（所以名子上最好带上日期）"
// @Param	type			formData	int		true	"活动类型，3：直降"
// @Param	vendorIDs		formData	string	true	"厂商ID，当前只支持，京东：0，京西（用于记录活动信息）：99"
// @Param	vendorOrgCode	formData	string	true	"厂商内组织代码"
// @Param	beginAt			formData	string	true	"开始日期"
// @Param	endAt			formData	string	true	"结束日期"
// @Param	pricePercentage	formData	int		true	"活动价格比例"
// @Param	advertising		formData	string	true	"广告语"
// @Param	actStoreSkuList	formData	string	true	"活动门店商品信息"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateActForMtByOrder [post]
func (c *ActController) CreateActForMtByOrder() {
	c.callCreateActForMtByOrder(func(params *tActCreateActForMtByOrderParams) (retVal interface{}, errCode string, err error) {
		var (
			actStoreSkuList []*act.ActStoreSkuParam
			vendorIDs       []int
		)
		timeList, err := jxutils.BatchStr2Time(params.BeginAt, params.EndAt)
		jxutils.Strings2Objs(params.VendorIDs, &vendorIDs)
		if err == nil {
			if err = jxutils.Strings2Objs(params.ActStoreSkuList, &actStoreSkuList); err == nil {
				actObj := &model.Act{
					Name:            params.Name,
					Type:            params.Type,
					CreateType:      model.ActCreateTypeAPI,
					PricePercentage: params.PricePercentage,
					BeginAt:         timeList[0],
					EndAt:           timeList[1],
					Advertising:     params.Advertising,
				}
				//retVal, err = act.CreateAct(params.Ctx, actObj, vendorIDs, params.VendorOrgCode, nil, actStoreSkuList, params.IsAsync)
				err = act.CreateActForMtByOrder(params.Ctx, actObj, vendorIDs, params.VendorOrgCode, actStoreSkuList)
			}
		}
		return "success", "", err
	})
}

// @Title 查询活动
// @Description 查询活动
// @Param	token			header		string	true	"认证token"
// @Param	createdAtFrom	query		string	false	"创建开始日期"
// @Param	createdAtTo		query		string	false	"创建结束日期"
// @Param	keyword			query		string	false	"关键字"
// @Param	actID			query		int		false	"活动id"
// @Param	name			query		string	false	"活动名，不完全匹配"
// @Param	cityCode		query		int		false	"活动门店所属城市code"
// @Param	beginAt			query		string	false	"开始日期，包括"
// @Param	endAt			query		string	false	"结束日期，包括"
// @Param	vendorID		query		int		false	"包含平台"
// @Param	typeList		query		string	false	"活动类型列表，3：直降，4：秒杀"
// @Param	statusList		query		string	false	"活动状态列表"
// @Param	createTypeList	query		string	false	"创建方式列表"
// @Param	storeID			query		int		false	"包含门店"
// @Param	skuID			query		int		false	"包含sku"
// @Param	syncStatus		query		int		false	"活动同步标识，缺省不限制"
// @Param	offset			query		int		false	"活动列表起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int		false	"活动列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryActs [get]
func (c *ActController) QueryActs() {
	c.callQueryActs(func(params *tActQueryActsParams) (retVal interface{}, errCode string, err error) {
		timeList, err := jxutils.BatchStr2Time(params.CreatedAtFrom, params.CreatedAtTo, params.BeginAt, params.EndAt)
		if err == nil {
			var typeList, statusList, createTypeList []int
			if err = jxutils.Strings2Objs(params.TypeList, &typeList, params.StatusList, &statusList, params.CreateTypeList, &createTypeList); err == nil {
				if params.MapData["vendorID"] == nil {
					params.VendorID = -1
				}
				if params.MapData["syncStatus"] == nil {
					params.SyncStatus = -1
				}
				retVal, err = act.QueryActs(params.Ctx, params.ActID, params.Offset, params.PageSize, params.SyncStatus, params.Keyword, params.VendorID,
					statusList, typeList, createTypeList, params.StoreID, params.SkuID, params.CityCode, timeList[2], timeList[3], timeList[0], timeList[1])
			}
		}
		return retVal, "", err
	})
}

// @Title 取消活动
// @Description 取消活动
// @Param	token		header		string	true	"认证token"
// @Param	actID		formData	int		true	"活动id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CancelAct [put]
func (c *ActController) CancelAct() {
	c.callCancelAct(func(params *tActCancelActParams) (retVal interface{}, errCode string, err error) {
		err = act.CancelAct(params.Ctx, params.ActID)
		return retVal, "", err
	})
}

// @Title 得到活动门店商品信息
// @Description 得到活动门店商品信息
// @Param	token			header		string	true	"认证token"
// @Param	actID			query		int		true	"活动id"
// @Param	vendorIDs		query		string	false	"厂商ID列表"
// @Param	keyword			query		string	false	"查询关键字（可以为空，为空表示不限制）"
// @Param	offset			query		int		false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int		false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetActStoreSkuInfo [get,post]
func (c *ActController) GetActStoreSkuInfo() {
	c.callGetActStoreSkuInfo(func(params *tActGetActStoreSkuInfoParams) (retVal interface{}, errCode string, err error) {
		var vendorIDs []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
			if params.PageSize == 0 {
				params.PageSize = -1
			}
			retVal, err = act.GetActStoreSkuInfo(params.Ctx, params.ActID, vendorIDs, params.Keyword, params.Offset, params.PageSize)
		}
		return retVal, "", err
	})
}

// @Title 同步活动
// @Description 同步活动
// @Param	token			header		string	true	"认证token"
// @Param	actID			formData	int		true	"活动id"
// @Param	vendorIDs		formData	string	false	"厂商ID列表"
// @Param	isAsync			formData	bool	false	"是否异步"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SyncAct [put]
func (c *ActController) SyncAct() {
	c.callSyncAct(func(params *tActSyncActParams) (retVal interface{}, errCode string, err error) {
		var vendorIDs /*, storeIDs, skuIDs*/ []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs /*, params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs*/); err == nil {
			retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, vendorIDs, params.IsAsync)
		}
		return retVal, "", err
	})
}

// @Title 添加SKU活动商品
// @Description 添加SKU活动商品
// @Param	token				header		string	true	"认证token"
// @Param	actID				formData	int		true	"活动id"
// @Param	actStoreSkuAddList		formData	string	false	"需添加的活动商品信息"
// @Param	actStoreSkuDeleteList	formData	string	false	"需删除的活动商品信息"
// @Param	isAsync					formData	bool	false	"是否异步"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateActStoreSkuBind [put]
func (c *ActController) UpdateActStoreSkuBind() {
	c.callUpdateActStoreSkuBind(func(params *tActUpdateActStoreSkuBindParams) (retVal interface{}, errCode string, err error) {
		var actStoreSkuAddList, actStoreSkuDeleteList []*act.ActStoreSkuParam
		if err = jxutils.Strings2Objs(params.ActStoreSkuAddList, &actStoreSkuAddList, params.ActStoreSkuDeleteList, &actStoreSkuDeleteList); err == nil {
			if len(actStoreSkuAddList) == 0 && len(actStoreSkuDeleteList) == 0 {
				err = fmt.Errorf("actStoreSkuAddList与actStoreSkuDeleteList不能都为空")
			} else {
				db := dao.GetDB()
				if len(actStoreSkuAddList) > 0 {
					if err = act.AddActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuAddList); err != nil {
						return
					}
				}
				if len(actStoreSkuDeleteList) > 0 {
					//可能是平台直接创建的活动，尝试直接取消一下
					if params.ActID < 1000 {
						act.DeleteActStoreSkuVendor(params.Ctx, db, actStoreSkuDeleteList)
					} else {
						if _, err = act.DeleteActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuDeleteList); err != nil {
							return
						}
					}
				}
				if err == nil {
					retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, nil, params.IsAsync)
				}
			}
		}
		return retVal, "", err
	})
}

// @Title 添加SKU活动商品
// @Description 添加SKU活动商品
// @Param	token				header		string	true	"认证token"
// @Param	vendorIDs			formData	string	true	"厂商ID列表"
// @Param	createdFrom			formData	string	true	"创建开始日期"
// @Param	isAsync				formData	bool	false	"是否异步"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshPageActs [put]
func (c *ActController) RefreshPageActs() {
	c.callRefreshPageActs(func(params *tActRefreshPageActsParams) (retVal interface{}, errCode string, err error) {
		timeList, err := jxutils.BatchStr2Time(params.CreatedFrom)
		if err == nil {
			var vendorIDs []int
			if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
				retVal, err = act.RefreshPageActs(params.Ctx, vendorIDs, timeList[0], params.IsAsync)
			}
		}
		return retVal, "", err
	})
}

// @Title 将SKU从所有活动中删除
// @Description 将SKU从所有活动中删除
// @Param	token				header	string	true	"认证token"
// @Param	skuIDs				query	string	true	"skuID列表"
// @Param	vendorID			query	int		true	"厂商ID"
// @Param	types				query	string	false	"活动类型列表"
// @Param	isAsync				query	bool	false	"是否异步"
// @Param	isContinueWhenError	query	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /DeleteSkusFromAct [delete]
func (c *ActController) DeleteSkusFromAct() {
	c.callDeleteSkusFromAct(func(params *tActDeleteSkusFromActParams) (retVal interface{}, errCode string, err error) {
		var skuIDs, types []int
		if err = jxutils.Strings2Objs(params.SkuIDs, &skuIDs, params.Types, &types); err == nil {
			retVal, err = act.DeleteSkusFromAct(params.Ctx, params.VendorID, types, skuIDs, params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// @Title 将门店从所有活动中删除
// @Description 将门店从所有活动中删除
// @Param	token				header	string	true	"认证token"
// @Param	storeIDs			query	string	true	"门店ID列表"
// @Param	vendorID			query	int		true	"厂商ID"
// @Param	types				query	string	false	"活动类型列表"
// @Param	isAsync				query	bool	false	"是否异步"
// @Param	isContinueWhenError	query	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /DeleteStoresFromAct [delete]
func (c *ActController) DeleteStoresFromAct() {
	c.callDeleteStoresFromAct(func(params *tActDeleteStoresFromActParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, types []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Types, &types); err == nil {
			retVal, err = act.DeleteStoresFromAct(params.Ctx, params.VendorID, types, storeIDs, params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// @Title 强制更新商品平台价
// @Description 强制更新商品平台价
// @Param	token			header		string	true	"认证token"
// @Param	type			formData	int		true	"活动类型，3：直降，4：秒杀（美团当前不支持秒杀）"
// @Param	vendorID		formData	int		true	"厂商ID，当前只支持，京东：0，京西（用于记录活动信息）：9"
// @Param	actStoreSkuList	formData	string	true	"活动门店商品信息"
// @Param	lockTime		formData	string	false	"平台价格锁定截止时间"
// @Param	isAsync			formData	bool	false	"是否异步，缺省否（暂时只支持同步）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ForceUpdateVendorPrice [post]
func (c *ActController) ForceUpdateVendorPrice() {
	c.callForceUpdateVendorPrice(func(params *tActForceUpdateVendorPriceParams) (retVal interface{}, errCode string, err error) {
		var actStoreSkuList []*act.ActStoreSkuParam
		if err = jxutils.Strings2Objs(params.ActStoreSkuList, &actStoreSkuList); err == nil {
			timeList, err2 := jxutils.BatchStr2Time(params.LockTime)
			if err = err2; err == nil {
				retVal, err = act.ForceUpdateVendorPrice(params.Ctx, params.VendorID, params.Type, actStoreSkuList, timeList[0], params.IsAsync)
			}
		}
		return retVal, "", err
	})
}

// @Title 通过Excel创建活动
// @Description 通过Excel创建活动
// @Param	token				header		string	true	"认证token"
// @Param	vendorID			formData	int		true	"厂商ID，当前只支持，京东：0，京西（用于记录活动信息）：99"
// @Param	vendorOrgCode		formData	string	false	"厂商内组织代码"
// @Param	mixType				formData	int		true	"数据处理方式：1（一行一条数据）2（门店与商品相乘）"
// @Param	isFocus				formData	bool	true	"是否批量关注可售所有商品，默认是"
// @Param	isSync				formData	bool	true	"是否同步所有未同步的商品，默认是"
// @Param	isAsync				formData	bool	false	"是否异步"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateActByExcel [post]
func (c *ActController) CreateActByExcel() {
	c.callCreateActByExcel(func(params *tActCreateActByExcelParams) (retVal interface{}, errCode string, err error) {
		// r := c.Ctx.Request
		// files := r.MultipartForm.File["userfiles"]
		retVal, err = act.CreateActByExcel(params.Ctx, "files", params.VendorID, params.VendorOrgCode, params.MixType, params.IsFocus, params.IsSync, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 获取平台流量活动List
// @Description 获取平台流量活动List
// @Param	token				header		string	true	"认证token"
// @Param	vendorID			query		int		true	"厂商ID，当前只支持，饿百3，美团1"
// @Param	storeID				query		int		false	"门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetVendorPopActs [get]
func (c *ActController) GetVendorPopActs() {
	c.callGetVendorPopActs(func(params *tActGetVendorPopActsParams) (retVal interface{}, errCode string, err error) {
		retVal, err = act.GetVendorPopActs(params.Ctx, params.VendorID, params.StoreID)
		return retVal, "", err
	})
}

// @Title 获取平台流量活动Detail
// @Description 获取平台流量活动Detail
// @Param	token				header		string	true	"认证token"
// @Param	vendorID			query		int		true	"厂商ID，当前只支持，饿百3，美团1"
// @Param	storeID				query		int		false	"门店ID"
// @Param	actID				query		int		true	"活动ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetVendorPopActDetail [get]
func (c *ActController) GetVendorPopActDetail() {
	c.callGetVendorPopActDetail(func(params *tActGetVendorPopActDetailParams) (retVal interface{}, errCode string, err error) {
		retVal, err = act.GetVendorPopActDetail(params.Ctx, params.VendorID, params.StoreID, params.ActID)
		return retVal, "", err
	})
}

// @Title 查询美团平台活动
// @Description 查询美团平台活动
// @Param	token				header		string	true	"认证token"
// @Param	storeIDs		query		string	 	false	"门店IDs"
// @Param	skuIDs			query		string		false	"skuIDs"
// @Param	keyword			query		string		false	"关键字"
// @Param	beginAt			query		string		false	"活动开始日期"
// @Param	endAt			query		string		false	"活动结束日期"
// @Param	actType			query		int			false	"折扣或者秒杀"
// @Param	offset			query		int			false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int			false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetActMtwmVendor [get]
func (c *ActController) GetActMtwmVendor() {
	c.callGetActMtwmVendor(func(params *tActGetActMtwmVendorParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, skuIDs []int
		err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs)
		retVal, err = act.GetActMtwmVendor(params.Ctx, storeIDs, skuIDs, params.Keyword, params.BeginAt, params.EndAt, params.ActType, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 查询美团平台线上活动（会有不在我们本地创建的）
// @Description 查询美团平台线上活动
// @Param	token			header		string	   true	"认证token"
// @Param	vendorStoreID	query		string	   true	"美团门店ID"
// @Param	vendorOrgCode 	query		string	   true	"美团appID"
// @Param	beginAt			query		int		   true	"活动开始日期 时间戳"
// @Param	endAt			query		int		   true	"活动结束日期"
// @Param	actType			query		int		   true	"折扣或者秒杀"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMTOnlineAct [get]
func (c *ActController) GetMTOnlineAct() {
	c.callGetMTOnlineAct(func(params *tActGetMTOnlineActParams) (interface{}, string, error) {
		retVal, err := mtwm.GetActByAppPoiCode(params.VendorStoreID, params.VendorOrgCode, int64(params.BeginAt), int64(params.EndAt), params.ActType)
		return retVal, "", err
	})
}

// @Title 根据商品id查询未开展活动的门店信息
// @Description 查询美团平台活动
// @Param	token			header		string	 	true	"认证token"
// @Param	skuID			query		int			false	"skuID"
// @Param	offset			query		int			false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int			false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetNotHaveSkuActList [get]
func (c *ActController) GetNotHaveSkuActList() {
	c.callGetNotHaveSkuActList(func(params *tActGetNotHaveSkuActListParams) (retVal interface{}, errCode string, err error) {
		retVal, err = act.GetStoreNotHaveSku(params.SkuID, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 查询美团平台活动
// @Description 查询美团平台活动
// @Param	token			header		string	 	true	"认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshMTActivityList [get]
func (c *ActController) RefreshMTActivityList() {
	c.callRefreshMTActivityList(func(params *tActRefreshMTActivityListParams) (retVal interface{}, errCode string, err error) {
		err = act.RrefreshMtwmVendorAct(params.Ctx)
		return retVal, "", err
	})
}

// @Title 查询美团平台活动sku
// @Description 查询美团平台活动sku
// @Param	token			header		string	 	true	"认证token"
// @Param	storeID			query		int	 		true	"门店ID"
// @Param	keyword			query		string		false	"关键字"
// @Param	actType			query		int			false	"折扣或者秒杀"
// @Param	offset			query		int			false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int			false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetActMtwmVendorSku [get]
func (c *ActController) GetActMtwmVendorSku() {
	c.callGetActMtwmVendorSku(func(params *tActGetActMtwmVendorSkuParams) (retVal interface{}, errCode string, err error) {
		retVal, err = act.GetActMtwmVendorSku(params.Ctx, params.StoreID, params.Keyword, params.ActType, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 查询饿百平台活动
// @Description 查询饿百平台活动
// @Param	token			header		string	 	true	"认证token"
// @Param	storeIDs		query		string	 	false	"门店IDs"
// @Param	skuIDs			query		string		false	"skuIDs"
// @Param	keyword			query		string		false	"关键字"
// @Param	beginAt			query		string		false	"活动开始日期"
// @Param	endAt			query		string		false	"活动结束日期"
// @Param	actType			query		int			false	"折扣或者秒杀"
// @Param	offset			query		int			false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int			false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetActEbaiVendor [get]
func (c *ActController) GetActEbaiVendor() {
	c.callGetActEbaiVendor(func(params *tActGetActEbaiVendorParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, skuIDs []int
		err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs)
		retVal, err = act.GetActEbaiVendor(params.Ctx, storeIDs, skuIDs, params.Keyword, params.BeginAt, params.EndAt, params.ActType, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 查询饿百平台活动sku
// @Description 查询饿百平台活动sku
// @Param	token			header		string	 	true	"认证token"
// @Param	actID			query		string	 	true	"活动ID"
// @Param	keyword			query		string		false	"关键字"
// @Param	offset			query		int			false	"起始序号（以0开始，缺省为0）"
// @Param	pageSize		query		int			false	"表页大小（缺省全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetActEbaiVendorSku [get]
func (c *ActController) GetActEbaiVendorSku() {
	c.callGetActEbaiVendorSku(func(params *tActGetActEbaiVendorSkuParams) (retVal interface{}, errCode string, err error) {
		retVal, err = act.GetActEbaiVendorSku(params.Ctx, params.ActID, params.Keyword, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 刷新平台活动
// @Description 刷新平台活动
// @Param	token			header		string	 	true	"认证token"
// @Param	vendorID		query		int		 	true	"平台ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshVendorAct [post]
func (c *ActController) RefreshVendorAct() {
	c.callRefreshVendorAct(func(params *tActRefreshVendorActParams) (retVal interface{}, errCode string, err error) {
		if params.VendorID == model.VendorIDMTWM {
			act.RrefreshMtwmVendorAct(params.Ctx)
		} else {
			act.RrefreshEbaiVendorAct(params.Ctx)
		}
		return retVal, "", err
	})
}
