浏览代码

Merge branch 'debug' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 年之前
父节点
当前提交
d8ba74069e
共有 3 个文件被更改,包括 195 次插入0 次删除
  1. 20 0
      controllers/activity_special.go
  2. 39 0
      models/activity_special_trip_bill.go
  3. 136 0
      services/activity_special.go

+ 20 - 0
controllers/activity_special.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -245,6 +246,25 @@ func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
 			itemBill.BillDetailed = -1 // 流水减一
 			itemBill.RegisterPlatform = 1
 			itemBill.ChartPermissionId = activityInfo.ChartPermissionId
+			userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
+			if err != nil {
+				br.Msg = "获取专项调研剩余次数失败"
+				br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
+				return
+			}
+			if userType == 2 {
+				tripRemaining -= 1
+				itemBill.Total = strconv.Itoa(tripRemaining) + "次"
+			} else {
+				for k, num := range mapChartName {
+					if activityInfo.ChartPermissionName == k {
+						num -= 1
+					}
+					itemBill.Total += k + strconv.Itoa(num) + "次+"
+				}
+				itemBill.Total = strings.TrimRight(itemBill.Total, "+")
+			}
+
 
 			var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
 			itemMeeting.UserId = user.UserId

+ 39 - 0
models/activity_special_trip_bill.go

@@ -21,6 +21,9 @@ type CygxActivitySpecialTripBill struct {
 	DoType            int       `description:"操作方式,1报名,2取消报名"`
 	RegisterPlatform  int       `description:"来源 1小程序,2:网页"`
 	ChartPermissionId int       `description:"行业id"`
+	Way               int       `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
+	Content           string    `description:"内容"`
+	Total             string    `description:"总和"`
 }
 
 // 添加
@@ -42,3 +45,39 @@ func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item
 	_, err = o.Raw(sql, pars).QueryRows(&item)
 	return
 }
+
+type CygxActivitySpecialTripBillList struct {
+	Id                  int       `orm:"column(id);pk"`
+	UserId              int       `description:"用户id,多个用,隔开"`
+	ActivityId          int       `description:"活动ID"`
+	CreateTime          time.Time `description:"创建时间"`
+	Mobile              string    `description:"手机号"`
+	Email               string    `description:"邮箱号"`
+	CompanyId           int       `description:"公司ID"`
+	CompanyName         string    `description:"公司名称"`
+	RealName            string    `description:"用户实际名称"`
+	AdminId             int       `description:"销售/管理员ID"`
+	Source              int       `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
+	BillDetailed        int       `description:"流水明细,判断是进账还是出账"`
+	DoType              int       `description:"操作方式,1报名,2取消报名"`
+	RegisterPlatform    int       `description:"来源 1小程序,2:网页"`
+	ChartPermissionId   int       `description:"行业id"`
+	ChartPermissionName string    `description:"行业名称"`
+	Way                 int       `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
+	Content             string    `description:"内容"`
+}
+
+
+func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			b.*,
+			c.chart_permission_name 
+		FROM
+			cygx_activity_special_trip_bill AS b
+			LEFT JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
+		WHERE
+			1 = 1` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 136 - 0
services/activity_special.go

@@ -1259,3 +1259,139 @@ func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
 	}
 	return
 }
+
+func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int,mapChartName map[string]int, err error) {
+	companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
+	if e != nil {
+		err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
+	}
+	if companyDetail == nil {
+		return
+	}
+	if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
+		return
+	}
+	var specialSurplus string
+	if companyDetail.Status == "永续" {
+		specialSurplus = "不限次数"
+	}
+	//chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
+	//chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
+	if companyDetail.Status == "正式" {
+		//var packageType int
+		userType, _, _ = GetUserType(companyId)
+		var condition string
+		var pars []interface{}
+
+		condition += ` AND company_id = ? `
+		pars = append(pars, companyId)
+
+		//查询当年的数据
+		condition += ` AND b.create_time >= ?  `
+		pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
+		listTripBill, e := models.GetCygxActivitySpecialTripBillList(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+		if userType == 2 {
+			//airborneList, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
+			//if e != nil {
+			//	err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
+			//	return
+			//}
+			//ariborneMap := make(map[int]int)
+			//for _, v := range airborneList {
+			//	ariborneMap[v.ChartPermissionId] = v.Count
+			//}
+			//到会空降的也加入流水记录表,这里不在做单独计算 2023-07-10
+			//airborneTotal, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
+			//if e != nil {
+			//	err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
+			//	return
+			//}
+			//condition += ` AND is_valid = 1 `
+			//TripBillNumMap := make(map[int]int)
+			//for _, v := range listTripBill {
+			//	TripBillNumMap[v.ChartPermissionId] += v.BillDetailed
+			//}
+			var TripBillNum int
+			for _, v := range listTripBill {
+				//if v.ActivityId == 0 {
+				//	continue
+				//}
+				TripBillNum += v.BillDetailed
+			}
+			// CRM13.2 70w客户有16次专项调研, 45w有10次
+			//packageTypeMap := map[int]int{1: 16, 2: 10}
+			//totalTrip := packageTypeMap[packageType]
+
+			tripRemaining = TripBillNum
+			if tripRemaining < 0 {
+				tripRemaining = 0
+			}
+
+			//for k, _ := range chartNumMap {
+			//	tripRemaining := totalTrip - ariborneMap[k] + TripBillNumMap[k]
+			//	if tripRemaining < 0 {
+			//		tripRemaining = 0
+			//	}
+			//	specialSurplus += chartMap[k] + strconv.Itoa(tripRemaining) + "次,"
+			//}
+			//specialSurplus = strings.TrimRight(specialSurplus, ",")
+
+			//tripRemaining = 12 - tripTota
+		} else {
+			list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
+			if e != nil && e.Error() != utils.ErrNoRow() {
+				err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
+			}
+			if len(list) == 0 {
+				return
+			}
+			var chartPermissionIdSlice []string
+			mapChartName = make(map[string]int)
+			mapPermissionNameTrip := make(map[string]int)
+			//mapPermissionName := make(map[int]string)
+			for _, v := range list {
+				chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
+
+			}
+			chartList, e := models.GetChartPermissionByIds(chartPermissionIdSlice)
+			if e != nil {
+				err = errors.New("获取品种信息失败, Err:" + e.Error())
+				return
+			}
+			if len(chartList) == 0 {
+				return
+			}
+			//到会空降的也加入流水记录表,这里不在做单独计算 2023-07-10
+			//airborneList, e := cygx.GetCygxActivitySpecialTripAirborneListByComapnyId(companyId)
+			//if e != nil {
+			//	err = errors.New("获取品种信息失败, Err:" + e.Error())
+			//	return
+			//}
+			//for _, v := range airborneList {
+			//	mapPermissionNameTrip[v.ChartPermissionName] += 1
+			//}
+
+			//var TripBillNum int
+			for _, v := range listTripBill {
+				if v.ActivityId == 0 {
+					continue
+				}
+				mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
+			}
+			for _, v := range chartList {
+				mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
+			}
+			for k, v := range mapChartName {
+				if v > 0 {
+					specialSurplus += k + strconv.Itoa(v) + "次+"
+				}
+			}
+			specialSurplus = strings.TrimRight(specialSurplus, "+")
+		}
+	}
+	return
+}