...
|
...
|
@@ -65,13 +65,15 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
chanceType int
|
|
|
incre int = 1
|
|
|
table string = "comment"
|
|
|
message string = protocol.MessageZanComment
|
|
|
)
|
|
|
rsp = &protocol.SympathyActionResponse{}
|
|
|
if chanceFavoirte, err = models.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
|
|
|
if chanceFavoirte, err = models.GetChanceFavorite(header.UserId, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if request.SourceType == protocol.SourceTypeChance {
|
|
|
message = protocol.MessageZanChance
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
log.Error("机会不存在", err)
|
|
|
return
|
...
|
...
|
@@ -102,7 +104,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
}
|
|
|
}
|
|
|
if exists {
|
|
|
if err = models.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
|
|
|
if err = models.UpdateChanceFavorite(header.UserId, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
|
|
|
log.Error(request.MarkType, err)
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -111,7 +113,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
//add
|
|
|
chanceFavoirte = &models.ChanceFavorite{
|
|
|
Id: idgen.Next(),
|
|
|
UserId: header.Uid,
|
|
|
UserId: header.UserId,
|
|
|
CompanyId: header.CompanyId,
|
|
|
MarkFlag: request.SympathyType,
|
|
|
SourceType: request.SourceType,
|
...
|
...
|
@@ -124,7 +126,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
log.Error(err)
|
|
|
return
|
|
|
} else {
|
|
|
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v", header.Uid, request.Id, request.SympathyType))
|
|
|
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v", header.UserId, request.Id, request.SympathyType))
|
|
|
goto END
|
|
|
}
|
|
|
END:
|
...
|
...
|
@@ -134,6 +136,11 @@ END: |
|
|
}
|
|
|
if request.SympathyType == protocol.UnMarkFlag {
|
|
|
incre = -1
|
|
|
//删除点赞消息
|
|
|
agg.DeleteSendedMsg(chance.Id, protocol.SourceTypeChance, chance.UserId, protocol.MsgTypeThumbUp)
|
|
|
} else {
|
|
|
//发送点赞消息
|
|
|
agg.SendMsg(chance.UserId, fmt.Sprintf("%v", chance.UserId), chance.CompanyId, chance.Id, 1, message, protocol.MsgTypeThumbUp)
|
|
|
}
|
|
|
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
|
|
|
//
|
...
|
...
|
@@ -276,7 +283,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
|
|
|
//生成提交记录
|
|
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id)); err != nil {
|
|
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
@@ -487,6 +494,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
chance *models.Chance
|
|
|
mapChance = make(map[string]interface{})
|
|
|
approveData protocol.ApproveData
|
|
|
result *protocol.ChanceCalculateScoreResponse
|
|
|
)
|
|
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5101) //不存在
|
...
|
...
|
@@ -496,6 +504,13 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
err = protocol.NewErrWithMessage(5205)
|
|
|
return
|
|
|
}
|
|
|
if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.Score}); err != nil {
|
|
|
log.Error("计算发现分错误:", err)
|
|
|
//err = protocol.NewErrWithMessage(5511)
|
|
|
return
|
|
|
}
|
|
|
request.Score.DiscoveryScore = result.DiscoveryScore
|
|
|
request.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
|
|
|
//TODO:角色检查权限
|
|
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
|
|
approveData.Score = request.Score
|
...
|
...
|
@@ -505,7 +520,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
mapChance["BasicScore"] = request.Score.BasicScore
|
|
|
mapChance["ExtraScore"] = request.Score.ExtraScore
|
|
|
mapChance["ValueScore"] = request.Score.ValueScore
|
|
|
mapChance["DiscoveryScore"] = request.Score.DiscoveryScore
|
|
|
mapChance["DiscoveryScore"] = result.DiscoveryScore
|
|
|
}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
...
|
...
|
@@ -521,10 +536,60 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
|
|
|
//计算发现分
|
|
|
func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.ChanceCalculateScoreRequest) (rsp *protocol.ChanceCalculateScoreResponse, err error) {
|
|
|
var ()
|
|
|
//TODO:取配置数据
|
|
|
var (
|
|
|
config *models.SysConfig
|
|
|
scoreConfig protocol.ScoreConfig
|
|
|
sum float64
|
|
|
)
|
|
|
rsp = &protocol.ChanceCalculateScoreResponse{}
|
|
|
rsp.DiscoveryScore = request.Score.BasicScore*1.0 + request.Score.ExtraScore*1.0 + request.Score.ValueScore*1.0
|
|
|
if config, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5510)
|
|
|
log.Error(header.CompanyId, err)
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5510)
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
{
|
|
|
basic := request.Score.BasicScore
|
|
|
if basic < scoreConfig.BasicScore.Min || basic > scoreConfig.BasicScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5501)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", basic, scoreConfig.BasicScore.Min, scoreConfig.BasicScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.BasicScore.Max * scoreConfig.DiscoveryScore.BasicFactor
|
|
|
}
|
|
|
{
|
|
|
extral := request.Score.ExtraScore
|
|
|
if extral < scoreConfig.ExtraScore.Min || extral > scoreConfig.ExtraScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5502)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", extral, scoreConfig.ExtraScore.Min, scoreConfig.ExtraScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.ExtraScore.Max * scoreConfig.DiscoveryScore.ExtraFactor
|
|
|
}
|
|
|
{
|
|
|
value := request.Score.ValueScore
|
|
|
if value < scoreConfig.ValueScore.Min || value > scoreConfig.ValueScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5502)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", value, scoreConfig.ValueScore.Min, scoreConfig.ValueScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
|
|
|
}
|
|
|
rsp.DiscoveryScore = request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor
|
|
|
rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100)
|
|
|
log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
|
|
|
//发现分不为0
|
|
|
if request.Score.DiscoveryScore != 0 {
|
|
|
if request.Score.DiscoveryScore != 0 && rsp.DiscoveryScore != request.Score.DiscoveryScore {
|
|
|
log.Error(fmt.Sprintf("input :%v out:%v want:%v", request.Score.DiscoveryScore, rsp.DiscoveryScore, request.Score.DiscoveryScore))
|
|
|
err = protocol.NewErrWithMessage(5511)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -542,7 +607,7 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe |
|
|
}
|
|
|
|
|
|
//生成审批流-提交记录
|
|
|
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64) (v *models.AuditFlowProcess) {
|
|
|
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
|
|
|
v = &models.AuditFlowProcess{
|
|
|
Id: idgen.Next(),
|
|
|
ChanceId: chanceId,
|
...
|
...
|
@@ -551,7 +616,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, |
|
|
UpdateAt: time.Now(),
|
|
|
ApproveTime: time.Now(),
|
|
|
EnableStatus: 1,
|
|
|
ReviewStatus: protocol.ReviewStatusSubmit,
|
|
|
ReviewStatus: int8(reviewStatus),
|
|
|
}
|
|
|
if approver, err := models.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -759,6 +824,8 @@ func getParentDepartmentors(pid int) (ids []int64) { |
|
|
func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceStatisticsRequest) (rsp *protocol.ChanceStatisticsResponse, err error) {
|
|
|
var (
|
|
|
chanceType []*models.ChanceType
|
|
|
total int
|
|
|
sum int
|
|
|
)
|
|
|
if chanceType, err = models.GetChanceTypeAll(header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -767,12 +834,18 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt |
|
|
rsp = &protocol.ChanceStatisticsResponse{}
|
|
|
for i := range chanceType {
|
|
|
item := chanceType[i]
|
|
|
if total, err = models.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
sum += total
|
|
|
rsp.List = append(rsp.List, protocol.ChanceTotalItem{
|
|
|
Id: item.Id,
|
|
|
Name: item.Name,
|
|
|
Total: i * 2,
|
|
|
Total: total,
|
|
|
})
|
|
|
}
|
|
|
rsp.ChanceTotal = sum
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -849,7 +922,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ |
|
|
commItem := protocol.CommonListItem{}
|
|
|
{
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.Id,
|
|
|
Id: chance.ChanceId,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
...
|
...
|
@@ -867,7 +940,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ |
|
|
CommentTotal: chance.CommentTotal,
|
|
|
PageViewTotal: chance.ViewTotal,
|
|
|
}
|
|
|
if flag, err = agg.GetChanceMarkData(header.UserId, header.CompanyId, chance.Id); err != nil {
|
|
|
if flag, err = agg.GetChanceMarkData(header.UserId, header.CompanyId, chance.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
continue
|
|
|
}
|
...
|
...
|
@@ -903,7 +976,6 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove |
|
|
total int
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
rsp = &protocol.MyApproveChanceResponse{}
|
|
|
if total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
...
|
...
|
@@ -922,9 +994,10 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove |
|
|
} else if chance.ChanceEnableStatus == 0 { //机会关闭
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusClose
|
|
|
} else {
|
|
|
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
log.Error(err)
|
|
|
log.Error(chance.ChanceUserId, header.CompanyId, err)
|
|
|
err = nil
|
|
|
//return
|
|
|
} else {
|
|
|
item := protocol.ChanceItem{
|
...
|
...
|
@@ -966,6 +1039,264 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove |
|
|
return
|
|
|
}
|
|
|
|
|
|
// 我的收藏
|
|
|
func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollectChanceRequest) (rsp *protocol.MyCollectChanceResponse, err error) {
|
|
|
var (
|
|
|
myChances []protocol.ChanceCollectItemOrm
|
|
|
total int
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
if total, err = models.GetChanceCollect(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MyCollectChanceResponse{Total: total}
|
|
|
for i := 0; i < len(myChances); i++ {
|
|
|
chance := myChances[i]
|
|
|
commItem := protocol.CommonListItem{}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
if len(chance.SourceContent) == 0 { //机会删除
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
} else if chance.ChanceEnableStatus == 0 { //机会关闭
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusClose
|
|
|
} else {
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
log.Error(err)
|
|
|
//return
|
|
|
} else {
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.ChanceId,
|
|
|
Provider: provider,
|
|
|
//CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chance.Voices, &item.Speechs)
|
|
|
jsonUnmarshal(chance.Videos, &item.Videos)
|
|
|
commItem.Chance = item
|
|
|
}
|
|
|
}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
{
|
|
|
var chanceData = protocol.ChanceData{
|
|
|
ThumbsUpTotal: chance.ZanTotal,
|
|
|
CommentTotal: chance.CommentTotal,
|
|
|
PageViewTotal: chance.ViewTotal,
|
|
|
}
|
|
|
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId)
|
|
|
commItem.ChanceData = chanceData
|
|
|
}
|
|
|
{
|
|
|
//做一次查询 查回所有的模板数据
|
|
|
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
|
|
|
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
|
|
|
}
|
|
|
{
|
|
|
//收藏数据
|
|
|
commItem.CollectData = protocol.CollectData{
|
|
|
Id: chance.CollectId,
|
|
|
CollectTime: chance.CollectTime.Unix() * 1000,
|
|
|
}
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//我点赞的机会
|
|
|
func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUpChanceRequest) (rsp *protocol.MyThumbUpChanceResponse, err error) {
|
|
|
var (
|
|
|
myChances []protocol.ChanceThumbUpItemOrm
|
|
|
total int
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MyThumbUpChanceResponse{Total: total}
|
|
|
for i := 0; i < len(myChances); i++ {
|
|
|
chance := myChances[i]
|
|
|
commItem := protocol.CommonListItem{}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
if len(chance.SourceContent) == 0 { //机会删除
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
} else if chance.ChanceEnableStatus == 0 { //机会关闭
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusClose
|
|
|
} else {
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
log.Error(err)
|
|
|
//return
|
|
|
} else {
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.ChanceId,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chance.Voices, &item.Speechs)
|
|
|
jsonUnmarshal(chance.Videos, &item.Videos)
|
|
|
commItem.Chance = item
|
|
|
}
|
|
|
}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
{
|
|
|
var chanceData = protocol.ChanceData{
|
|
|
ThumbsUpTotal: chance.ZanTotal,
|
|
|
CommentTotal: chance.CommentTotal,
|
|
|
PageViewTotal: chance.ViewTotal,
|
|
|
}
|
|
|
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId)
|
|
|
commItem.ChanceData = chanceData
|
|
|
}
|
|
|
{
|
|
|
//做一次查询 查回所有的模板数据
|
|
|
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
|
|
|
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
|
|
|
}
|
|
|
{
|
|
|
//收藏数据
|
|
|
commItem.ThumbUpData = protocol.ThumbUpData{
|
|
|
Id: chance.CollectId,
|
|
|
ThumbUpTime: chance.CollectTime.Unix() * 1000,
|
|
|
}
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//我的评论
|
|
|
func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentRequest) (rsp *protocol.MyCommentResponse, err error) {
|
|
|
var (
|
|
|
myChances []protocol.ChanceCommentItemOrm
|
|
|
total int
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MyCommentResponse{Total: total}
|
|
|
for i := 0; i < len(myChances); i++ {
|
|
|
chance := myChances[i]
|
|
|
commItem := protocol.CommonListItem{}
|
|
|
if chance.SourceType == protocol.SourceTypeChance {
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
if len(chance.SourceContent) == 0 { //机会删除
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
} else if chance.ChanceEnableStatus == 0 { //机会关闭
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusClose
|
|
|
} else {
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
|
|
|
commItem.ChanceStatus = protocol.ChanceStatusDelete
|
|
|
log.Error(err)
|
|
|
//return
|
|
|
} else {
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.SourceId,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chance.Voices, &item.Speechs)
|
|
|
jsonUnmarshal(chance.Videos, &item.Videos)
|
|
|
commItem.Chance = item
|
|
|
}
|
|
|
}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
//{
|
|
|
// var chanceData = protocol.ChanceData{
|
|
|
// ThumbsUpTotal: chance.ZanTotal,
|
|
|
// CommentTotal: chance.CommentTotal,
|
|
|
// PageViewTotal: chance.ViewTotal,
|
|
|
// }
|
|
|
// chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.SourceType)
|
|
|
// commItem.ChanceData = chanceData
|
|
|
//}
|
|
|
//{
|
|
|
// //做一次查询 查回所有的模板数据
|
|
|
// commItem.ChanceTemplate = getTemplate(chance.TemplateId)
|
|
|
// commItem.ChanceType = getChanceType(chance.ChanceTypeId)
|
|
|
//}
|
|
|
}
|
|
|
if chance.SourceType == protocol.SourceTypeComment {
|
|
|
commItem.CommentedData = protocol.CommentData{
|
|
|
Id: chance.SourceId,
|
|
|
Content: chance.CommentedContent,
|
|
|
CommentTime: chance.CommentedTime.Unix() * 1000,
|
|
|
}
|
|
|
}
|
|
|
commItem.CommentData = protocol.CommentData{
|
|
|
Id: chance.CommentId,
|
|
|
CommentTime: chance.CommentTime.Unix() * 1000,
|
|
|
Content: chance.CommentContent,
|
|
|
}
|
|
|
commItem.SourceType = chance.SourceType
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取机会点赞/收藏状态
|
|
|
func getChanceMarkFlag(header *protocol.RequestHeader, chanceId int64) (isThumbsUp, isCollect bool, err error) {
|
|
|
var flag int
|
|
|
if flag, err = agg.GetChanceMarkData(header.UserId, header.CompanyId, chanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
isThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan
|
|
|
isCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取模板
|
|
|
func getTemplate(templateId int) protocol.NameItem {
|
|
|
if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil {
|
|
|
item := protocol.NameItem{
|
|
|
Id: int(template.Id),
|
|
|
Name: template.Name,
|
|
|
}
|
|
|
return item
|
|
|
} else {
|
|
|
log.Error(templateId, e)
|
|
|
}
|
|
|
return protocol.NameItem{}
|
|
|
}
|
|
|
|
|
|
//获取机会一级分类
|
|
|
func getChanceType(chanceTypeId int) protocol.NameItem {
|
|
|
if template, e := models.GetChanceTypeById(chanceTypeId); e == nil {
|
|
|
item := protocol.NameItem{
|
|
|
Id: int(template.Id),
|
|
|
Name: template.Name,
|
|
|
}
|
|
|
return item
|
|
|
} else {
|
|
|
log.Error(chanceTypeId, e)
|
|
|
}
|
|
|
return protocol.NameItem{}
|
|
|
}
|
|
|
|
|
|
func jsonUnmarshal(jsonData string, v interface{}) {
|
|
|
if len(jsonData) == 0 {
|
|
|
return
|
...
|
...
|
@@ -998,6 +1329,7 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
approveProcess *protocol.ChanceApproveProcessResponse
|
|
|
//chanceType *models.ChanceType
|
|
|
//tempalte *models.AuditTemplate
|
|
|
table string = "chance"
|
|
|
)
|
|
|
rsp = &protocol.ChanceDetailResponse{}
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
...
|
...
|
@@ -1024,6 +1356,11 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
if chance.ReviewStatus == protocol.ReviewStatusPass {
|
|
|
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "view_total", 1, request.Id)) {
|
|
|
//
|
|
|
}
|
|
|
}
|
|
|
//用户信息
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -1051,6 +1388,22 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
rsp.ApproveProcess = approveProcess.ApproveProcess
|
|
|
rsp.ApproveAccess = approveProcess.ApproveAccess
|
|
|
}
|
|
|
|
|
|
{
|
|
|
var flag int
|
|
|
var chanceData = protocol.ChanceData{
|
|
|
ThumbsUpTotal: chance.ZanTotal,
|
|
|
CommentTotal: chance.CommentTotal,
|
|
|
PageViewTotal: chance.ViewTotal,
|
|
|
}
|
|
|
if flag, err = agg.GetChanceMarkData(header.UserId, header.CompanyId, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
chanceData.IsThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan
|
|
|
chanceData.IsCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
|
|
|
rsp.StatisticData = chanceData
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|