12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/utils"
- "strconv"
- "strings"
- "time"
- )
- func GetUserType(companyId int) (userType int, permissionStrnew string, err error) {
- var permissionStr, permissionZhengShiStr string
- if companyId <= 1 {
- userType = 0
- } else {
- total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- if total == 0 {
- userType = 0
- } else {
- companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStr, errs = models.GetCompanyPermission(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStrnew = permissionStr
-
- companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
- if errs != nil && errs.Error() != utils.ErrNoRow() {
- err = errs
- return
- }
- if companyUserTypeDetail != nil {
- if companyUserTypeDetail.CustomerTypeId != 0 {
- userType = companyUserTypeDetail.CustomerTypeId
- return
- }
- }
- permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
- if errs != nil {
- err = errs
- return
- }
-
-
- if companyDetail.Status == "永续" {
- userType = 1
- } else if companyDetail.Status == "试用" {
- userType = 5
- } else if companyDetail.Status == "冻结" {
- userType = 6
- } else if companyDetail.Status == "流失" {
- userType = 7
- }
-
- if userType == 0 && companyDetail.Status == "正式" {
- var permissionZhegnshiNum int
- if strings.Count(permissionZhengShiStr, "医药") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "消费") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "科技") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "智造") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "策略") == 1 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
- permissionZhegnshiNum++
- }
-
-
-
-
- if permissionZhegnshiNum >= 4 {
- userType = 10
- } else {
- userType = 3
- }
- }
- }
- }
- permissionStrnew = permissionStr
- return
- }
- func GetUserTypeZhengShi(companyId int) (userType int, permissionStrnew, permissionStrZhengShinew string, err error) {
- var permissionStr, permissionZhengShiStr string
- if companyId <= 1 {
- userType = 0
- } else {
- total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- if total == 0 {
- userType = 0
- } else {
- companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStr, errs = models.GetCompanyPermission(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStrnew = permissionStr
- permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStrZhengShinew = permissionZhengShiStr
-
- companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
- if errs != nil && errs.Error() != utils.ErrNoRow() {
- err = errs
- return
- }
- if companyUserTypeDetail != nil {
- if companyUserTypeDetail.CustomerTypeId != 0 {
- userType = companyUserTypeDetail.CustomerTypeId
- return
- }
- }
-
-
- if companyDetail.Status == "永续" {
- userType = 1
- } else if companyDetail.Status == "试用" {
- userType = 5
- } else if companyDetail.Status == "冻结" {
- userType = 6
- } else if companyDetail.Status == "流失" {
- userType = 7
- }
-
- if userType == 0 && companyDetail.Status == "正式" {
- var permissionZhegnshiNum int
- if strings.Count(permissionZhengShiStr, "医药") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "消费") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "科技") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "智造") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "策略") == 1 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
- permissionZhegnshiNum++
- }
-
-
-
-
- if permissionZhegnshiNum >= 4 {
- userType = 10
- } else {
- userType = 3
- }
- }
- }
- }
- permissionStrnew = permissionStr
- permissionStrZhengShinew = permissionZhengShiStr
- return
- }
- func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
- var companyDetailStatus string
- var userTypeStr string
- userId := user.UserId
- activityId := activityInfo.ActivityId
- activityPointsByUserAllMap := GetActivityPointsByUserAllMap()
-
- if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] {
- isResearchSpecial = true
- }
-
-
- if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
- havePower = true
- return
- }
- if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" {
-
- userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
- if userCardTotal == 1 {
- havePower = true
- return
- }
- } else {
- activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(user.Mobile, activityId)
- if activtyPayTotal == 1 {
- havePower = true
- return
- }
- }
- userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
- return
- }
-
-
- mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
- if mfyxUserPermissionTotal == 1 {
- permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
- }
-
- if strings.Contains(permissionStrZhengShi, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
- permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
- permissionStrZhengShi += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
- }
-
- if strings.Contains(permissionStr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
- permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
- }
-
- if permissionStr == "" {
- return
- }
-
- if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && mfyxUserPermissionTotal == 0 {
- havePower = false
- return
- }
- permissionStr += "," + utils.HONG_GUAN_NAME
- if permissionStrZhengShi == "" {
- permissionStrZhengShi = utils.HONG_GUAN_NAME
- } else {
- permissionStrZhengShi += "," + utils.HONG_GUAN_NAME
- }
-
- if activityInfo.YidongActivityId != "" {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) {
- havePower = true
- return
- }
- }
-
- if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- return
- }
-
- if activityInfo.IsResearchPoints {
-
- userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
- if e != nil {
- err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
- return
- }
- if userPointsNum > 0 {
-
-
-
-
- if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
- havePower = false
- return
- }
- }
- }
-
- if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
- havePower = false
- return
- }
-
- if activityInfo.VisibleRange == 1 {
- adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
- if e != nil {
- err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
- return
- }
- haveVisibleRange := false
- adminIdSlice := strings.Split(adminIds, ",")
- for _, v := range adminIdSlice {
- if v == strconv.Itoa(activityInfo.AdminId) {
- haveVisibleRange = true
- }
- }
- if !haveVisibleRange {
- havePower = false
- return
- }
- }
- if permissionStr == "" {
- return
- }
-
- if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
- havePower = true
- return
- }
-
- if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
- if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
- havePower = true
- } else {
- havePower = false
- }
- } else {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
- havePower = true
- } else {
- havePower = false
- }
- }
- if !havePower {
- return
- }
- }
- if activityInfo.LimitPeopleNum > 0 {
- mapUserType, e := GetActivityCcustomerTypeList()
- if e != nil {
- err = e
- return
- }
- userTypeStr = mapUserType[userType]
-
- if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
- if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
- havePower = true
-
- }
- }
- } else {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- havePower = true
- return
- }
- }
-
- companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
- if e != nil {
- err = e
- return
- }
- if companyProduct != nil && activityInfo.Scale != "" {
- if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
- havePower = true
- }
- }
- if user.CompanyId <= 1 {
- return
- } else {
- if permissionStr == "" {
- return
- } else {
- companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
- return
- }
- if companyDetail == nil {
- err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
- return
- }
- companyDetailStatus = companyDetail.Status
- }
- }
-
- if activityInfo.ChartPermissionId == 1 {
- if activityInfo.LimitPeopleNum > 0 {
- if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
- havePower = true
- return
- }
- } else {
- havePower = true
- return
- }
- }
- if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
- havePower = true
- } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
- havePower = true
- } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
- havePower = true
- } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
- havePower = true
- }
- fmt.Println(permissionStrZhengShi)
-
-
-
-
- if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
- if strings.Contains(activityInfo.CustomerTypeIds, "5") {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- havePower = true
- return
- }
- } else {
- if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
- havePower = true
- return
- }
- }
- }
- permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
- if errs != nil {
- err = errs
- return
- }
-
-
-
-
-
-
- if activityInfo.CustomerTypeIds != "" {
- if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
- havePower = false
- if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
- havePower = true
- }
- }
- }
- if havePower && activityInfo.LimitPeopleNum > 0 {
-
- noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
- if e != nil {
- err = errors.New("GetShareNoPowe, Err: " + e.Error())
- return
- }
- if noPower {
- havePower = false
- }
- }
- return
- }
- func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
-
- if user.CompanyId == utils.HZ_COMPANY_ID {
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fmt.Println(userType)
- if userType == 8 {
- permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
- if errs != nil {
- err = errs
- return
- }
- if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
- noPower = true
- return
- }
- }
- if !noPower {
- noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
- }
- return
- }
- func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
-
- if activityInfo.VisibleRange == 1 {
- adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
- if errAdmin != nil {
- err = errAdmin
- return
- }
- sliceAdminIds := strings.Split(adminIds, ",")
- var haveAdminId bool
- for _, v := range sliceAdminIds {
- if v == strconv.Itoa(activityInfo.AdminId) {
- haveAdminId = true
- }
- }
- if !haveAdminId {
- noPower = true
- }
- }
-
- if activityInfo.IsMakerShow == 1 {
- if user.IsMaker == 0 {
- noPower = true
- }
- }
- return
- }
- func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
-
- if user.UserId == 0 {
- conditionActivity = ` AND art.publish_status = 1 AND art.yidong_activity_id = '' ` + condition
- return
- }
-
- if user.UserId == 0 || user.CompanyId == 1 {
- conditionActivity = ` AND art.publish_status = 1 AND art.visible_range != 1 AND (art.is_limit_people = 0 OR (art.is_limit_people=1 AND art.is_all_customer_type=1)) ` + condition
- return
- }
- condition += ` AND art.publish_status = 1 `
- conditionActivity = condition
-
- if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || user.UserId == 0 {
- return
- }
- adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
- if err != nil {
- return
- }
- userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
- if err != nil {
- return
- }
-
- companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- isMaker := user.IsMaker
- slicePer := strings.Split(permissionStr, ",")
- var permissionSqlStr string
- var permissionNameStr string
- for _, v := range slicePer {
- if userType == 1 {
-
- if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
- permissionNameStr += "'" + v + "',"
- }
- } else {
- permissionNameStr += "'" + v + "',"
- }
- }
- permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
- permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
- permissionNameStr = strings.TrimRight(permissionNameStr, ",")
- slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
- var permissionNameStrZhengShi string
- for _, v := range slicePerZhengShi {
- if userType == 1 {
-
- if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
- permissionNameStrZhengShi += "'" + v + "',"
- }
- } else {
- permissionNameStrZhengShi += "'" + v + "',"
- }
- }
- permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
- permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
- permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
- mapUserType, e := GetActivityCcustomerTypeList()
- if e != nil {
- err = e
- return
- }
- var userTypeStr string
- userTypeStr = mapUserType[userType]
-
- if permissionNameStr == `` {
- permissionNameStr = `'宏观'`
- } else {
- permissionNameStr += `, '宏观'`
- }
- var sqlExport string
- sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
- if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
- sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
- }
- sqlExport += `) `
- if isPower == 1 {
-
-
- }
- var conditionOr string
-
- if adminIds != "" {
- condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
- }
-
- if isMaker == 0 {
- condition += ` AND art.is_maker_show = 0 `
- }
-
- if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
- conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
- }
- if (userType == 5) && strings.Contains(permissionStr, "专家") {
- conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
- }
- if userType == 1 {
- conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
- } else {
- conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
- }
- if userType == 6 || userType == 7 {
- conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
- }
- if companyProduct != nil {
- if companyProduct.Scale != "" {
- conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
- }
- }
-
-
-
- condition += ` AND art.is_limit_people = 1 `
- conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
- return
- }
- func LabelStr(label string) (labelNew string) {
- slicebr := strings.Split(label, "-")
- if len(slicebr) < 2 {
- labelNew = label
- } else {
- labelNew = slicebr[1]
- }
- return labelNew
- }
- func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
- if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
- isShowAppointment = true
- }
- if activityTypeId == 5 && chartPermissionName == "医药" {
- isShowAppointment = true
- }
- return
- }
- func ArticleUserRemind(user *models.WxUserItem, articleDetail *models.ArticleDetail, source int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(" 用户报告操作行为,模板消息推送失败"+fmt.Sprint("UserId:", user.UserId, "ArticleId:", articleDetail.ArticleId), 2)
- }
- }()
- countUser, err := models.GetUserRemind(user.UserId)
- if err != nil {
- return err
- }
- if countUser == 0 {
- return err
- }
- var sourceMsg string
- if source == 1 {
- sourceMsg = "阅读报告"
- } else {
- sourceMsg = "收藏报告"
- }
-
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if sellerItemQy != nil {
- openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
- if err != nil {
- fmt.Println(err)
- return err
- }
- var keyword1 string
- var keyword2 string
- keyword1 = articleDetail.Title
- keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
- SendWxMsgWithArticleUserRemind(keyword1, keyword2, openIdList, articleDetail.ArticleId)
- }
- return
- }
- func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
-
- countUser, e := models.GetUserRemind(user.UserId)
- if e != nil {
- err = errors.New("GetUserRemind, Err: " + e.Error())
- return
- }
-
- if activityDetail.ActivityTypeId == 5 {
- go SendNeiRongZuActivitieSignTemplateMsg(user, activityDetail)
- go SendNeiRongZuActivitieSignCategoryTemplateMsg(user, activityDetail)
- }
-
- sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
- return
- }
- if sellerItemQy == nil {
- err = nil
- return
- }
-
- conf, e := models.GetConfigByCode("tpl_msg_seller_mobile")
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error())
- return
- }
-
- if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) {
- err = nil
- return
- }
- var sourceMsg string
- if source == 1 {
- sourceMsg = "预约外呼"
- } else if source == 2 {
- sourceMsg = "设置会议提醒"
- } else if source == 3 {
- sourceMsg = "预约纪要"
- } else if source == 4 {
- sourceMsg = "活动报名"
- }
- openIdList, e := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
- if e != nil {
- err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
- return err
- }
- var keyword1 string
- var keyword2 string
- keyword1 = activityDetail.ActivityName
- keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
- SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
-
- keyword1 = user.RealName + "-" + user.CompanyName
- keyword2 = fmt.Sprint("互动提醒:", sourceMsg)
- keyword3 := activityDetail.ActivityName
- keyword4 := time.Now().Format(utils.FormatDateTimeMinute2)
- SendWxCategoryMsgWithActivityUserRemind(keyword1, keyword2, keyword3, keyword4, openIdList, activityDetail.ActivityId)
- return
- }
- func ActivityButtonShow(item *models.ActivityDetail) (activityDetail *models.ActivityDetail) {
- if item.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- item.IsResearch = true
- }
- activityDetail = item
-
-
-
-
-
- activityTypeIdMap := GetActivityTypeIdMap()
- activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId]
- activityPointsByUserAllMap := GetActivityPointsByUserAllMap()
- activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
- if activityDetail.SiginupDeadline == utils.FormatDateTimeInit {
- activityDetail.SiginupDeadline = ""
- }
-
- if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
- activityDetail.CancelDeadline = ""
- }
- activityTimeText := activityDetail.ActivityTimeText
- activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
- activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
- activityDetail.ActivityTimeText = activityTimeText
- if activityDetail.SourceType != 2 {
- activityDetail.SourceType = 1
- }
- activityDetail.IsShowAppointment = false
-
- if activityDetail.YidongActivityId != "" {
- activityDetail.SourceType = 1
- activityDetail.IsShowSignup = false
- activityDetail.IsShowDetails = true
- activityDetail.IsExternalLabel = true
- activityDetail.IsResearch = false
- activityDetail.IsResearchSpecial = false
- return
- }
-
- if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
- activityDetail.IsShowHelpSsk = true
- }
-
- if activityDetail.IsCanAppointmentMinutes == 1 {
- activityDetail.IsShowAppointment = true
- } else {
- activityDetail.IsShowAppointment = false
- }
- if activityDetail.ActiveState == "1" {
-
-
- if activityDetail.ActivityTypeId == 1 {
-
- if activityDetail.LimitPeopleNum == 0 {
- activityDetail.IsShowOutboundCall = true
-
- } else {
- activityDetail.IsShowSignup = true
- }
- activityDetail.IsShowMeetingReminder = true
- activityDetail.IsShowHelpSsk = true
- }
-
- if activityDetail.ActivityTypeId == 2 {
- if activityDetail.LimitPeopleNum == 0 {
- activityDetail.IsShowOutboundCall = true
-
- } else {
- activityDetail.IsShowSignup = true
- }
- activityDetail.IsShowMeetingReminder = true
- }
-
- if activityDetail.ActivityTypeId == 3 {
- if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
- activityDetail.IsShowSignup = true
- } else {
- activityDetail.IsShowMeetingReminder = true
- activityDetail.IsShowOutboundCall = true
- }
- }
-
- if activityDetail.ActivityTypeId == 4 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 5 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 6 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 7 {
- activityDetail.IsShowSignup = true
- activityDetail.IsShowMeetingReminder = true
- activityDetail.ActivityTypeName = "分析师电话会"
- }
-
- if activityDetail.ActivityTypeId == 8 {
- activityDetail.IsShowSignup = true
- }
- }
-
- if activityDetail.IsYidongConduct {
- activityDetail.IsShowSignup = true
- activityDetail.IsShowOutboundCall = false
- }
- return
- }
- func ActivityArrButtonShow(items []*models.ActivityDetail) (activityDetails []*models.ActivityDetail) {
- activityPointsByUserAllMap := GetActivityPointsByUserAllMap()
- activityTypeIdMap := GetActivityTypeIdMap()
- for _, activityDetail := range items {
- activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId]
- if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- activityDetail.IsResearch = true
- }
-
- if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
- activityDetail.IsResearchSpecial = true
- }
-
-
-
-
-
- activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
- if activityDetail.SiginupDeadline == utils.FormatDateTimeInit {
- activityDetail.SiginupDeadline = ""
- }
-
- if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
- activityDetail.CancelDeadline = ""
- }
- activityTimeText := activityDetail.ActivityTimeText
- activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
- activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
- activityDetail.ActivityTimeText = activityTimeText
- if activityDetail.SourceType != 2 {
- activityDetail.SourceType = 1
- }
- activityDetail.IsShowAppointment = false
-
- if activityDetail.YidongActivityId != "" {
- activityDetail.SourceType = 1
- activityDetail.IsShowSignup = false
- activityDetail.IsShowDetails = true
- } else {
-
- if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
- activityDetail.IsShowHelpSsk = true
- }
-
- if activityDetail.IsCanAppointmentMinutes == 1 {
- activityDetail.IsShowAppointment = true
- } else {
- activityDetail.IsShowAppointment = false
- }
- if activityDetail.ActiveState == "1" {
-
-
- if activityDetail.ActivityTypeId == 1 {
-
- if activityDetail.LimitPeopleNum == 0 {
- activityDetail.IsShowOutboundCall = true
-
- } else {
- activityDetail.IsShowSignup = true
- }
- activityDetail.IsShowMeetingReminder = true
- activityDetail.IsShowHelpSsk = true
- }
-
- if activityDetail.ActivityTypeId == 2 {
- if activityDetail.LimitPeopleNum == 0 {
- activityDetail.IsShowOutboundCall = true
-
- } else {
- activityDetail.IsShowSignup = true
- }
- activityDetail.IsShowMeetingReminder = true
- }
-
- if activityDetail.ActivityTypeId == 3 {
- if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
- activityDetail.IsShowSignup = true
- } else {
- activityDetail.IsShowMeetingReminder = true
- activityDetail.IsShowOutboundCall = true
- }
- }
-
- if activityDetail.ActivityTypeId == 4 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 5 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 6 {
- activityDetail.IsShowSignup = true
- }
-
- if activityDetail.ActivityTypeId == 7 {
- activityDetail.IsShowSignup = true
- activityDetail.IsShowMeetingReminder = true
- activityDetail.ActivityTypeName = "分析师电话会"
- }
-
- if activityDetail.ActivityTypeId == 8 {
- activityDetail.IsShowSignup = true
- }
- }
-
- if activityDetail.IsYidongConduct {
- activityDetail.IsShowSignup = true
- activityDetail.IsShowOutboundCall = false
- }
- }
-
- if activityDetail.YidongActivityId != "" {
- activityDetail.IsExternalLabel = true
- activityDetail.IsResearch = false
- activityDetail.IsResearchSpecial = false
- }
- if activityDetail.ActivityTypeName == "买方线下交流" {
- activityDetail.LabelKeyword = utils.LABEL_L1_2
- activityDetail.LabelKeywordImgLink = utils.LABEL_ICO_1
- }
- if activityDetail.ActivityTypeName == "专家电话会" || activityDetail.ActivityTypeName == "专家线下沙龙" {
- activityDetail.LabelKeyword = utils.LABEL_L1_3
- activityDetail.LabelKeywordImgLink = utils.LABEL_ICO_2
- }
- if activityDetail.ActivityTypeName == "公司调研电话会" {
- activityDetail.LabelKeyword = utils.LABEL_L1_4
- activityDetail.LabelKeywordImgLink = utils.LABEL_ICO_3
- }
- activityDetails = append(activityDetails, activityDetail)
- }
- return
- }
- func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
- labelMap = make(map[int]bool, 0)
- industryNewMap = make(map[int]bool, 0)
- if len(activityIds) == 0 {
- return
- }
-
- var groupCond string
- var groupPars []interface{}
- groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
- groupPars = append(groupPars, activityIds)
- groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
- if e != nil {
- err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
- return
- }
- activityIndustryMap := make(map[int][]int, 0)
- industryIds := make([]int, 0)
- for i := range groups {
- industryIds = append(industryIds, groups[i].IndustrialManagementId)
- activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
- }
-
- industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
- if e != nil {
- err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
- return
- }
-
- for k := range industryLabelMap {
- for k2, v2 := range activityIndustryMap {
- if labelMap[k2] {
- continue
- }
-
- if utils.InArrayByInt(v2, k) {
- labelMap[k2] = true
- }
- }
- }
-
-
-
-
-
-
-
-
-
- return
- }
- func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
- activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
- if len(activityVoiceList) > 0 {
- for _, v := range activityVoiceList {
- mapActivityVoice[v.ActivityId] = v
- }
- }
- mapItem = mapActivityVoice
- return
- }
- func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
- var condition string
- var ativityVIdstr string
- for _, v := range mapActivityId {
- ativityVIdstr += strconv.Itoa(v) + ","
- }
- if ativityVIdstr == "" {
- return
- }
- ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
- condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
- var pars []interface{}
-
-
-
- videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
- if len(videoList) > 0 {
- for _, v := range videoList {
- mapActivityVideo[v.ActivityId] = v
- }
- }
- mapItem = mapActivityVideo
- return
- }
- func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
- }
- }()
- countUser, err := models.GetUserRemind(user.UserId)
- if err != nil {
- return err
- }
- if countUser == 0 {
- return err
- }
- var first string
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var remark string
-
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if sellerItemQy != nil {
- openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
-
- if fileType == 1 {
- activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- keyword1 = activityInfo.VideoName
- keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
- first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
- } else {
- activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- keyword1 = activityInfo.VoiceName
- keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
- first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
- }
-
-
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- err = PublicSendTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- }
- return
- }
- func GetActivityReportLinkToArticleList(item *models.ActivityDetail) (items []*models.ActivityArticleResp, err error) {
- reportLink := item.ReportLink
-
- var articleIds []int
- var articleList []string
- if strings.Contains(reportLink, ";") {
- articleList = strings.Split(reportLink, ";")
- } else {
- articleList = strings.Split(reportLink, ";")
- }
- for _, v := range articleList {
- linkList := strings.Split(v, "/")
- if linkList[len(linkList)-1] != "" {
- linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
- articleIds = append(articleIds, linkArticleId)
- }
- }
- lenarticleIds := len(articleIds)
- if lenarticleIds == 0 {
- return
- }
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
- pars = append(pars, articleIds)
- listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- if len(listArticle) > 0 {
- for _, v := range listArticle {
- artItem := new(models.ActivityArticleResp)
- artItem.ArticleId = v.ArticleId
- artItem.Title = v.Title
- items = append(items, artItem)
- }
- }
- return
- }
- func GetActivityTypeIdMap() (mapResp map[int]int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("获取活动线上还是线下的类型,失败,GetActivityTypeIdMap:Err "+err.Error(), 2)
- }
- }()
- list, e := models.GetActivityTypeList("")
- if e != nil {
- err = errors.New("GetActivityTypeList, Err: " + e.Error())
- return
- }
- mapResp = make(map[int]int, 0)
- for _, v := range list {
- mapResp[v.ActivityTypeId] = v.ActivityType
- }
- return
- }
- func GetYanxuanActivityIds(user *models.WxUserItem) (activityIds []int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("获取研选活动ID GetYanxuanActivityIds,失败:"+err.Error(), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition = ` AND chart_permission_id = 31 AND art.publish_status = 1 `
-
- if user.CompanyId > 1 {
- conditionActivity, e := ActivityConditioninitSql(user, condition, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("ActivityConditioninitSql, Err: " + e.Error())
- return
- }
- condition += conditionActivity
- }
- condition += ` ORDER BY art.activity_time DESC , art.active_state ASC `
- list, e := models.GetCygxActivityList(condition, pars, 0, 2000)
- if e != nil {
- err = errors.New("GetCygxActivityIdList, Err: " + e.Error())
- return
- }
- for _, v := range list {
- activityIds = append(activityIds, v.ActivityId)
- }
- return
- }
|