/**
* @Author: zou.yingbin
* @Create  : 2021/6/24 10:32
* @Modify  : 2021/6/24 10:32
 */

package qhjPCWeb

import (
	"github.com/gin-gonic/gin"
	"mtp2_if/global/app"
	"mtp2_if/models"
)

// QuerySubArea
// @Summary 查询子机构列表
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.QhjMgrSubArea
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QuerySubArea [get]
// @Tags 大连千海金(PCWeb)
func QuerySubArea(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID int64 `form:"userid" binding:"required"` // 用户id
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrSubArea{USERID: req.USERID}
	a.DoGetDataI(&m)
}

// QueryCustomerInfo
// @Summary 查询客户资料
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param querytype query int true "查询类型 1:未提交(网上开户表) 2:待审核(网上开户表) 3:正常 4:停用"
// @Param userinfotype query int false "客户类型 1-个人 2-企业"
// @Param customername query string false "客户名称(模糊匹配)"
// @Param nickname query string false "昵称(模糊匹配)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrCustomer
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryCustomerInfo [get]
// @Tags 大连千海金(PCWeb)
func QueryCustomerInfo(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid" binding:"required"`                // 用户id
		QUERYTYPE    int32  `form:"querytype" binding:"required,min=1,max=4"` // 查询类型
		USERINFOTYPE int32  `form:"userinfotype"`                             // 客户类型
		CUSTOMERNAME string `form:"customername"`                             // 客户名称
		NICKNAME     string `form:"nickname"`                                 // 昵称
		INCLUDESUB   int32  `form:"includesub"`                               // 是否包含子级
	}{}
	a.DoBindReq(&req)
	// Tips: 手机号码是加密存储的, 做不了模糊匹配, 加了又去掉了
	m := models.QhjMgrCustomer{USERID: req.USERID, USERINFOTYPE: req.USERINFOTYPE, QUERYTYPE: req.QUERYTYPE,
		CUSTOMERNAME: req.CUSTOMERNAME, NICKNAME: req.NICKNAME, IncludeSub: req.INCLUDESUB}
	a.DoGetDataI(&m)
}

// QueryAccountInOutApply
// @Summary 查询充值提现
// @Produce json
// @Security ApiKeyAuth
// @Param querytype query int true "查询类型 1-提现(出金) 2-充值(出金)"
// @Param applystatus query int false "状态 1-待审核 2-审核通过 3-审核拒绝"
// @Param begindate query string false "申请起始日期(格式yyyymmdd)"
// @Param enddate query string false "申请截止日期(格式yyyymmdd)"
// @Param likename query string false "模糊搜索名称"
// @Success 200 {array} models.QhjMgrAccountOutInApply
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryAccountInOutApply [get]
// @Tags 大连千海金(PCWeb)
func QueryAccountInOutApply(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		BEGINDATE   string `form:"begindate"`   // 开始申请日期
		ENDDATE     string `form:"enddate"`     // 结束申请日期
		LIKENAME    string `form:"likename"`    // 模糊搜索名称
		QUERYTYPE   int32  `form:"querytype"`   // 查询类型
		APPLYSTATUS int32  `form:"applystatus"` // 状态 1-待审核 2-审核通过 3-审核拒绝
	}{}
	a.DoBindReq(&req)
	a.CheckParamF(func() bool {
		if len(req.BEGINDATE) > 0 && len(req.BEGINDATE) != 8 {
			return false
		}
		if len(req.ENDDATE) > 0 && len(req.ENDDATE) != 8 {
			return false
		}
		for i := range req.BEGINDATE {
			if req.BEGINDATE[i] < '0' || req.BEGINDATE[i] > '9' {
				return false
			}
		}
		for i := range req.ENDDATE {
			if req.ENDDATE[i] < '0' || req.ENDDATE[i] > '9' {
				return false
			}
		}
		return true
	})
	m := models.QhjMgrAccountOutInApply{BeginDate: req.BEGINDATE, EndDate: req.ENDDATE, FilterName: req.LIKENAME,
		QUERYTYPE: req.QUERYTYPE, STATUS: req.APPLYSTATUS}
	a.DoGetDataI(&m)
}

// QueryTradePosition
// @Summary 查询持仓汇总
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param userinfotype query int false "用户类型 1-个人 2-企业"
// @Param trademode query int false "交易模式"
// @Param goodsid query int false "商品id"
// @Param filtername query string false "名称(模糊搜索账户)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrPositionRsp
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryTradePosition [get]
// @Tags 大连千海金(PCWeb)
func QueryTradePosition(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid" binding:"required"` // 用户id
		USERINFOTYPE int32  `form:"userinfotype"`
		FILTERNAME   string `form:"filtername"`
		GOODSID      int32  `form:"goodsid"`
		INCLUDESUB   int32  `form:"includesub"`
		TRADEMODE    int32  `form:"trademode"`
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrTradePosition{}
	m.USERID, m.FilterName = req.USERID, req.FILTERNAME
	m.USERINFOTYPE, m.GOODSID = req.USERINFOTYPE, req.GOODSID
	m.IncludeSub, m.TRADEMODE = req.INCLUDESUB, req.TRADEMODE
	a.DoGetDataI(&m)
}

// QueryTradeDetail
// @Summary 查询成交明细
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param userinfotype query int false "用户类型 1-个人 2-企业"
// @Param trademode query int false "交易模式"
// @Param goodsid query int false "商品id"
// @Param filtername query string false "名称(模糊搜索账户)"
// @Param begindate query string false "开始交易日(yyyymmdd)"
// @Param enddate query string false "结束交易日(yyyymmdd)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrTradeDetailRsp
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryTradeDetail [get]
// @Tags 大连千海金(PCWeb)
func QueryTradeDetail(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid" binding:"required"` // 用户id
		USERINFOTYPE int32  `form:"userinfotype"`
		FILTERNAME   string `form:"filtername"`
		GOODSID      int32  `form:"goodsid"`
		INCLUDESUB   int32  `form:"includesub"`
		BEGINDATE    string `form:"begindate"`
		ENDDATE      string `form:"enddate"`
		TRADEMODE    int32  `form:"trademode"`
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrTradeDetail{}
	m.USERID, m.FilterName = req.USERID, req.FILTERNAME
	m.USERINFOTYPE, m.GOODSID = req.USERINFOTYPE, req.GOODSID
	m.IncludeSub, m.TRADEMODE = req.INCLUDESUB, req.TRADEMODE
	m.BeginDate, m.EndDate = req.BEGINDATE, req.ENDDATE
	a.DoGetDataI(&m)
}

// QueryTradeOrderDetail
// @Summary 查询委托明细
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param userinfotype query int false "用户类型 1-个人 2-企业"
// @Param trademode query int false "交易模式"
// @Param goodsid query int false "商品id"
// @Param filtername query string false "名称(模糊搜索账户)"
// @Param begindate query string false "开始交易日(yyyymmdd)"
// @Param enddate query string false "结束交易日(yyyymmdd)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrTradeOrderDetailRsp
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryTradeOrderDetail [get]
// @Tags 大连千海金(PCWeb)
func QueryTradeOrderDetail(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid" binding:"required"` // 用户id
		USERINFOTYPE int32  `form:"userinfotype"`
		FILTERNAME   string `form:"filtername"`
		GOODSID      int32  `form:"goodsid"`
		INCLUDESUB   int32  `form:"includesub"`
		BEGINDATE    string `form:"begindate"`
		ENDDATE      string `form:"enddate"`
		TRADEMODE    int32  `form:"trademode"`
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrTradeOrderDetail{}
	m.USERID, m.FilterName = req.USERID, req.FILTERNAME
	m.USERINFOTYPE, m.GOODSID = req.USERINFOTYPE, req.GOODSID
	m.IncludeSub, m.TRADEMODE = req.INCLUDESUB, req.TRADEMODE
	m.BeginDate, m.EndDate = req.BEGINDATE, req.ENDDATE
	a.DoGetDataI(&m)
}

// QueryTradePayOrder
// @Summary 查询待付款单
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param payflag query string false "付款标识(逗号隔开,如1,2) - 1:未支付 2:已支付 3:已过期 4:已撤销 5:结算过期 6:预售终止"
// @Param userinfotype query int false "用户类型 1-个人 2-企业"
// @Param trademode query int false "交易模式"
// @Param goodsid query int false "商品id"
// @Param filtername query string false "名称(模糊搜索账户)"
// @Param begindate query string false "开始交易日(yyyymmdd)"
// @Param enddate query string false "结束交易日(yyyymmdd)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrTradePayOrder
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryTradePayOrder [get]
// @Tags 大连千海金(PCWeb)
func QueryTradePayOrder(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid" binding:"required"` // 用户id
		USERINFOTYPE int32  `form:"userinfotype"`
		FILTERNAME   string `form:"filtername"`
		GOODSID      int32  `form:"goodsid"`
		INCLUDESUB   int32  `form:"includesub"`
		BEGINDATE    string `form:"begindate"`
		ENDDATE      string `form:"enddate"`
		TRADEMODE    int32  `form:"trademode"`
		PAYFLAG      string `form:"payflag"`
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrTradePayOrder{}
	m.USERID, m.FilterName = req.USERID, req.FILTERNAME
	m.USERINFOTYPE, m.GOODSID = req.USERINFOTYPE, req.GOODSID
	m.IncludeSub, m.TRADEMODE = req.INCLUDESUB, req.TRADEMODE
	m.BeginDate, m.EndDate = req.BEGINDATE, req.ENDDATE
	m.FilterPayFlag = req.PAYFLAG
	a.DoGetDataI(&m)
}

// QueryContract
// @Summary 查询融资信息(合同)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int false "用户ID"
// @Param goodsid query int false "商品id"
// @Param filtername query string false "名称(模糊搜索账户)"
// @Param risklevel query string false "风险级别(逗号隔开) - 1:正常 2:追加货款 3:支付尾款"
// @Param begindate query string false "开始交易日(yyyymmdd)"
// @Param enddate query string false "结束交易日(yyyymmdd)"
// @Success 200 {array} models.QhjMgrContract
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryContract [get]
// @Tags 大连千海金(PCWeb)
func QueryContract(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID       int64  `form:"userid"` // 用户id
		USERINFOTYPE int32  `form:"userinfotype"`
		FILTERNAME   string `form:"filtername"`
		GOODSID      int32  `form:"goodsid"`
		BEGINDATE    string `form:"begindate"`
		ENDDATE      string `form:"enddate"`
		RISKLEVEL    string `form:"risklevel"`
	}{}
	a.DoBindReq(&req)
	m := models.QhjMgrContract{}
	m.USERID, m.FilterName = req.USERID, req.FILTERNAME
	m.USERINFOTYPE, m.GOODSID = req.USERINFOTYPE, req.GOODSID
	m.BeginDate, m.EndDate = req.BEGINDATE, req.ENDDATE
	m.FilterRiskLevel = req.RISKLEVEL
	a.DoGetDataI(&m)
}

// QueryPickGoods
// @Summary 查询提货商品
// @Produce json
// @Security ApiKeyAuth
// @Param status query string false "状态(可多选,逗号隔开) - 1:正常 2:停用 3:注销"
// @Success 200 {array} models.QhjPickGoods
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryPickGoods [get]
// @Tags 大连千海金(PCWeb)
func QueryPickGoods(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		STATUS string `form:"status"` // 用户id
	}{}
	a.DoBindReq(&req)
	m := models.QhjPickGoods{FilterStatus: req.STATUS}
	a.DoGetDataI(&m)
}

// QueryBrokerApply
// @Summary 查询经纪人申请
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int false "所属机构ID"
// @Param filterstatus query string false "状态 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回"
// @Param filtername query string false "名称(模糊匹配)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrBrokerApply
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryBrokerApply [get]
// @Tags 大连千海金(PCWeb)
func QueryBrokerApply(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	m := models.QhjMgrBrokerApply{}
	a.DoBindReq(&m)
	a.DoGetDataI(&m)
}

// QueryBrokerRewardReport
// @Summary 查询经纪人奖励报表(废弃)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "所属机构ID"
// @Param cycletype query int true "周期类型 - 0:日 1:月 2:季 3:年 4:周 5:全报表【原值】"
// @Param cycletime query string true "周期时间 日(YYYYMMDD) 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYMMDD) 全(0)【原值】"
// @Param filtername query string false "名称(模糊匹配)"
// @Param includesub query int false "是否包含子级 1-包含"
// @Success 200 {array} models.QhjMgrBrokerRewardReport
// @Failure 500 {object} app.Response
// @Router /QhjMgr/QueryBrokerRewardReport [get]
// @Tags 大连千海金(PCWeb)
func QueryBrokerRewardReport(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	m := models.QhjMgrBrokerRewardReport{}
	a.DoBindReq(&m)
	a.DoGetDataI(&m)
}
