package controllers

import (
	"git.rosy.net.cn/baseapi/platformapi/lakala"
	"git.rosy.net.cn/baseapi/utils"
	lakalaServer "git.rosy.net.cn/jx-callback/business/lakala"
	"github.com/astaxie/beego/server/web"
)

type LaKaLaController struct {
	web.Controller
}

// LaKaLaApplyContract 拉卡拉商户合同申请
// @Title 拉卡拉商户合同申请
// @Description 拉卡拉商户合同申请
// @Param	token			header		string	true	"认证token"
// @Param	payload			formData	string	true	"json数据，lakala.ApplyContractParam 对象"
// @Param	storeID			formData	int		true	"门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LaKaLaApplyContract [post]
func (c *LaKaLaController) LaKaLaApplyContract() {
	c.callLaKaLaApplyContract(func(params *tLakalaLaKaLaApplyContractParams) (retVal interface{}, errCode string, err error) {
		contract := &lakala.ApplyContractParam{}
		err = utils.UnmarshalUseNumber([]byte(params.Payload), contract)
		if err != nil {
			return retVal, "", err
		}

		retVal, err = lakalaServer.LaKaLaApplyContract(params.Ctx, contract, params.StoreID)
		return retVal, "", err
	})
}

// LaKaLaApplyContractByPeople 拉卡拉商户合同申请,人工审核
// @Title 拉卡拉商户合同申请,人工审核
// @Description 拉卡拉商户合同申请,人工审核
// @Param	token			header		string	true	"认证token"
// @Param	payload			formData	string	true	"json数据，lakala.ApplyContractByPeople 对象"
// @Param	storeID			formData	int		true	"门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LaKaLaApplyContractByPeople [post]
func (c *LaKaLaController) LaKaLaApplyContractByPeople() {
	c.callLaKaLaApplyContractByPeople(func(params *tLakalaLaKaLaApplyContractByPeopleParams) (retVal interface{}, errCode string, err error) {
		contract := &lakala.ApplyContractByPeople{}
		err = utils.UnmarshalUseNumber([]byte(params.Payload), contract)
		if err != nil {
			return retVal, "", err
		}

		retVal, err = lakalaServer.LaKaLaApplyContractByPeople(params.StoreID, contract)
		return retVal, "", err
	})
}

// QueryElectronicContract 合同申请状态查询
// @Title 合同申请状态查询
// @Description 合同申请状态查询
// @Param	token			header		string	true	"认证token"
// @Param	storeID			formData	int		true	"门店ID"
// @Param	orderNo			formData	string	true	"订单编号"
// @Param	orgId			formData	int		true	"组织ID"
// @Param	ecApplyId		formData	string	true	"申请ID"
// @Param	queryType		formData	string	true	"查询类型[1-人工审核查询/2-电子合同申请查询]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryElectronicContract [post]
func (c *LaKaLaController) QueryElectronicContract() {
	c.callQueryElectronicContract(func(params *tLakalaQueryElectronicContractParams) (retVal interface{}, errCode string, err error) {
		switch params.QueryType {
		case "1":
			retVal, err = lakalaServer.QueryElectronicContract(params.OrderNo, params.OrgId, params.EcApplyId, params.StoreID)
		case "2":
			retVal, err = lakalaServer.QueryElectronic(params.OrderNo, params.OrgId, params.EcApplyId, params.StoreID)
		}
		return
	})
}

// MerchantIncoming 拉卡拉商户进件
// @Title 创建拉卡拉商户
// @Description 创建拉卡拉商户
// @Param	token			header		string	true	"认证token"
// @Param	payload			formData	string	true	"json数据，lakala.MerchantIncomingReq 对象"
// @Param	storeID			formData	int		true	"门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /MerchantIncoming [post]
func (c *LaKaLaController) MerchantIncoming() {
	c.callMerchantIncoming(func(params *tLakalaMerchantIncomingParams) (retVal interface{}, errCode string, err error) {
		incoming := &lakala.MerchantIncomingReq{}
		err = utils.UnmarshalUseNumber([]byte(params.Payload), incoming)
		if err != nil {
			return retVal, "", err
		}
		retVal, err = lakalaServer.LaKaLaInComing(params.Ctx, incoming, params.StoreID)
		return retVal, "", err
	})
}

// GetMerchant 获取进件商户详情
// @Title 获取进件商户详情
// @Description 获取进件商户详情
// @Param	token			header		string	true	"认证token"
// @Param	merchantNo		query		string	true	"商户号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMerchant [get]
func (c *LaKaLaController) GetMerchant() {
	c.callGetMerchant(func(params *tLakalaGetMerchantParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetMerchantInfo(params.MerchantNo)
		return
	})
}

// GetPosTerminalInfo 获取终端详情
// @Title 获取终端详情
// @Description 获取终端详情
// @Param	token			header		string	true	"认证token"
// @Param	posSN			query		string	true	"机具号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetPosTerminalInfo [get]
func (c *LaKaLaController) GetPosTerminalInfo() {
	c.callGetPosTerminalInfo(func(params *tLakalaGetPosTerminalInfoParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetPosTerimeInfo(params.PosSN)
		return
	})
}

// QueryCityCode 获取拉卡拉城市code
// @Title 获取拉卡拉城市code
// @Description 获取拉卡拉城市code
// @Param	token			header	string	true	"认证token"
// @Param	parentCode		query	string	true	"城市code,1获取全部城市code"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryCityCode [get]
func (c *LaKaLaController) QueryCityCode() {
	c.callQueryCityCode(func(params *tLakalaQueryCityCodeParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryCityCode(params.ParentCode)
		return retVal, "", err
	})
}

// QueryBankList 获取拉卡拉城市银行列表
// @Title 获取拉卡拉城市银行列表
// @Description 获取拉卡拉城市银行列表
// @Param	token			header	string	true	"认证token"
// @Param	areaCode		query	string	true	"城市code"
// @Param	bankName		query	string	false	"银行名称"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryBankList [get]
func (c *LaKaLaController) QueryBankList() {
	c.callQueryBankList(func(params *tLakalaQueryBankListParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryBankList(params.AreaCode, params.BankName)
		return retVal, "", err
	})
}

// QueryCustomerCategory 获取商户类别
// @Title 获取商户类别
// @Description 获取商户类别
// @Param	token				header	string	true	"认证token"
// @Param	businessScene		query	string	true	"B2B收银台和逸码通产品传1，其他传2"
// @Param	parentCode			query	string	false	"小类分类ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryCustomerCategory [get]
func (c *LaKaLaController) QueryCustomerCategory() {
	c.callQueryCustomerCategory(func(params *tLakalaQueryCustomerCategoryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetCustomerCategory(params.BusinessScene, params.ParentCode)
		return retVal, "", err
	})
}

// QueryCustomerFee 商户费率查询
// @Title 商户费率查询
// @Description 商户费率查询
// @Param	token				header	string	true	"认证token"
// @Param	customerNo			query	string	true	"商户ID"
// @Param	productCode			query	string	false	"产品类型"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryCustomerFee [get]
func (c *LaKaLaController) QueryCustomerFee() {
	c.callQueryCustomerFee(func(params *tLakalaQueryCustomerFeeParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.MerchantFeeQuery(params.CustomerNo, params.ProductCode)
		return retVal, "", err
	})
}

// CustomerFeeChange 商户费率信息变更
// @Title 商户费率信息变更
// @Description 商户费率信息变更
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			formData	string	true	"商户ID"
// @Param	payload				formData	string	true	"json数据，lakala.FeeChangeReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CustomerFeeChange [post]
func (c *LaKaLaController) CustomerFeeChange() {
	c.callCustomerFeeChange(func(params *tLakalaCustomerFeeChangeParams) (retVal interface{}, errCode string, err error) {
		fee := &lakala.FeeChangeReq{}
		err = utils.UnmarshalUseNumber([]byte(params.Payload), fee)
		if err != nil {
			return retVal, "", err
		}

		changeID, changeStatus, err := lakalaServer.MerchantFeeChange(fee, params.CustomerNo)
		return map[string]string{"id": utils.Int64ToStr(changeID), "status": changeStatus}, "", err
	})
}

// CustomerSettleFee 商户结算信息变更/查询
// @Title 商户结算信息已经变更接口
// @Description 当payload为空时视为查询,不为空则是变更信息
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			formData	string	true	"商户ID"
// @Param	payload				formData	string	false	"json数据，lakala.UpdateSettleInfoReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CustomerSettleFee [post]
func (c *LaKaLaController) CustomerSettleFee() {
	c.callCustomerSettleFee(func(params *tLakalaCustomerSettleFeeParams) (retVal interface{}, errCode string, err error) {
		var settle *lakala.UpdateSettleInfoReq
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), &settle); err != nil {
				return retVal, "", err
			}
		}

		queryInfo, updateStatus, err := lakalaServer.UpdateSettleInfo(params.CustomerNo, settle)
		if params.Payload != "" {
			return updateStatus, "", err
		} else {
			return queryInfo, "", err
		}
	})
}

// UpdateBasicInfo 商户基本信息变更
// @Title 商户基本信息变更
// @Description 商户基本信息变更
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			formData	string	true	"商户ID"
// @Param	payload				formData	string	true	"json数据，lakala.UpdateBaseInfoReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateBasicInfo [post]
func (c *LaKaLaController) UpdateBasicInfo() {
	c.callUpdateBasicInfo(func(params *tLakalaUpdateBasicInfoParams) (retVal interface{}, errCode string, err error) {
		basic := &lakala.UpdateBaseInfoReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), basic); err != nil {
				return retVal, "", err
			}
		}
		basicStatus, err := lakalaServer.MerchantUpdateBaseInfo(params.CustomerNo, basic)

		return basicStatus, "", err
	})
}

// QueryExamine 查询变更事件审核状态
// @Title 查询变更事件审核状态
// @Description 查询变更事件审核状态
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			query		string	true	"商户ID"
// @Param	reviewRelatedId		query		string	true	"变更事件ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryExamine [get]
func (c *LaKaLaController) QueryExamine() {
	c.callQueryExamine(func(params *tLakalaQueryExamineParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryExamine(params.CustomerNo, params.ReviewRelatedId)
		return
	})
}

// CheckIsUploadPhoto 检查门店是否需要补充照片
// @Title 检查门店是否需要补充照片
// @Description 检查门店是否需要补充照片
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			query		string	true	"商户ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CheckIsUploadPhoto [get]
func (c *LaKaLaController) CheckIsUploadPhoto() {
	c.callCheckIsUploadPhoto(func(params *tLakalaCheckIsUploadPhotoParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.CheckIsUploadPhoto(params.CustomerNo)
		return
	})
}

// ImgSupplement 补充门店照片
// @Title 补充门店照片
// @Description 补充门店照片
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.ImgSupplementReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ImgSupplement [post]
func (c *LaKaLaController) ImgSupplement() {
	c.callImgSupplement(func(params *tLakalaImgSupplementParams) (retVal interface{}, errCode string, err error) {
		imgs := &lakala.ImgSupplementReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), imgs); err != nil {
				return nil, "", err
			}
		}

		err = lakalaServer.ImgSupplement(imgs)
		return retVal, errCode, err
	})
}

// GetMerchantReportStatus 查看银联报备状态
// @Title 查看银联报备状态
// @Description 查看银联报备状态
// @Param	token				header		string	true	"认证token"
// @Param	customerNo			query		string	true	"商户ID"
// @Param	agentNo				query		string	true	"代理商编号"
// @Param	orgCode				query		string	true	"机构号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMerchantReportStatus [get]
func (c *LaKaLaController) GetMerchantReportStatus() {
	c.callGetMerchantReportStatus(func(params *tLakalaGetMerchantReportStatusParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetMerchantReportStatus(params.OrgCode, params.AgentNo, params.CustomerNo)
		return
	})
}

// GetMerchantTerminal 获取终端报备信息
// @Title 获取终端报备信息
// @Description 获取终端报备信息
// @Param	token				header		string	true	"认证token"
// @Param	agentNo				query		string	true	"代理商编号"
// @Param	orgCode				query		string	true	"机构号"
// @Param	customerNo			query		string	true	"商户ID"
// @Param	posSn				query		string	true	"机具序列号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMerchantTerminal [get]
func (c *LaKaLaController) GetMerchantTerminal() {
	c.callGetMerchantTerminal(func(params *tLakalaGetMerchantTerminalParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetMerchantTerminal(params.OrgCode, params.AgentNo, params.CustomerNo, params.PosSn)
		return
	})
}

// SupplementBusinessLicense 营业执照变更
// @Title 营业执照变更
// @Description 营业执照变更
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.BusinessLicenseReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SupplementBusinessLicense [post]
func (c *LaKaLaController) SupplementBusinessLicense() {
	c.callSupplementBusinessLicense(func(params *tLakalaSupplementBusinessLicenseParams) (retVal interface{}, errCode string, err error) {
		license := &lakala.BusinessLicenseReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), license); err != nil {
				return nil, "", err
			}
		}
		retVal, err = lakalaServer.SupplementBusinessLicense(license)
		return
	})
}

// UnionPayMerInfo 联防机制查询(失信人)
// @Title 联防机制查询(失信人)
// @Description 联防机制查询(失信人)
// @Param	token				header		string	true	"认证token"
// @Param	larName				query		string	true	"身份证名称"
// @Param	larIdCard			query		string	true	"身份证ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UnionPayMerInfo [get]
func (c *LaKaLaController) UnionPayMerInfo() {
	c.callUnionPayMerInfo(func(params *tLakalaUnionPayMerInfoParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.UnionPayMerInfo(params.LarName, params.LarIdCard)
		return
	})
}

// CreateSeparate 创建分账账户
// @Title 创建分账账户
// @Description 创建分账账户
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.CreateSeparateReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateSeparate [post]
func (c *LaKaLaController) CreateSeparate() {
	c.callCreateSeparate(func(params *tLakalaCreateSeparateParams) (retVal interface{}, errCode string, err error) {
		separateCreate := &lakala.CreateSeparateReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), separateCreate); err != nil {
				return nil, "", err
			}
		}
		retVal, err = lakalaServer.CreateSeparate(separateCreate)
		return
	})
}

// SeparateModify 变更分账账户
// @Title 变更分账账户
// @Description 变更分账账户
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.SeparateModifyReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateModify [post]
func (c *LaKaLaController) SeparateModify() {
	c.callSeparateModify(func(params *tLakalaSeparateModifyParams) (retVal interface{}, errCode string, err error) {
		separateUpdate := &lakala.SeparateModifyReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), separateUpdate); err != nil {
				return nil, "", err
			}
		}
		retVal, err = lakalaServer.SeparateModify(separateUpdate)
		return
	})
}

// SeparateQuery 分账商户查询
// @Title 分账商户查询
// @Description 分账商户查询
// @Param	token				header		string	true	"认证token"
// @Param	merInnerNo			query		string	true	"商户号"
// @Param	orgCode				query		string	true	"机构代码"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateQuery [get]
func (c *LaKaLaController) SeparateQuery() {
	c.callSeparateQuery(func(params *tLakalaSeparateQueryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SeparateQuery(params.MerInnerNo, params.OrgCode)
		return
	})
}

// CreateSeparateRecipient 创建分账接收方
// @Title 创建分账接收方
// @Description 创建分账接收方
// @Param	payload				formData	string	true	"json数据，lakala.CreateSeparateRecipientReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateSeparateRecipient [post]
func (c *LaKaLaController) CreateSeparateRecipient() {
	c.callCreateSeparateRecipient(func(params *tLakalaCreateSeparateRecipientParams) (retVal interface{}, errCode string, err error) {
		separateUpdate := &lakala.CreateSeparateRecipientReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), separateUpdate); err != nil {
				return nil, "", err
			}
		}

		retVal, err = lakalaServer.CreateSeparateRecipient(params.Ctx, separateUpdate)
		return
	})
}

// UpdateSeparateRecipient 修改分账接收方
// @Title 修改分账接收方
// @Description 修改分账接收方
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.UpdateSeparateRecipientReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateSeparateRecipient [post]
func (c *LaKaLaController) UpdateSeparateRecipient() {
	c.callUpdateSeparateRecipient(func(params *tLakalaUpdateSeparateRecipientParams) (retVal interface{}, errCode string, err error) {
		separateUpdate := &lakala.UpdateSeparateRecipientReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), separateUpdate); err != nil {
				return nil, "", err
			}
		}

		retVal, err = lakalaServer.UpdateSeparateRecipient(separateUpdate)
		return
	})
}

// QuerySeparateRecipient 分账商户查询
// @Title 分账商户查询
// @Description 分账商户查询
// @Param	token				header		string	true	"认证token"
// @Param	receiverNo			query		string	true	"商户号"
// @Param	orgCode				query		string	true	"机构代码"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QuerySeparateRecipient [get]
func (c *LaKaLaController) QuerySeparateRecipient() {
	c.callQuerySeparateRecipient(func(params *tLakalaQuerySeparateRecipientParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QuerySeparateRecipient(params.OrgCode, params.ReceiverNo)
		return
	})
}

// ApplyBind 分账关系申请绑定
// @Title 分账关系申请绑定
// @Description 分账关系申请绑定
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.SeparateApplyBindReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ApplyBind [post]
func (c *LaKaLaController) ApplyBind() {
	c.callApplyBind(func(params *tLakalaApplyBindParams) (retVal interface{}, errCode string, err error) {
		bind := &lakala.SeparateApplyBindReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), bind); err != nil {
				return nil, "", err
			}
		}
		retVal, err = lakalaServer.ApplyBind(bind)
		return
	})
}

// SeparateUnBind 分账关系申请解绑
// @Title 分账关系申请解绑
// @Description 分账关系申请解绑
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.SeparateUnBindReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateUnBind [post]
func (c *LaKaLaController) SeparateUnBind() {
	c.callSeparateUnBind(func(params *tLakalaSeparateUnBindParams) (retVal interface{}, errCode string, err error) {
		unBind := &lakala.SeparateUnBindReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), unBind); err != nil {
				return nil, "", err
			}
		}
		err = lakalaServer.SeparateUnBind(unBind)
		return
	})
}

// SeparateQueryAmt 可分账金额查询
// @Title 可分账金额查询
// @Description 可分账金额查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	logDate				query		string	true	"拉卡拉对账单交易日期[yyyyMMdd]"
// @Param	logNo 				query		string	true	"交易流水号"
// @Param	vendorOrderId 		query		string	true	"京西订单号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateQueryAmt [get]
func (c *LaKaLaController) SeparateQueryAmt() {
	c.callSeparateQueryAmt(func(params *tLakalaSeparateQueryAmtParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SeparateQueryAmt(params.Ctx, params.MerchantNo, params.LogDate, params.LogNo, params.VendorOrderId)
		return
	})
}

// SeparateAmt 分账
// @Title 分账
// @Description 分账
// @Param	token				header			string	true	"认证token"
// @Param	payload				formData		string	true	"json数据，lakala.OrderSeparateReq 对象"
// @Param	vendorOrderId 		formData		string	true	"京西订单号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateAmt [post]
func (c *LaKaLaController) SeparateAmt() {
	c.callSeparateAmt(func(params *tLakalaSeparateAmtParams) (retVal interface{}, errCode string, err error) {
		amt := &lakala.OrderSeparateReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), amt); err != nil {
				return nil, "", err
			}
		}
		retVal, err = lakalaServer.Separate(params.Ctx, amt, params.VendorOrderId)
		return
	})
}

// SeparateResultQuery 分账结果查询(也会刷新本地数据)
// @Title 分账结果查询
// @Description 分账结果查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	separateNo			query		string	true	"拉卡拉分账指令流水号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateResultQuery [get]
func (c *LaKaLaController) SeparateResultQuery() {
	c.callSeparateResultQuery(func(params *tLakalaSeparateResultQueryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SeparateResultQuery(params.MerchantNo, params.SeparateNo)
		return
	})
}

// SeparateCancel 分账撤销
// @Title 分账撤销
// @Description 分账撤销
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	separateNo			query		string	true	"拉卡拉分账指令流水号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateCancel [get]
func (c *LaKaLaController) SeparateCancel() {
	c.callSeparateCancel(func(params *tLakalaSeparateCancelParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SeparateCancel(params.MerchantNo, params.SeparateNo)
		return
	})
}

// SeparateFallBack 分账退回
// @Title 分账退回
// @Description 分账退回
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	separateNo			query		string	true	"拉卡拉分账指令流水号"
// @Param	reason				query		string	true	"退回原因"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SeparateFallBack [get]
func (c *LaKaLaController) SeparateFallBack() {
	c.callSeparateFallBack(func(params *tLakalaSeparateFallBackParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SeparateFallBack(params.MerchantNo, params.SeparateNo, params.Reason)
		return
	})
}

// CreateOrder 创建拉卡拉支付订单
// @Title 创建拉卡拉支付订单
// @Description 创建拉卡拉支付订单
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	vendorOrderId		query		string	true	"订单号"
// @Param	vendorId			query		int		true	"平台id"
// @Param	callbackUrl			query		string	false   "支付后打开地址"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateOrder [get]
func (c *LaKaLaController) CreateOrder() {
	c.callCreateOrder(func(params *tLakalaCreateOrderParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.CreateOrder(params.Ctx, params.VendorOrderId, params.MerchantNo, params.CallbackUrl, params.VendorId)
		return
	})
}

// CloseOrder 关闭支付订单
// @Title 关闭支付订单
// @Description 关闭支付订单
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	vendorOrderId		query		string	true	"订单号"
// @Param	vendorId			query		int		true	"平台id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CloseOrder [get]
func (c *LaKaLaController) CloseOrder() {
	c.callCloseOrder(func(params *tLakalaCloseOrderParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.CloseOrder(params.MerchantNo, params.VendorOrderId, params.VendorId)
		return
	})
}

// QueryOrder 收银台订单查询
// @Title 收银台订单查询
// @Description 收银台订单查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	vendorOrderId		query		string	true	"订单号"
// @Param	vendorId			query		int		true	"平台id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryOrder [get]
func (c *LaKaLaController) QueryOrder() {
	c.callQueryOrder(func(params *tLakalaQueryOrderParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryOrder(params.VendorOrderId, params.MerchantNo, params.VendorId)
		return
	})
}

// QueryBillBalance 账户余额查询
// @Title 账户余额查询
// @Description 账户余额查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	orgNo				query		string	true	"bmcp机构号"
// @Param	payType				query		string	true	"平台id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryBillBalance [get]
func (c *LaKaLaController) QueryBillBalance() {
	c.callQueryBillBalance(func(params *tLakalaQueryBillBalanceParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryBillBalance(params.OrgNo, params.MerchantNo, params.PayType)
		return
	})
}

// EwalletWithdrawD1 账户金额提现
// @Title 账户金额提现
// @Description 账户金额提现
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	orgNo				query		string	true	"bmcp机构号"
// @Param	payType				query		string	true	"平台id"
// @Param	drawAmt				query		string	true	"提现金额(元)"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /EwalletWithdrawD1 [get]
func (c *LaKaLaController) EwalletWithdrawD1() {
	c.callEwalletWithdrawD1(func(params *tLakalaEwalletWithdrawD1Params) (retVal interface{}, errCode string, err error) {
		err = lakalaServer.EwalletWithdrawD1(params.Ctx, params.OrgNo, params.MerchantNo, params.PayType, params.DrawAmt)
		return
	})
}

// EwalletWithdrawQuery 提现结果查询
// @Title 提现结果查询
// @Description 提现结果查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	orgNo				query		string	true	"bmcp机构号"
// @Param	drawJnl				query		string	true	"提现流水号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /EwalletWithdrawQuery [get]
func (c *LaKaLaController) EwalletWithdrawQuery() {
	c.callEwalletWithdrawQuery(func(params *tLakalaEwalletWithdrawQueryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.EwalletWithdrawQuery(params.Ctx, params.OrgNo, params.MerchantNo, params.DrawJnl)
		return
	})
}

// SettleDrawPattern 提款模式设置
// @Title 提款模式设置
// @Description 提款模式设置
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.SettleDrawPatternReq 对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SettleDrawPattern [post]
func (c *LaKaLaController) SettleDrawPattern() {
	c.callSettleDrawPattern(func(params *tLakalaSettleDrawPatternParams) (retVal interface{}, errCode string, err error) {
		settle := &lakala.SettleDrawPatternReq{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), settle); err != nil {
				return nil, "", err
			}
		}

		err = lakalaServer.SettleDrawPattern(settle)
		return
	})
}

// EwalletSettleQuery 提款模式查询
// @Title 提款模式查询
// @Description 提款模式查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	true	"商户号"
// @Param	orgNo				query		string	true	"bmcp机构号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /EwalletSettleQuery [get]
func (c *LaKaLaController) EwalletSettleQuery() {
	c.callEwalletSettleQuery(func(params *tLakalaEwalletSettleQueryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.EwalletSettleQuery(params.OrgNo, params.MerchantNo)
		return
	})
}

// UploadImg 图片上传
// @Title 图片上传
// @Description 图片上传
// @Param	token				header			string	true	"认证token"
// @Param	file				formData		string	true	"url"
// @Param	imgType				formData		string	true	"图片类型"
// @Param	sourcechnl			formData		string	true	"来源"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UploadImg [post]
func (c *LaKaLaController) UploadImg() {
	c.callUploadImg(func(params *tLakalaUploadImgParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.UploadImg(params.File, params.ImgType, params.Sourcechnl, "false")
		return
	})
}

// UploadAttachmentImg 图片上传
// @Title 图片上传
// @Description 图片上传
// @Param	token				header			string	true	"认证token"
// @Param	orgCode				formData		string	true	"机构代码"
// @Param	attType				formData		string	true	"附件类型"
// @Param	attExtName			formData		string	true	"附件扩展名称"
// @Param	attContext			formData		string	true	"附件内容	"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UploadAttachmentImg [post]
func (c *LaKaLaController) UploadAttachmentImg() {
	c.callUploadAttachmentImg(func(params *tLakalaUploadAttachmentImgParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.UploadAttachmentImg(params.OrgCode, params.AttType, params.AttExtName, params.AttContext)
		return
	})
}

// QueryIncoming 进件查询
// @Title 进件查询
// @Description 进件查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	false	"商户号"
// @Param	storeID				query		int		false	"门店ID"
// @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 /QueryIncoming [get]
func (c *LaKaLaController) QueryIncoming() {
	c.callQueryIncoming(func(params *tLakalaQueryIncomingParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetIncomingList(params.MerchantNo, params.StoreID, params.PageSize, params.Offset)
		return
	})
}

// GetRecipient 分账账户查询
// @Title 分账账户查询
// @Description 分账账户查询
// @Param	token				header		string	true	"认证token"
// @Param	OrgCode				query		string	false	"申请机构代码"
// @Param	ReceiverNo			query		string	false	"接收方编号"
// @Param	ReceiverName		query		string	false	"接收方名称"
// @Param	offset				query		int		true	"列表起始序号（以0开始，缺省为0）"
// @Param	pageSize			query		int		true	"列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetRecipient [get]
func (c *LaKaLaController) GetRecipient() {
	c.callGetRecipient(func(params *tLakalaGetRecipientParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetRecipientList(params.OrgCode, params.ReceiverNo, params.ReceiverName, params.Offset, params.PageSize)
		return
	})
}

// GetSeparateAmt 分账记录查询
// @Title 分账记录查询
// @Description 分账记录查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	false	"商户号"
// @Param	cmdType				query		string	false	"流水类型[SEPARATE：分账 CANCEL：分账撤销FALLBACK：分账回退]"
// @Param	status				query		string	false	"分账状态"
// @Param	separateNo			query		string	false	"分账流水号"
// @Param	separateTimeStart	query		string	false	"开始交易时间[yyyy-mm-dd hh:mm:ss]"
// @Param	separateTimeEnd		query		string	false	"结束交易时间[yyyy-mm-dd hh:mm:ss]"
// @Param	vendorOrderId		query		string	false	"订单ID"
// @Param	storeId				query		int		false	"门店ID"
// @Param	offset				query		int		true	"列表起始序号（以0开始，缺省为0）"
// @Param	pageSize			query		int		true	"列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetSeparateAmt [get]
func (c *LaKaLaController) GetSeparateAmt() {
	c.callGetSeparateAmt(func(params *tLakalaGetSeparateAmtParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetSeparateAmt(params.MerchantNo, params.CmdType, params.Status, params.SeparateNo, params.SeparateTimeStart, params.SeparateTimeEnd, params.VendorOrderId, params.StoreId, params.Offset, params.PageSize)
		return
	})
}

// WithdrawalList 提现流水查询
// @Title 提现流水查询
// @Description 提现流水查询
// @Param	token				header		string	true	"认证token"
// @Param	merchantNo			query		string	false	"商户号"
// @Param	drawJnl				query		string	false	"订单号"
// @Param	acctName			query		string	false	"账户名"
// @Param	startTime			query		string	false	"开始交易时间[yyyy-mm-dd hh:mm:ss]"
// @Param	endTime				query		string	false	"结束交易时间[yyyy-mm-dd hh:mm:ss]"
// @Param	separateNo			query		string	false	"分账流水号"
// @Param	offset				query		int		true	"列表起始序号（以0开始，缺省为0）"
// @Param	pageSize			query		int		true	"列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /WithdrawalList [get]
func (c *LaKaLaController) WithdrawalList() {
	c.callWithdrawalList(func(params *tLakalaWithdrawalListParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.WithdrawalList(params.MerchantNo, params.DrawJnl, params.AcctName, params.StartTime, params.EndTime, params.PageSize, params.PageSize)
		return
	})
}

// QueryApplyContractList 门店合同申请记录查询
// @Title 门店合同申请记录查询
// @Description 门店合同申请记录查询
// @Param	token				header		string	true	"认证token"
// @Param	storeId				query		int		false	"门店ID"
// @Param	orderNo				query		string	false	"京西订单ID"
// @Param	offset				query		int		true	"列表起始序号（以0开始，缺省为0）"
// @Param	pageSize			query		int		true	"列表页大小（缺省为50，-1表示全部）"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryApplyContractList [get]
func (c *LaKaLaController) QueryApplyContractList() {
	c.callQueryApplyContractList(func(params *tLakalaQueryApplyContractListParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.QueryApplyContractList(params.OrderNo, params.StoreId, params.PageSize, params.Offset)
		return
	})
}

// GetCardBin 卡BIN查询
// @Title 卡BIN查询
// @Description 卡BIN查询
// @Param	token				header		string	true	"认证token"
// @Param	orgCode				query		string	true	"机构号"
// @Param	cardNo				query		string	true	"卡号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetCardBin [get]
func (c *LaKaLaController) GetCardBin() {
	c.callGetCardBin(func(params *tLakalaGetCardBinParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.GetCardBin(params.OrgCode, params.CardNo)
		return
	})
}

// SaveAuthentication 微信支付宝认证
// @Title 微信支付宝认证
// @Description 微信支付宝认证
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.AuthenticationInfo 对象"
// @Param	authType			formData	string	true	"支付类型[支付宝传:ZFBZF(其他类型不传)]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SaveAuthentication [post]
func (c *LaKaLaController) SaveAuthentication() {
	c.callSaveAuthentication(func(params *tLakalaSaveAuthenticationParams) (retVal interface{}, errCode string, err error) {
		authentic := &lakala.AuthenticationInfo{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), authentic); err != nil {
				return nil, "", err
			}
		}

		err = lakalaServer.SaveAuthentication(authentic, params.AuthType)
		return
	})
}

// UpdateAuthentication 微信支付宝修改认证
// @Title 微信支付宝修改认证
// @Description 微信支付宝修改认证
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.AuthenticationInfo 对象"
// @Param	authType			formData	string	true	"支付类型[支付宝传:ZFBZF(其他类型不传)]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateAuthentication [post]
func (c *LaKaLaController) UpdateAuthentication() {
	c.callUpdateAuthentication(func(params *tLakalaUpdateAuthenticationParams) (retVal interface{}, errCode string, err error) {
		authentic := &lakala.UpdateAuthentication{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), authentic); err != nil {
				return nil, "", err
			}
		}

		err = lakalaServer.UpdateAuthentication(authentic, params.AuthType)
		return
	})
}

// QueryAuthentication 认证状态查询
// @Title 认证状态查询
// @Description 认证状态查询
// @Param	token				header		string	true	"认证token"
// @Param	payload				formData	string	true	"json数据，lakala.QueryAuthentication 对象"
// @Param	authType			formData	string	true	"支付类型[支付宝传:ZFBZF(其他类型不传)]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QueryAuthentication [post]
func (c *LaKaLaController) QueryAuthentication() {
	c.callQueryAuthentication(func(params *tLakalaQueryAuthenticationParams) (retVal interface{}, errCode string, err error) {
		authentic := &lakala.QueryAuthentication{}
		if params.Payload != "" {
			if err = utils.UnmarshalUseNumber([]byte(params.Payload), authentic); err != nil {
				return nil, "", err
			}
		}

		retVal, err = lakalaServer.QueryAuthentication(authentic, params.AuthType)
		return
	})
}

// AccountStatusQuery 开户状态查询
// @Title 开户状态查询
// @Description 开户状态查询
// @Param	token				header		string	true	"认证token"
// @Param	tradeMode			query		string	true	"支付类型交易钱包类型[ALIPAY，WECHAT]"
// @Param	subMerchantId		query		string	true	"子商户号"
// @Param	merchantNo			query		string	true	"商户号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /AccountStatusQuery [get]
func (c *LaKaLaController) AccountStatusQuery() {
	c.callAccountStatusQuery(func(params *tLakalaAccountStatusQueryParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.AccountStatusQuery(params.TradeMode, params.SubMerchantId, params.MerchantNo)
		return
	})
}

// QuerySubMerInfo 商户报备查询
// @Title 商户报备查询
// @Description 商户报备查询
// @Param	token				header		string	true	"认证token"
// @Param	merCupNo			query		string	false	"银联商户号(二选一填写)"
// @Param	merInnerNo			query		string	false	"内部商户号(二选一填写)"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /QuerySubMerInfo [get]
func (c *LaKaLaController) QuerySubMerInfo() {
	c.callQuerySubMerInfo(func(params *tLakalaQuerySubMerInfoParams) (retVal interface{}, errCode string, err error) {
		retVal, err = lakalaServer.SubMerchantInfoQuery(params.MerInnerNo, params.MerCupNo)
		return
	})
}

// CloseOrderByMini 聚合支付关单
// @Title 聚合支付关单
// @Description 聚合支付关单
// @Param	token				header			string	true	"认证token"
// @Param	merCupNo			formData		string	true	"银联商户号"
// @Param	termNo				formData		string	true	"设备号"
// @Param	orderNo				formData		string	true	"订单号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CloseOrderByMini [post]
func (c *LaKaLaController) CloseOrderByMini() {
	c.callCloseOrderByMini(func(params *tLakalaCloseOrderByMiniParams) (retVal interface{}, errCode string, err error) {
		err = lakalaServer.CloseOrderByMini(params.MerCupNo, params.TermNo, params.OrderNo, params.Ctx.GetRealRemoteIP())
		return
	})
}

//
//// AggregateRefundOrder 聚合支付退款
//// @Title 聚合支付退款
//// @Description 聚合支付退款
//// @Param	token				header		string	true	"认证token"
//// @Param	vendorOrderID		formData	string	true	"订单ID"
//// @Param	skuIds				formData	string	true	"[key:value]退款商品 skuId:count,int"
//// @Param	Reason				formData	string	false	"退单原因"
//// @Success 200 {object} controllers.CallResult
//// @Failure 200 {object} controllers.CallResult
//// @router /AggregateRefundOrder [post]
//func (c *LaKaLaController) AggregateRefundOrder() {
//	c.callAggregateRefundOrder(func(params *tLakalaAggregateRefundOrderParams) (retVal interface{}, errCode string, err error) {
//		skuIds := make(map[int]int, 0)
//		if err = json.Unmarshal([]byte(params.SkuIds), &skuIds); err != nil {
//			return nil, "", err
//		}
//
//		retVal, err = localjx.RefundBarCodeScannerOrderByLaKaLa(params.Ctx, params.VendorOrderID, skuIds, params.Reason, "aggregate")
//		return
//	})
//}
