|
|
@@ -1328,3 +1328,119 @@ func (r *QhjMgrBrokerApply) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, err
|
|
|
}
|
|
|
+
|
|
|
+// QhjMgrBrokerRewardReport 经纪人奖励报表
|
|
|
+type QhjMgrBrokerRewardReport struct {
|
|
|
+ CYCLETIME string `json:"cycletime" xorm:"CYCLETIME" form:"cycletime"` // 周期时间 日(YYYYMMDD) 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYMMDD) 全(0)【原值】
|
|
|
+ CYCLETYPE int32 `json:"cycletype" xorm:"CYCLETYPE" form:"cycletype"` // 周期类型 - 0:日 1:月 2:季 3:年 4:周 5:全报表【原值】
|
|
|
+ USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 经纪人用户ID
|
|
|
+ DIRECTTOTALNUM int32 `json:"directtotalnum" xorm:"DIRECTTOTALNUM" form:"directtotalnum"` // 直推总人数【期末】
|
|
|
+ INDIRECTTOTALNUM int32 `json:"indirecttotalnum" xorm:"INDIRECTTOTALNUM" form:"indirecttotalnum"` // 间推总人数【期末】
|
|
|
+ TODAYREWARDAMOUNT float64 `json:"todayrewardamount" xorm:"TODAYREWARDAMOUNT" form:"todayrewardamount"` // 奖励总金额【汇总】
|
|
|
+ UPDATETIME string `json:"updatetime" xorm:"UPDATETIME" form:"updatetime"` // 更新时间
|
|
|
+ USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称
|
|
|
+ REFEREEUSERID int64 `json:"refereeuserid" xorm:"'REFEREEUSERID'"` // 推荐人id(经纪人id)
|
|
|
+ REFERNUM string `json:"refernum" xorm:"'REFERNUM'"` // 推荐码
|
|
|
+ SUBAREALEVELPATH string `json:"subarealevelpath" xorm:"'SUBAREALEVELPATH'"` // 用户层级路径
|
|
|
+ CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间(注册时间)
|
|
|
+ USERINFOTYPE int32 `json:"userinfotype" xorm:"'USERINFOTYPE'"` // 用户类型 1-个人 2-企业
|
|
|
+ MOBILE string `json:"mobile" xorm:"'MOBILE'"` // 电话号码
|
|
|
+ REFEREEUSERNAME string `json:"refereeusername" xorm:"'REFEREEUSERNAME'"` // 推荐人名称(经纪人) 上级经纪人名称
|
|
|
+
|
|
|
+ IncludeSub int32 `json:"-" form:"includesub"` // 是否包含子级 1-包含
|
|
|
+ FilterName string `json:"-" form:"filtername"` // 模糊搜索名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QhjMgrBrokerRewardReport) calc() {
|
|
|
+ r.MOBILE = DecryptField(r.MOBILE)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QhjMgrBrokerRewardReport) sqlDay() string {
|
|
|
+ var sqlId utils.SQLVal = "SELECT t.reckondate as CYCLETIME," +
|
|
|
+ " 0 as CYCLETYPE," +
|
|
|
+ " t.USERID," +
|
|
|
+ " t.DIRECTTOTALNUM," +
|
|
|
+ " t.INDIRECTTOTALNUM," +
|
|
|
+ " t.TODAYREWARDAMOUNT," +
|
|
|
+ " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
|
|
|
+ " u.accountname USERNAME," +
|
|
|
+ " u.refereeuserid," +
|
|
|
+ " u.refernum," +
|
|
|
+ " u.subarealevelpath," +
|
|
|
+ " to_char(u.createtime, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
|
|
|
+ " ui.userinfotype," +
|
|
|
+ " ui.mobile," +
|
|
|
+ " u2.accountname REFEREEUSERNAME" +
|
|
|
+ " FROM RECKON_BROKERREWARD t" +
|
|
|
+ " INNER JOIN USERACCOUNT u on t.userid=u.userid" +
|
|
|
+ " INNER JOIN USERINFO ui on t.userid=ui.userid" +
|
|
|
+ " LEFT JOIN USERACCOUNT u2 on u.refereeuserid=u2.userid" +
|
|
|
+ " WHERE 1 = 1"
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QhjMgrBrokerRewardReport) sqlCycle() string {
|
|
|
+ var sqlId utils.SQLVal = "SELECT t.CYCLETIME," +
|
|
|
+ " t.CYCLETYPE," +
|
|
|
+ " t.USERID," +
|
|
|
+ " t.DIRECTTOTALNUM," +
|
|
|
+ " t.INDIRECTTOTALNUM," +
|
|
|
+ " t.TODAYREWARDAMOUNT," +
|
|
|
+ " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
|
|
|
+ " u.accountname USERNAME," +
|
|
|
+ " u.refereeuserid," +
|
|
|
+ " u.refernum," +
|
|
|
+ " u.subarealevelpath," +
|
|
|
+ " to_char(u.createtime, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
|
|
|
+ " ui.userinfotype," +
|
|
|
+ " ui.mobile," +
|
|
|
+ " u2.accountname REFEREEUSERNAME" +
|
|
|
+ " FROM REPORT_BROKERREWARD t" +
|
|
|
+ " INNER JOIN USERACCOUNT u on t.userid=u.userid" +
|
|
|
+ " INNER JOIN USERINFO ui on t.userid=ui.userid" +
|
|
|
+ " LEFT JOIN USERACCOUNT u2 on u.refereeuserid=u2.userid" +
|
|
|
+ " WHERE 1 = 1"
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QhjMgrBrokerRewardReport) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal
|
|
|
+ if r.CYCLETYPE == 0 {
|
|
|
+ sqlId = utils.SQLVal(r.sqlDay())
|
|
|
+ sqlId.AndEx("t.reckondate", r.CYCLETIME, r.CYCLETIME != "")
|
|
|
+ } else {
|
|
|
+ sqlId = utils.SQLVal(r.sqlCycle())
|
|
|
+ sqlId.And("t.CYCLETYPE", r.CYCLETYPE)
|
|
|
+ // 转换时间
|
|
|
+ // 兼容性处理, 月报表日期如果是yyyymmdd, 只取yyyymm
|
|
|
+ if r.CYCLETYPE == 1 && len(r.CYCLETIME) > 6 {
|
|
|
+ r.CYCLETIME = r.CYCLETIME[:6]
|
|
|
+ } else if r.CYCLETYPE == 4 {
|
|
|
+ r.CYCLETIME = mtpcache.GetWeekIW(r.CYCLETIME)
|
|
|
+ }
|
|
|
+ sqlId.And("t.CYCLETIME", r.CYCLETIME)
|
|
|
+ }
|
|
|
+ if r.IncludeSub == 1 {
|
|
|
+ //sqlId.JoinFormat(" and u.subarealevelpath like '%%,%v,%%,%%'", r.USERID)
|
|
|
+ // 要用 refereeuserid 递归查询, 不能用subarealevelpath
|
|
|
+ } else {
|
|
|
+ sqlId.And("u.refereeuserid", r.USERID)
|
|
|
+ }
|
|
|
+ if len(r.FilterName) > 0 {
|
|
|
+ sqlId.JoinFormat(" and u.accountname like '%%%v%%'", r.FilterName, r.FilterName)
|
|
|
+ }
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取经纪人奖励报表
|
|
|
+func (r *QhjMgrBrokerRewardReport) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]QhjMgrBrokerRewardReport, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|