/**
* @Author: zou.yingbin
* @Create  : 2021/6/1 14:59
* @Modify  : 2021/6/1 14:59
 */

package qhj

import (
	"mtp2_if/global/app"
	"mtp2_if/models"
	"mtp2_if/mtpcache"

	"github.com/gin-gonic/gin"
)

// QueryContract
// @Summary 查询融资明细(合同)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param scfcontractid query int false "scf合同id"
// @Success 200 {array} models.QhjContract
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryContract [get]
// @Tags 大连千海金
func QueryContract(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID        int64 `form:"userid" binding:"required"` // 用户id
		SCFCONTRACTID int64 `form:"scfcontractid"`             // scf合同id
	}{}
	a.DoBindReq(&req)
	m := models.QhjContract{USERID: req.USERID}
	a.DoGetDataI(&m)
}

// QueryContractLog
// @Summary 查询融资明细流水(融资明细详情页中的流水)
// @Produce json
// @Security ApiKeyAuth
// @Param scfcontractid query int true "scf合同id"
// @Param amounttype query string false "资金类型(逗号隔开) - 1:首付款 2:尾款 3:利息 4:追加款"
// @Success 200 {array} models.QhjContractLog
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryContractLog [get]
// @Tags 大连千海金
func QueryContractLog(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		SCFCONTRACTID int64  `form:"scfcontractid" binding:"required"` // scf合同id
		AMOUNTTYPE    string `form:"amounttype"`                       // 资金类型(逗号隔开) - 1:首付款2:尾款 3:利息  4:追加款
	}{}
	a.DoBindReq(&req)
	m := models.QhjContractLog{SCFCONTRACTID: req.SCFCONTRACTID, FilterType: req.AMOUNTTYPE}
	a.DoGetDataI(&m)
}

// QueryRStrategy
// @Summary 查询定投设置(我的定投/历史定投[状态=已终止])
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param status query string false "策略状态(可多选,逗号隔开) - 1:正常 2:暂停 3:终止"
// @Success 200 {array} models.QhjRStrategy
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryRStrategy [get]
// @Tags 大连千海金
func QueryRStrategy(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID int64  `form:"userid" binding:"required"` // 用户id
		STATUS string `form:"status"`                    // 状态
	}{}
	a.DoBindReq(&req)
	m := models.QhjRStrategy{USERID: req.USERID, FilterStatus: req.STATUS}
	a.DoGetDataI(&m)
}

// QueryRSTriggerLog
// @Summary 查询定投记录(定投管理/详情/定投记录)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Param regularlystrategyid query int false "定投策略id"
// @Success 200 {array} models.QhjRSTriggerLog
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryRSTriggerLog [get]
// @Tags 大连千海金
func QueryRSTriggerLog(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID              int64 `form:"userid" binding:"required"` // 用户id
		REGULARLYSTRATEGYID int64 `form:"regularlystrategyid"`       // 策略id
	}{}
	a.DoBindReq(&req)
	m := models.QhjRSTriggerLog{USERID: req.USERID, REGULARLYSTRATEGYID: req.REGULARLYSTRATEGYID}
	a.DoGetDataI(&m)
}

// QueryUserReceiveInfo
// @Summary 查询收货地址信息
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.UserReceiveInfo
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryUserReceiveInfo [get]
// @Tags 大连千海金
func QueryUserReceiveInfo(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.UserReceiveInfo{USERID: req.USERID}
	a.DoGetDataI(&m)
}

// QueryUserCollectConfig
// @Summary 查询提现账户设置
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.UserCollectConfig
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryUserCollectConfig [get]
// @Tags 大连千海金
func QueryUserCollectConfig(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.UserCollectConfig{USERID: mtpcache.GetAreaUserId(req.USERID, 0)}
	a.DoGetDataI(&m)
}

// QueryTradeGoodsPickup
// @Summary 查询提货
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.QhjTradeGoodsPickup
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryTradeGoodsPickup [get]
// @Tags 大连千海金
func QueryTradeGoodsPickup(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.QhjTradeGoodsPickup{USERID: req.USERID}
	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 /Qhj/QueryPickGoods [get]
// @Tags 大连千海金
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)
}

// QueryPickArea
// @Summary 查询提货门店
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int false "用户ID"
// @Success 200 {array} models.QhjPickArea
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryPickArea [get]
// @Tags 大连千海金
func QueryPickArea(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		USERID int64 `form:"userid"` // 用户id
	}{}
	a.DoBindReq(&req)
	m := models.QhjPickArea{USERID: req.USERID}
	a.DoGetDataI(&m)
}

// QueryBankAccountSign
// @Summary 查询签约银行信息(提现账户管理)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.QhjBankAccountSign
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryBankAccountSign [get]
// @Tags 大连千海金
func QueryBankAccountSign(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.QhjBankAccountSign{RELATEDUSERID: req.USERID}
	a.DoGetDataI(&m)
}

// QueryBankInfo
// @Summary 查询开户行
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {array} models.QhjBankInfo
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryBankInfo [get]
// @Tags 大连千海金
func QueryBankInfo(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	m := models.QhjBankInfo{}
	a.DoGetDataI(&m)
}

// QueryReckonPriceLog
// @Summary 查询定投价(结算价)
// @Produce json
// @Security ApiKeyAuth
// @Param goodsid query int false "商品ID"
// @Param tradedate query string false "交易日 格式(yyyymmdd)"
// @Success 200 {array} models.QhjReckonPriceLog
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryReckonPriceLog [get]
// @Tags 大连千海金
func QueryReckonPriceLog(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	m := models.QhjReckonPriceLog{}
	a.DoBindReq(&m)
	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.QhjCustomer
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryCustomerInfo [get]
// @Tags 大连千海金
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)
	m := models.QhjCustomer{USERID: req.USERID, USERINFOTYPE: req.USERINFOTYPE, QUERYTYPE: req.QUERYTYPE,
		CUSTOMERNAME: req.CUSTOMERNAME, NICKNAME: req.NICKNAME, IncludeSub: req.INCLUDESUB}
	a.DoGetDataI(&m)
}

// QueryCusBankSignBank
// @Summary 查询托管银行
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {array} models.QhjCusBankSignBankEx
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryCusBankSignBank [get]
// @Tags 大连千海金
func QueryCusBankSignBank(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	m := models.QhjCusBankSignBankEx{}
	a.DoGetDataI(&m)
}

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

// QueryAccountInOutApply
// @Summary 查询充值提现
// @Produce json
// @Security ApiKeyAuth
// @Param begindate query string false "申请起始日期(格式yyyymmdd)"
// @Param enddate query string false "申请截止日期(格式yyyymmdd)"
// @Param likename query string false "模糊搜索名称"
// @Success 200 {array} models.QhjAccountOutInApply
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryAccountInOutApply [get]
// @Tags 大连千海金
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"`  // 模糊搜索名称
	}{}
	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.QhjAccountOutInApply{BeginDate: req.BEGINDATE, EndDate: req.ENDDATE, FilterName: req.LIKENAME}
	a.DoGetDataI(&m)
}

// QueryPayOrder
// @Summary 查询待付款单据
// @Produce json
// @Security ApiKeyAuth
// @Param accountid query int true "资金账号id"
// @Param tradeid query int false "成交单号"
// @Param payflag query int false "付款标识 - 1:未支付 2:已支付 3:已过期 4:已撤销 5:结算过期 6:预售终止"
// @Success 200 {array} models.QhjPayOrder
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryPayOrder [get]
// @Tags 大连千海金
func QueryPayOrder(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		ACCOUNTID int64  `form:"accountid" binding:"required"` // 用户id
		TRADEID   string `form:"tradeid"`                      // 成交单号
		PAYFLAG   int32  `form:"payflag"`                      // 付款标识
	}{}
	a.DoBindReq(&req)
	m := models.QhjPayOrder{BUYACCOUNTID: req.ACCOUNTID, TRADEID: req.TRADEID, PAYFLAG: req.PAYFLAG}
	a.DoGetDataI(&m)
}

// QueryGoodsEx
// @Summary 交易商品扩展表
// @Produce json
// @Security ApiKeyAuth
// @Param goodsid query int false "商品id"
// @Success 200 {array} models.Qhjgoodsex
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryGoodsEx [get]
// @Tags 大连千海金
func QueryGoodsEx(c *gin.Context) {
	a := app.GinUtils{Gin: app.Gin{C: c}}
	req := struct {
		GOODSID int `form:"goodsid"` // 商品id
	}{}
	a.DoBindReq(&req)
	m := models.Qhjgoodsex{Goodsid: int32(req.GOODSID)}
	a.DoGetDataI(&m)
}

// QueryParentAreaList
// @Summary 查询所属机构列表
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true "用户ID"
// @Success 200 {array} models.QhjParentAreaList
// @Failure 500 {object} app.Response
// @Router /Qhj/QueryParentAreaList [get]
// @Tags 大连千海金
func QueryParentAreaList(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.QhjParentAreaList{USERID: mtpcache.GetAreaUserId(req.USERID, 0)}
	a.DoGetDataI(&m)
}
