package controllers

import (
	"git.rosy.net.cn/jx-callback/business/jxstore/cms"
	"git.rosy.net.cn/jx-callback/business/jxstore/report"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"github.com/astaxie/beego/server/web"
)

// 统计相关API
type ReportController struct {
	web.Controller
}

// @Title 查询订单统计信息
// @Description 根据门店idlist和时间范围查询
// @Param	token			header		string	true	"认证token"
// @Param	storeIDs		formData	string	false	"京西门店ID列表[1,2,3]"
// @Param	vendorIDs		formData	string	false	"平台ID列表[1,2,3]"
// @Param	marketManPhone	formData	string	false	"平台负责人"
// @Param	jdPhone			formData	string	false	"京东负责人电话"
// @Param	mtPhone			formData	string	false	"美团负责人电话"
// @Param	ebaiPhone		formData	string	false	"饿百负责人电话"
// @Param	fromDate		formData	string	true	"开始日期（包含），格式（2006-01-02 00:00:00)"
// @Param	toDate			formData	string	true	"结束日期（包含），格式（2006-01-02 00:00:00)"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /StatisticsReportForOrders [post]
func (c *ReportController) StatisticsReportForOrders() {
	c.callStatisticsReportForOrders(func(params *tReportStatisticsReportForOrdersParams) (retVal interface{}, errCode string, err error) {
		var storeIDList, vendorIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList, params.VendorIDs, &vendorIDs); err == nil {
			retVal, err = report.GetStatisticsReportForOrders(params.Ctx, storeIDList, vendorIDs, params.FromDate, params.ToDate, params.MarketManPhone, params.JdPhone, params.MtPhone, params.EbaiPhone)
		}
		return retVal, "", err
	})
}

// @Title 查询售后单统计信息
// @Description 根据门店idlist和时间范围查询
// @Param	token			header		string	true	"认证token"
// @Param	storeIDs		formData	string	true	"京西门店ID列表[1,2,3]"
// @Param	fromDate		formData	string	true	"开始日期（包含），格式（2006-01-02 00:00:00)"
// @Param	toDate			formData	string	true	"结束日期（包含），格式（2006-01-02 00:00:00)"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /StatisticsReportForAfsOrders [post]
func (c *ReportController) StatisticsReportForAfsOrders() {
	c.callStatisticsReportForAfsOrders(func(params *tReportStatisticsReportForAfsOrdersParams) (retVal interface{}, errCode string, err error) {
		var storeIDList []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
			retVal, err = report.GetStatisticsReportForAfsOrders(params.Ctx, storeIDList, params.FromDate, params.ToDate)
		}
		return retVal, "", err
	})
}

// @Title 查询京西门店商品价格统计相关信息
// @Description 查询京西门店商品价格统计相关信息
// @Param	token			header		string	true	"认证token"
// @Param	cityCodes		formData	string	true	"城市ID列表[1,2,3]"
// @Param	skuIDs			formData	string	false	"skuID列表[1,2,3]"
// @Param	snapDate		formData	string	true	"某天的参考价格 格式：2006-01-02,默认前一天"
// @Param	offset			formData	int		false	"门店列表起始序号（以0开始，缺省为0）"
// @Param	pageSize		formData	int		false	"门店列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /StatisticsReportForStoreSkusPrice [post]
func (c *ReportController) StatisticsReportForStoreSkusPrice() {
	c.callStatisticsReportForStoreSkusPrice(func(params *tReportStatisticsReportForStoreSkusPriceParams) (retVal interface{}, errCode string, err error) {
		var cityCodeList, skuIDList []int
		if err = jxutils.Strings2Objs(params.CityCodes, &cityCodeList, params.SkuIDs, &skuIDList); err == nil {
			retVal, err = report.StatisticsReportForStoreSkusPrice(params.Ctx, cityCodeList, skuIDList, params.SnapDate, 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 /PriceRefer [post]
func (c *ReportController) PriceRefer() {
	c.callPriceRefer(func(params *tReportPriceReferParams) (retVal interface{}, errCode string, err error) {
		report.BeginSavePriceRefer(params.Ctx, nil, nil, true, true)
		return retVal, "", err
	})
}

// @Title 自动关注商品（针对后加的商品规格未关注）
// @Description 自动关注商品（针对后加的商品规格未关注）
// @Param	token			header		string	true	"认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /AutoFocusStoreSkus [post]
func (c *ReportController) AutoFocusStoreSkus() {
	c.callAutoFocusStoreSkus(func(params *tReportAutoFocusStoreSkusParams) (retVal interface{}, errCode string, err error) {
		cms.AutoFocusStoreSkusWithoutFocus(params.Ctx, nil, false)
		return retVal, "", err
	})
}

// @Title 查询经营概况
// @Description 查询经营概况
// @Param	token			header		string	true	"认证token"
// @Param	cityCodes		query		string	false	"城市ID列表[1,2,3]"
// @Param	vendorID		query		int		false	"vendorID 全部传-1"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetManageState [get]
func (c *ReportController) GetManageState() {
	c.callGetManageState(func(params *tReportGetManageStateParams) (retVal interface{}, errCode string, err error) {
		var cityCodes []int
		if err = jxutils.Strings2Objs(params.CityCodes, &cityCodes); err == nil {
			retVal, err = report.GetManageState(params.Ctx, cityCodes, params.VendorID)
		}
		return retVal, "", err
	})
}

// @Title 查询门店经营数据
// @Description 查询门店经营数据
// @Param	token			header		string	true	"认证token"
// @Param	storeIDs		query		string	false	"门店ID列表[1,2,3]"
// @Param	brandIDs		query		string	false	"品牌ID列表[1,2,3]"
// @Param	vendorID		query		int		true	"平台ID"
// @Param	sortType		query		int		false	"排序类型,1 覆盖范围，2市场规模，3营业时长，4商品数，5虚高商品数，6活动丰富度，7无效订单数，8拒绝订单数，9门店评分，10完成订单数,正升序，负倒序"
// @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 /GetStoreManageState [get]
func (c *ReportController) GetStoreManageState() {
	c.callGetStoreManageState(func(params *tReportGetStoreManageStateParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, brandIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.BrandIDs, &brandIDs); err == nil {
			retVal, err = report.GetStoreManageState(params.Ctx, storeIDs, brandIDs, params.VendorID, params.SortType, params.Offset, params.PageSize)
		}
		return retVal, "", err
	})
}

// @Title 统计会员信息
// @Description 统计会员信息
// @Param	token			header		string		true	"认证token"
// @Param	vendorID		query		int			false	"平台ID"
// @Param	keyword			query		string		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 /UserMemberReport [get]
func (c *ReportController) UserMemberReport() {
	c.callUserMemberReport(func(params *tReportUserMemberReportParams) (retVal interface{}, errCode string, err error) {
		retVal, err = report.UserMemberReport(params.Ctx, params.VendorID, params.Keyword, params.Offset, params.PageSize)
		return retVal, "", err
	})
}

// @Title 统计语音短信收费
// @Description 统计语音短信收费
// @Param	token			header		string		true	"认证token"
// @Param	storeIDs		query		string		false	"门店ID列表[1,2,3]"
// @Param	brandIDs		query		string		false	"品牌ID列表[1,2,3]"
// @Param	vendorID		query		int			false	"平台ID"
// @Param	notifyType		query		int			false	"-1 表示全部，1表示短信，2表示语音"
// @Param	keyword			query		string		false	"关键字"
// @Param	fromTime		query		string		true	"开始日期（包含），格式（2006-01-02 00:00:00)"
// @Param	toTime			query		string		true	"结束日期（包含），格式（2006-01-02 00:00:00)"
// @Param	isFinished		query		bool		false	"默认下单时间，true是订单完成时间"
// @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 /OrderNotifyReport [get]
func (c *ReportController) OrderNotifyReport() {
	c.callOrderNotifyReport(func(params *tReportOrderNotifyReportParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, brandIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.BrandIDs, &brandIDs); err == nil {
			retVal, err = report.OrderNotifyReport(params.Ctx, storeIDs, brandIDs, params.VendorID, params.NotifyType, params.Keyword, params.IsFinished, params.FromTime, params.ToTime, params.Offset, params.PageSize)
		}
		return retVal, "", err
	})
}

// @Title 统计三方配送费用
// @Description 统计三方配送费用
// @Param	token			header		string		true	"认证token"
// @Param	storeIDs		query		string		false	"门店ID列表[1,2,3]"
// @Param	brandIDs		query		string		false	"品牌ID列表[1,2,3]"
// @Param	vendorID		query		int			false	"平台ID"
// @Param	deliveryVendorID	query  	int			false	"配送平台ID"
// @Param	keyword			query		string		false	"关键字"
// @Param	fromTime		query		string		true	"开始日期（包含），格式（2006-01-02 00:00:00)"
// @Param	toTime			query		string		true	"结束日期（包含），格式（2006-01-02 00:00:00)"
// @Param	isFinished		query		bool		false	"默认下单时间，true是订单完成时间"
// @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 /OrderDeliveryReport [get]
func (c *ReportController) OrderDeliveryReport() {
	c.callOrderDeliveryReport(func(params *tReportOrderDeliveryReportParams) (retVal interface{}, errCode string, err error) {
		var storeIDs, brandIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.BrandIDs, &brandIDs); err == nil {
			retVal, err = report.OrderDeliveryReport(params.Ctx, storeIDs, brandIDs, params.VendorID, params.DeliveryVendorID, params.Keyword, params.IsFinished, params.FromTime, params.ToTime, params.Offset, params.PageSize)
		}
		return retVal, "", err
	})
}
