作者 yangfu

重构-我提交的机会

@@ -116,9 +116,9 @@ func DeleteChance(id int64) (err error) { @@ -116,9 +116,9 @@ func DeleteChance(id int64) (err error) {
116 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 116 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
117 sql := `select a.*,b.images,speechs,videos 117 sql := `select a.*,b.images,speechs,videos
118 from ( 118 from (
119 -select id,user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data,review_status,enable_status,status from chance 119 +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
120 where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1 120 where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1
121 -) a left JOIN chance_data b on a.id =b.chance_id 121 +) a left JOIN chance_data b on a.chance_id =b.chance_id
122 order by update_at desc 122 order by update_at desc
123 limit ? 123 limit ?
124 ` //approve_time 124 ` //approve_time
@@ -191,8 +191,8 @@ type ChancePoolResponse struct { @@ -191,8 +191,8 @@ type ChancePoolResponse struct {
191 191
192 //我的机会列表 192 //我的机会列表
193 type ChanceItemOrm struct { 193 type ChanceItemOrm struct {
194 - Id int64 `orm:"column(id)"`  
195 - Uid int64 `orm:"column(user_id)"` 194 + ChanceId int64 `orm:"column(id)"`
  195 + ChanceUserId int64 `orm:"column(user_id)"`
196 CreateTime time.Time `orm:"column(create_at)"` 196 CreateTime time.Time `orm:"column(create_at)"`
197 UpdateTime time.Time `orm:"column(update_at)"` 197 UpdateTime time.Time `orm:"column(update_at)"`
198 ApproveTime time.Time `orm:"column(chance_approve_time)"` 198 ApproveTime time.Time `orm:"column(chance_approve_time)"`
@@ -362,6 +362,8 @@ type CommChanceItemOrm struct { @@ -362,6 +362,8 @@ type CommChanceItemOrm struct {
362 ChanceId int64 `orm:"column(chance_id)"` 362 ChanceId int64 `orm:"column(chance_id)"`
363 ChanceUserId int64 `orm:"column(chance_user_id)"` 363 ChanceUserId int64 `orm:"column(chance_user_id)"`
364 CreateTime time.Time `orm:"column(create_at)"` 364 CreateTime time.Time `orm:"column(create_at)"`
  365 + UpdateTime time.Time `orm:"column(update_at)"`
  366 + ApproveTime time.Time `orm:"column(chance_approve_time)"`
365 SourceContent string `orm:"column(source_content)"` 367 SourceContent string `orm:"column(source_content)"`
366 ChanceEnableStatus int `orm:"column(enable_status)"` 368 ChanceEnableStatus int `orm:"column(enable_status)"`
367 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过 369 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
@@ -370,6 +372,7 @@ type CommChanceItemOrm struct { @@ -370,6 +372,7 @@ type CommChanceItemOrm struct {
370 Videos string `orm:"column(videos)"` 372 Videos string `orm:"column(videos)"`
371 PublishStatus int `orm:"column(publish_status)"` //公开状态 373 PublishStatus int `orm:"column(publish_status)"` //公开状态
372 Status int `orm:"column(status)"` //开启状态 374 Status int `orm:"column(status)"` //开启状态
  375 + ApproveData string `orm:"column(chance_approve_data)"` //审核数据
373 CommentTotal int `orm:"column(comment_total)"` 376 CommentTotal int `orm:"column(comment_total)"`
374 ZanTotal int `orm:"column(zan_total)"` 377 ZanTotal int `orm:"column(zan_total)"`
375 ViewTotal int `orm:"column(view_total)"` 378 ViewTotal int `orm:"column(view_total)"`
@@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte @@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
222 CreateTime: chance.CreateTime.Unix() * 1000, 222 CreateTime: chance.CreateTime.Unix() * 1000,
223 PublicStatus: chance.PublishStatus, 223 PublicStatus: chance.PublishStatus,
224 } 224 }
  225 + item.UpdateTime = chance.UpdateTime.Unix() * 1000
  226 + item.ApproveTime = chance.UpdateTime.Unix() * 1000
  227 + if item.ApproveTime < 0 {
  228 + item.ApproveTime = 0
  229 + }
  230 + if item.UpdateTime < 0 {
  231 + item.UpdateTime = 0
  232 + }
225 utils.JsonUnmarshal(chance.SourceContent, &item.FormList) 233 utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
226 item.FormList = ClearEmptyForm(item.FormList) 234 item.FormList = ClearEmptyForm(item.FormList)
227 utils.JsonUnmarshal(chance.Images, &item.Pictures) 235 utils.JsonUnmarshal(chance.Images, &item.Pictures)
@@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt @@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
1494 //我提交的机会 1494 //我提交的机会
1495 func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) { 1495 func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) {
1496 var ( 1496 var (
1497 - myChances []protocol.ChanceItemOrm  
1498 - total int  
1499 - provider *protocol.BaseUserInfo 1497 + ormItems []protocol.CommChanceItemOrm
1500 chance *models.Chance 1498 chance *models.Chance
1501 ) 1499 )
  1500 + rsp = &protocol.MySubmitChanceResponse{
  1501 + List: make([]protocol.CommonListItem, 0),
  1502 + }
1502 if request.LastId > 0 { 1503 if request.LastId > 0 {
1503 if chance, err = models.GetChanceById(request.LastId); err != nil { 1504 if chance, err = models.GetChanceById(request.LastId); err != nil {
1504 log.Error("机会不存在", request.LastId, err) 1505 log.Error("机会不存在", request.LastId, err)
@@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1506 } 1507 }
1507 request.LastId = chance.UpdateAt.Unix() 1508 request.LastId = chance.UpdateAt.Unix()
1508 } 1509 }
1509 - if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1510 + if rsp.Total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1510 if err == orm.ErrNoRows { 1511 if err == orm.ErrNoRows {
1511 err = nil 1512 err = nil
1512 return 1513 return
@@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1514 log.Error(err) 1515 log.Error(err)
1515 return 1516 return
1516 } 1517 }
1517 - if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {  
1518 - log.Error(err)  
1519 - return  
1520 - }  
1521 - rsp = &protocol.MySubmitChanceResponse{Total: total}  
1522 1518
1523 - for i := 0; i < len(myChances); i++ {  
1524 - chance := myChances[i] 1519 + for i := 0; i < len(ormItems); i++ {
  1520 + ormItem := ormItems[i]
1525 commItem := protocol.CommonListItem{} 1521 commItem := protocol.CommonListItem{}
1526 - {  
1527 - item := protocol.ChanceItem{  
1528 - Id: chance.Id,  
1529 - Provider: provider,  
1530 - CreateTime: chance.CreateTime.Unix() * 1000,  
1531 - UpdateTime: chance.UpdateTime.Unix() * 1000,  
1532 - ApproveTime: chance.ApproveTime.Unix() * 1000,  
1533 - }  
1534 - if item.ApproveTime < 0 {  
1535 - item.ApproveTime = 0  
1536 - }  
1537 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1538 - item.FormList = clearEmptyForm(item.FormList)  
1539 - jsonUnmarshal(chance.Images, &item.Pictures)  
1540 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1541 - jsonUnmarshal(chance.Videos, &item.Videos)  
1542 - commItem.Chance = item  
1543 - }  
1544 - if chance.Status == models.ChanceStatusClose {  
1545 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1546 - }  
1547 - commItem.ReviewStatus = chance.ReviewStatus 1522 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem)
  1523 + commItem.ReviewStatus = ormItem.ReviewStatus
1548 if request.ReviewStatus == protocol.ReviewStatusPass { 1524 if request.ReviewStatus == protocol.ReviewStatusPass {
1549 var approveData protocol.ApproveData 1525 var approveData protocol.ApproveData
1550 - jsonUnmarshal(chance.ApproveData, &approveData)  
1551 - //commItem.ApproveData = approveData //TODO:删除不需要 1526 + jsonUnmarshal(ormItem.ApproveData, &approveData)
1552 commItem.Score = approveData.Score 1527 commItem.Score = approveData.Score
1553 } 1528 }
1554 rsp.List = append(rsp.List, commItem) 1529 rsp.List = append(rsp.List, commItem)