作者 yangfu

重构-我提交的机会

... ... @@ -116,9 +116,9 @@ func DeleteChance(id int64) (err error) {
func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data,review_status,enable_status,status from chance
select id chance_id,user_id chance_user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data chance_approve_data,review_status,enable_status,status from chance
where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1
) a left JOIN chance_data b on a.id =b.chance_id
) a left JOIN chance_data b on a.chance_id =b.chance_id
order by update_at desc
limit ?
` //approve_time
... ...
... ... @@ -191,8 +191,8 @@ type ChancePoolResponse struct {
//我的机会列表
type ChanceItemOrm struct {
Id int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
ChanceId int64 `orm:"column(id)"`
ChanceUserId int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ApproveTime time.Time `orm:"column(chance_approve_time)"`
... ... @@ -362,14 +362,17 @@ type CommChanceItemOrm struct {
ChanceId int64 `orm:"column(chance_id)"`
ChanceUserId int64 `orm:"column(chance_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ApproveTime time.Time `orm:"column(chance_approve_time)"`
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)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"` //开启状态
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"` //开启状态
ApproveData string `orm:"column(chance_approve_data)"` //审核数据
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
... ...
... ... @@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
item.UpdateTime = chance.UpdateTime.Unix() * 1000
item.ApproveTime = chance.UpdateTime.Unix() * 1000
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
if item.UpdateTime < 0 {
item.UpdateTime = 0
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
... ...
... ... @@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
//我提交的机会
func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) {
var (
myChances []protocol.ChanceItemOrm
total int
provider *protocol.BaseUserInfo
chance *models.Chance
ormItems []protocol.CommChanceItemOrm
chance *models.Chance
)
rsp = &protocol.MySubmitChanceResponse{
List: make([]protocol.CommonListItem, 0),
}
if request.LastId > 0 {
if chance, err = models.GetChanceById(request.LastId); err != nil {
log.Error("机会不存在", request.LastId, err)
... ... @@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
}
request.LastId = chance.UpdateAt.Unix()
}
if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
log.Error(err)
return
}
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.MySubmitChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.CommonListItem{}
{
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ApproveTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
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
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
commItem.ReviewStatus = chance.ReviewStatus
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem)
commItem.ReviewStatus = ormItem.ReviewStatus
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData protocol.ApproveData
jsonUnmarshal(chance.ApproveData, &approveData)
//commItem.ApproveData = approveData //TODO:删除不需要
jsonUnmarshal(ormItem.ApproveData, &approveData)
commItem.Score = approveData.Score
}
rsp.List = append(rsp.List, commItem)
... ...