chance.go 9.2 KB
package v1

import (
	"encoding/json"
	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
	"opp/controllers"
	"opp/internal/utils"
	"opp/protocol"
	"opp/services/chance"
)

type ChanceController struct {
	controllers.BaseController
}

//IComment
// @router /iComment [post]
func (this *ChanceController) IComment() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ICommentRequest
	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.IComment(header, request))
}

//IComments
// @router /iComments [post]
func (this *ChanceController) IComments() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ICommentsRequest
	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.IComments(header, request))
}

//Comments
// @router /comments [post]
func (this *ChanceController) Comments() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.CommentsRequest
	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)
	request.SourceType = protocol.SourceTypeChance
	msg = protocol.NewReturnResponse(chance.Comments(header, request))
}

//Favorite
// @router /favorite [post]
func (this *ChanceController) Favorite() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.FavoriteRequest
	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.Favorite(header, request))
}

//CommentDetailsSingle
//@router /commentDetailsSingle [post]
func (this *ChanceController) CommentDetailsSingle() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.CommentDetailsSingleRequest
	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.CommentDetailsSingle(header, request))
}

//CommentDetailsMulti
//@router /commentDetailsMulti [post]
func (this *ChanceController) CommentDetailsMulti() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.CommentDetailsMultiRequest
	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.CommentDetailsMulti(header, request))
}

//SympathyAction
//@router /sympathyAction [post]
func (this *ChanceController) SympathyAction() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.SympathyActionRequest
	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
	}
	if !(request.SourceType == protocol.SourceTypeChance || request.SourceType == protocol.SourceTypeComment) {
		msg = protocol.BadRequestParam(2)
		return
	}
	header := controllers.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(chance.SympathyAction(header, request))
}

//ChanceType
//@router /chanceType [post]
func (this *ChanceController) ChanceType() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceTypeRequest
	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.ChanceType(header, request))
}

//Templates
//@router /templates [post]
func (this *ChanceController) Templates() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.TemplatesRequest
	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.Templates(header, request))
}

//ChanceSubmit 提交机会
//@router /submit [post]
func (this *ChanceController) ChanceSubmit() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceSubmitRequest
	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)
	if request.Id > 0 {
		msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
		return
	}
	msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
}

//ChanceStatistics
//@router /statistics [post]
func (this *ChanceController) ChanceStatistics() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceStatisticsRequest
	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.ChanceStatistics(header, request))
}

//MySubmitChance 我提交的机会
//@router /mySubmitChance [post]
func (this *ChanceController) MySubmitChance() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.MySubmitChanceRequest
	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.MySubmitChance(header, request))
}

//ChanceDetail 机会详情
//@router /chanceDetail [post]
func (this *ChanceController) ChanceDetail() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceDetailRequest
	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.ChanceDetail(header, request))
}

//ChanceApproveProcess 机会审核流程信息
//func(this *ChanceController)ChanceApproveProcess(){
//	var msg *protocol.ResponseMessage
//	defer func() {
//		this.Resp(msg)
//	}()
//	var request *protocol.ChanceApproveProcessRequest
//	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.ChanceApproveProcess(header,request))
//}

//ChanceDelete 机会删除
//@router /delete [post]
func (this *ChanceController) ChanceDelete() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceDeleteRequest
	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.ChanceDelete(header, request))
}

//ChanceApprove  机会审核
//@router /approve [post]
func (this *ChanceController) ChanceApprove() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.ChanceApproveRequest
	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
	}
	if request.ReviewStatus == protocol.ReviewStatusPass {
		if utils.IsNil(request.ApproveData) {
			msg = protocol.BadRequestParam(5204)
			return
		}
		if utils.IsNil(request.ApproveData.PublicData) {
			msg = protocol.BadRequestParam(5204)
			return
		}
		if utils.IsNil(request.ApproveData.PublicData) {
			msg = protocol.BadRequestParam(5204)
			return
		}
	}
	header := controllers.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(chance.ChanceApprove(header, request))
}