|
@@ -1,14 +1,17 @@
|
|
|
package cygx
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"hongze/hz_crm_api/controllers"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
"hongze/hz_crm_api/models/cygx"
|
|
|
+ "hongze/hz_crm_api/models/roadshow"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// 权益服务类型
|
|
@@ -345,6 +348,18 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
sortStr = " ORDER BY end_date DESC "
|
|
|
}
|
|
|
|
|
|
+ //如果不是权益管理员和admin、财务,就做可见权限限制
|
|
|
+ if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
|
|
|
+ if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
|
|
|
+ condition = " AND (seller_id = ? OR share_seller_id = ? ) "
|
|
|
+ pars = append(pars, sysUser.AdminId, sysUser.AdminId)
|
|
|
+ }
|
|
|
+ if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
|
|
|
+ condition = " AND ( seller_id = ? OR share_seller_id = ? OR group_id = ? OR share_group_id = ? ) "
|
|
|
+ pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.GroupId, sysUser.GroupId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
total, err := cygx.GetCygxRaiServeCompanyCount(condition, pars)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
@@ -358,15 +373,52 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- switch tagType {
|
|
|
- case 1:
|
|
|
- fmt.Println(tagId)
|
|
|
- case 2:
|
|
|
- case 3:
|
|
|
-
|
|
|
+ var companyIds []int
|
|
|
+ for _, v := range listRaiServeCompany {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
}
|
|
|
- if serveTypeId > 0 {
|
|
|
|
|
|
+ mapWeekAmount := make(map[string]float64) //周度服务量
|
|
|
+
|
|
|
+ lencompanyIds := len(companyIds)
|
|
|
+ if lencompanyIds > 0 {
|
|
|
+ var conditionBill string
|
|
|
+ var parsBill []interface{}
|
|
|
+
|
|
|
+ conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败!"
|
|
|
+ br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //服务类型筛选
|
|
|
+ if serveTypeId > 0 {
|
|
|
+ conditionBill += ` AND serve_type_id = ? `
|
|
|
+ parsBill = append(parsBill, serveTypeId)
|
|
|
+ }
|
|
|
+
|
|
|
+ conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
|
|
|
+ parsBill = append(parsBill, companyIds)
|
|
|
+
|
|
|
+ listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败!"
|
|
|
+ br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now()
|
|
|
+ weeks := 4
|
|
|
+ for _, v := range listBill {
|
|
|
+ for i := 0; i < weeks; i++ {
|
|
|
+ // 计算当前周的周一
|
|
|
+ monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
|
|
|
+ weekmonday := monday.Format(utils.FormatDate)
|
|
|
+ if v.WeekStartDate == weekmonday {
|
|
|
+ mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if isExport {
|
|
@@ -388,10 +440,10 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
item.ShareSellerId = v.ShareSellerId
|
|
|
item.Status = v.Status
|
|
|
item.PermissionName = v.PermissionName
|
|
|
- item.ThisWeekAmount = 99
|
|
|
- item.LastWeekAmount = 99
|
|
|
- item.TwoWeekAmount = 99
|
|
|
- item.ThreeWeekAmount = 99
|
|
|
+ item.ThisWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 0)]
|
|
|
+ item.LastWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 1)]
|
|
|
+ item.TwoWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 2)]
|
|
|
+ item.ThreeWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 3)]
|
|
|
resp.List = append(resp.List, item)
|
|
|
}
|
|
|
|
|
@@ -404,6 +456,116 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// 标签搜索语句筛选
|
|
|
+func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
|
|
|
+ var activityIds []int
|
|
|
+ var activitySpecialIds []int
|
|
|
+ var articleIds []int
|
|
|
+ var rsCalendarIds []int
|
|
|
+ switch tagType {
|
|
|
+ case 1:
|
|
|
+ listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupActivity {
|
|
|
+ activityIds = append(activityIds, v.ActivityId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupActivitySpecial {
|
|
|
+ activitySpecialIds = append(activitySpecialIds, v.ActivityId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupArticle {
|
|
|
+ articleIds = append(articleIds, v.ArticleId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupRsCalendar {
|
|
|
+ rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
|
|
|
+ }
|
|
|
+ case 2:
|
|
|
+ listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 1) // 关联的活动
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupActivity {
|
|
|
+ activityIds = append(activityIds, v.ActivityId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectId(tagId, 2) // 关联的产业
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupActivitySpecial {
|
|
|
+ activitySpecialIds = append(activitySpecialIds, v.ActivityId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectId(tagId) // 关联的产业
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSubjectArticleGroupManagementListBysubjectId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupArticle {
|
|
|
+ articleIds = append(articleIds, v.ArticleId)
|
|
|
+ }
|
|
|
+
|
|
|
+ listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listGroupRsCalendar {
|
|
|
+ rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ conditionBill += " AND chart_permission_id = ? "
|
|
|
+ parsBill = append(parsBill, tagId)
|
|
|
+ }
|
|
|
+
|
|
|
+ lenactivityIds := len(activityIds)
|
|
|
+ if lenactivityIds > 0 {
|
|
|
+ conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
|
|
|
+ parsBill = append(parsBill, activityIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ lenactivitySpecialIds := len(activitySpecialIds)
|
|
|
+ if lenactivitySpecialIds > 0 {
|
|
|
+ conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
|
|
|
+ parsBill = append(parsBill, activitySpecialIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ lenarticleIds := len(articleIds)
|
|
|
+ if lenarticleIds > 0 {
|
|
|
+ conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
|
|
|
+ parsBill = append(parsBill, articleIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ lenrsCalendarIds := len(rsCalendarIds)
|
|
|
+ if lenrsCalendarIds > 0 {
|
|
|
+ conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
|
|
|
+ parsBill = append(parsBill, rsCalendarIds)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// @Title 近四周覆盖率
|
|
|
// @Description 近四周覆盖率接口
|
|
|
// @Param CompanyId query int false "公司ID"
|
|
@@ -422,18 +584,23 @@ func (this *RaiServeCoAntroller) CoverageRate() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
- companyId := this.GetString("CompanyId")
|
|
|
- fmt.Println(companyId)
|
|
|
+ companyId, _ := this.GetInt("CompanyId")
|
|
|
+ listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败!"
|
|
|
+ br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mapWeek := make(map[int]float64)
|
|
|
+ for k, v := range listWeekBill {
|
|
|
+ mapWeek[k] = v.ServeCount
|
|
|
+ }
|
|
|
+ //fmt.Sprintf(mapWeek[1])
|
|
|
resp := new(cygx.RaiServeCoverageRateResp)
|
|
|
- //ThisWeekAmount string `comment:"本周互动量"`
|
|
|
- //LastWeekAmount string `comment:"上周互动量"`
|
|
|
- //TwoWeekAmount string `comment:"上上周互动量"`
|
|
|
- //ThreeWeekAmount string `comment:"上三周互动量"`
|
|
|
- resp.ThisWeekAmount = "22%"
|
|
|
+ //resp.ThisWeekAmount = fmt.Sprintf(,"%")
|
|
|
resp.LastWeekAmount = "33%"
|
|
|
resp.TwoWeekAmount = "44%"
|
|
|
resp.ThreeWeekAmount = "55%"
|
|
|
- //resp.List = []string{"22%", "33%", "44%", "55%"}
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|