作者 yangfu

我的点赞/收藏

... ... @@ -12,7 +12,7 @@ aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#redis相关配置
redis_add = "${REDIS_HOST||192.168.100.102}"
redis_add = "${REDIS_HOST||127.0.0.1}"
redis_add_port = "${REDIS_PORT||6379}"
redis_auth = "123456"
... ...
... ... @@ -294,27 +294,6 @@ func (this *ChanceController) MySubmitChance() {
msg = protocol.NewReturnResponse(chance.MySubmitChance(header, request))
}
//ChancePool 机会池
//@router /chancePool [post]
func (this *ChanceController) ChancePool() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChancePoolRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
}
//ChanceDetail 机会详情
//@router /chanceDetail [post]
func (this *ChanceController) ChanceDetail() {
... ... @@ -488,3 +467,66 @@ func (this *ChanceController) MyApproveChance() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyApproveChance(header, request))
}
//MyCollectChance 我的收藏
//@router /myCollectChance [post]
func (this *ChanceController) MyCollectChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyCollectChanceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyCollectChance(header, request))
}
//MyThumbUpChance 我点赞的机会
//@router /myThumbUpChance [post]
func (this *ChanceController) MyThumbUpChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyThumbUpChanceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyThumbUpChance(header, request))
}
//ChancePool 机会池
//@router /chancePool [post]
func (this *ChanceController) ChancePool() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChancePoolRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
}
... ...
... ... @@ -173,3 +173,49 @@ order by create_at desc
}
return
}
func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id>?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&2)>0
)a left outer join chance b on a.source_id = b.id
)a left outer join chance_data b on a.source_id =b.chance_id
order by collect_time desc
limit ?`)
sqlCount := `select count(0) from chance_favorite where user_id =? and enable_status=1 and (mark_flag&2)>0`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, lastId, lastId, uid, pageSize); err != nil {
return
}
}
return
}
func GetChanceThumbUp(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id>?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&1)>0
)a left outer join chance b on a.source_id = b.id
)a left outer join chance_data b on a.source_id =b.chance_id
order by collect_time desc
limit ?`)
sqlCount := `select count(0) from chance_favorite where user_id =? and enable_status=1 and (mark_flag&2)>0`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, lastId, lastId, uid, pageSize); err != nil {
return
}
}
return
}
... ...
... ... @@ -198,9 +198,29 @@ type ChanceApproveItemOrm struct {
ChanceId int64 `orm:"column(chance_id)"` // 机会id
}
/*MyCollectChance 我的收藏*/
type MyCollectChanceRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MyCollectChanceResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
/*MyThumbUpChance 我点赞的机会*/
type MyThumbUpChanceRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MyThumbUpChanceResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
//机会池列表
type ChancePoolItemOrm struct {
Id int64 `orm:"column(id)"`
ChanceId int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
SourceContent string `orm:"column(source_content)"`
... ... @@ -210,12 +230,60 @@ type ChancePoolItemOrm struct {
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
}
//机会池收藏列表项
type ChanceCollectItemOrm struct {
ChanceId int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
CollectId int64 `orm:"column(collect_id)"` //收藏id
CollectTime time.Time `orm:"column(collect_time)"` //收藏时间
}
//机会池收藏列表项
type ChanceThumbUpItemOrm struct {
ChanceId int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
CollectId int64 `orm:"column(collect_id)"` //收藏id
CollectTime time.Time `orm:"column(collect_time)"` //收藏时间
}
/*ChanceDetail 机会详情*/
... ... @@ -352,7 +420,9 @@ type CommonListItem struct {
Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve
ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData
Message interface{} `json:"message,omitempty"` //消息
Comment interface{} `json:"comment,omitempty"` //评论
CommentData interface{} `json:"commentData,omitempty"` //评论
CollectData interface{} `json:"collectData,omitempty"` //收藏数据
ThumbUpData interface{} `json:"thumbUpData,omitempty"` //点赞数据
//我审核的-通过
Score interface{} `json:"score,omitempty"`
... ... @@ -380,3 +450,15 @@ type ChanceData struct {
IsThumbsUp bool `json:"isThumbsUp"` //是否点赞 1 点赞, 0 没有点赞
IsCollect bool `json:"isCollect"` //是否收藏 1 是 0 否
}
//收藏数据
type CollectData struct {
Id int64 `json:"id"`
CollectTime int64 `json:"collectTime"` //收藏时间
}
//点赞数据
type ThumbUpData struct {
Id int64 `json:"id"`
ThumbUpTime int64 `json:"thumbUpTime"` //收藏时间
}
... ...
... ... @@ -177,6 +177,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MyCollectChance",
Router: `/myCollectChance`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MySubmitChance",
Router: `/mySubmitChance`,
AllowHTTPMethods: []string{"post"},
... ... @@ -185,6 +193,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MyThumbUpChance",
Router: `/myThumbUpChance`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Permission",
Router: `/permission`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -864,7 +864,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,
}
... ... @@ -882,7 +882,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
}
... ... @@ -918,7 +918,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
... ... @@ -981,6 +980,186 @@ 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(header.UserId, 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(header.UserId, 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 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
... ...
... ... @@ -373,6 +373,16 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis
for flag = 1; flag <= (protocol.MyAuditChanceReturn); flag = flag << 1 {
total = 0
switch flag {
case protocol.CollectStatic: //收藏
if total, err = models.GetChanceCollect(header.UserId, 0, 0, nil); err != nil {
log.Error(err)
}
break
case protocol.ZanStatic: //点赞
if total, err = models.GetChanceThumbUp(header.UserId, 0, 0, nil); err != nil {
log.Error(err)
}
break
case protocol.MyCommitChance:
if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {
log.Error(err)
... ...