|
@@ -15,6 +15,8 @@ import (
|
|
|
crmService "hongze/fms_api/services/crm"
|
|
|
"hongze/fms_api/utils"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -91,19 +93,45 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
|
|
|
|
|
|
// 查询列表
|
|
|
groupOB := new(crm.SysGroup)
|
|
|
- totalCond := outCond
|
|
|
- totalPars := make([]interface{}, 0)
|
|
|
- total, e := groupOB.Count(totalCond, totalPars)
|
|
|
+ //totalCond := outCond
|
|
|
+ //totalPars := make([]interface{}, 0)
|
|
|
+ //total, e := groupOB.Count(totalCond, totalPars)
|
|
|
+ //if e != nil {
|
|
|
+ // resp.FailMsg("获取失败", "获取销售组开票统计列表总数失败, Err: "+e.Error(), c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //list, e := fms.GetCensusSellerGroupInvoicePageList(page, cond, outCond, pars, invSum)
|
|
|
+ //if e != nil {
|
|
|
+ // resp.FailMsg("获取失败", "获取销售组开票统计列表失败, Err: "+e.Error(), c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ groupCond := ` department_id = %d AND parent_id = 0 `
|
|
|
+ groupCond = fmt.Sprintf(groupCond, departmentId)
|
|
|
+ groupPars := make([]interface{}, 0)
|
|
|
+ groupList, e := groupOB.List(groupCond, groupPars)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取销售组开票统计列表总数失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取组别列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- list, e := fms.GetCensusSellerGroupInvoicePageList(page, cond, outCond, pars, invSum)
|
|
|
+ total := len(groupList)
|
|
|
+ groupMap := make(map[int]*crm.SysGroup)
|
|
|
+ groupIdSlice := make([]string,0)
|
|
|
+ for i := range groupList {
|
|
|
+ groupMap[groupList[i].GroupId] = groupList[i]
|
|
|
+ groupIdSlice = append(groupIdSlice, strconv.Itoa(groupList[i].GroupId))
|
|
|
+ }
|
|
|
+
|
|
|
+ groupStr := strings.Join(groupIdSlice, ",")
|
|
|
+ list, e := fms.GetCensusSellerGroupInvoicePageListV2(page, groupStr, cond, pars, invSum)
|
|
|
if e != nil {
|
|
|
resp.FailMsg("获取失败", "获取销售组开票统计列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ for _, v := range list {
|
|
|
+ if group, ok := groupMap[v.GroupId]; ok{
|
|
|
+ v.GroupName = group.GroupName
|
|
|
+ }
|
|
|
+ }
|
|
|
// 处理百分比, 乘100并保留两位小数
|
|
|
mulNum := decimal.NewFromFloat(100)
|
|
|
for i := range list {
|
|
@@ -118,7 +146,7 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
|
|
|
ExportGroupInvoiceList(c, list, req)
|
|
|
return
|
|
|
}
|
|
|
- page.SetTotal(total)
|
|
|
+ page.SetTotal(int64(total))
|
|
|
baseData := new(base.BaseData)
|
|
|
baseData.SetPage(page)
|
|
|
baseData.SetList(list)
|
|
@@ -223,8 +251,11 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
pars := make([]interface{}, 0)
|
|
|
+ adminPars := make([]interface{}, 0)
|
|
|
outCond := ` a.department_id = %d `
|
|
|
outCond = fmt.Sprintf(outCond, departmentId)
|
|
|
+ adminCond := ` department_id = %d `
|
|
|
+ adminCond = fmt.Sprintf(adminCond, departmentId)
|
|
|
totalCond := ` department_id = %d `
|
|
|
totalCond = fmt.Sprintf(totalCond, departmentId)
|
|
|
totalPars := make([]interface{}, 0)
|
|
@@ -246,13 +277,15 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
|
|
|
}
|
|
|
outCond += ` AND a.group_id IN (?) `
|
|
|
pars = append(pars, groupIds)
|
|
|
+ adminCond += ` AND group_id IN (?) `
|
|
|
+ adminPars = append(adminPars, groupIds)
|
|
|
totalCond += ` AND group_id IN (?) `
|
|
|
totalPars = append(totalPars, groupIds)
|
|
|
}
|
|
|
sumCond := ` invoice_type = ? AND is_deleted = 0 AND seller_id != 0 `
|
|
|
sumPars := make([]interface{}, 0)
|
|
|
sumPars = append(sumPars, fms.ContractInvoiceTypeMake)
|
|
|
- cond := ` c.invoice_type = %d AND c.is_deleted = 0 AND c.seller_id != 0 `
|
|
|
+ cond := ` invoice_type = %d AND is_deleted = 0 AND seller_id != 0 `
|
|
|
cond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake)
|
|
|
// 开票日期
|
|
|
if req.StartDate != "" && req.EndDate != "" {
|
|
@@ -286,17 +319,46 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
|
|
|
|
|
|
// 查询列表
|
|
|
adminOB := new(crm.Admin)
|
|
|
- total, e := adminOB.Count(totalCond, totalPars)
|
|
|
+ //total, e := adminOB.Count(totalCond, totalPars)
|
|
|
+ //if e != nil {
|
|
|
+ // resp.FailMsg("获取失败", "获取销售开票统计列表总数失败, Err: "+e.Error(), c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //list, e := fms.GetCensusSellerInvoicePageList(page, cond, outCond, pars, invSum)
|
|
|
+ //if e != nil {
|
|
|
+ // resp.FailMsg("获取失败", "获取销售开票统计列表失败, Err: "+e.Error(), c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ adminList, e := adminOB.List(adminCond, adminPars)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取销售开票统计列表总数失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取销售列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- list, e := fms.GetCensusSellerInvoicePageList(page, cond, outCond, pars, invSum)
|
|
|
+ //total := len(adminList)
|
|
|
+ adminIdSlice := make([]string,0)
|
|
|
+ sellerMap := make(map[int]*crm.Admin)
|
|
|
+ for i := range adminList {
|
|
|
+ sellerMap[adminList[i].AdminId] = adminList[i]
|
|
|
+ adminIdSlice = append(adminIdSlice, strconv.Itoa(adminList[i].AdminId))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ adminStr := strings.Join(adminIdSlice, ",")
|
|
|
+
|
|
|
+ total, list, e := fms.GetCensusSellerInvoicePageListV2(page, adminStr, cond, pars, invSum)
|
|
|
if e != nil {
|
|
|
resp.FailMsg("获取失败", "获取销售开票统计列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ for _, v := range list {
|
|
|
+ if admin, ok := sellerMap[v.SellerId]; ok{
|
|
|
+ v.GroupName = admin.GroupName
|
|
|
+ v.SellerName = admin.RealName
|
|
|
+ v.GroupId = admin.GroupId
|
|
|
+ }
|
|
|
+ }
|
|
|
// 分组信息, list的groupId可能是三级的ID, 要转为对应的二级
|
|
|
groupMap, e := crmService.GetSellerTeamGroupMap()
|
|
|
if e != nil {
|
|
@@ -327,7 +389,7 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
|
|
|
ExportInvoiceList(c, list, req)
|
|
|
return
|
|
|
}
|
|
|
- page.SetTotal(total)
|
|
|
+ page.SetTotal(int64(total))
|
|
|
baseData := new(base.BaseData)
|
|
|
baseData.SetPage(page)
|
|
|
baseData.SetList(list)
|