作者 yangfu

上传修改

1 package v1 1 package v1
2 2
3 import ( 3 import (
  4 + "fmt"
4 "opp/controllers" 5 "opp/controllers"
5 "opp/protocol" 6 "opp/protocol"
6 "opp/services/upload" 7 "opp/services/upload"
@@ -18,25 +19,27 @@ func (this *UploadController) Image() { @@ -18,25 +19,27 @@ func (this *UploadController) Image() {
18 var ( 19 var (
19 msg *protocol.ResponseMessage 20 msg *protocol.ResponseMessage
20 err error 21 err error
  22 + rsp *protocol.FileResponse = &protocol.FileResponse{}
21 ) 23 )
22 defer func() { 24 defer func() {
23 this.Resp(msg) 25 this.Resp(msg)
24 }() 26 }()
25 var request = &protocol.FileRequest{} 27 var request = &protocol.FileRequest{}
26 - //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{  
27 - // log.Error(err)  
28 - // msg = protocol.ReturnResponse(1)  
29 - // return  
30 - //}  
31 - //if b,m :=this.Valid(request);!b{  
32 - // msg = m  
33 - // return  
34 - //}  
35 - if request.Files, err = this.GetFiles("image"); err != nil { 28 + for i := 1; i <= 9; i++ {
  29 + var tmp *protocol.FileResponse
  30 + key := fmt.Sprintf("%v%v", "image", i)
  31 + if request.Files, err = this.GetFiles(key); err != nil {
  32 + log.Error(key, err)
  33 + err = nil
  34 + break
  35 + }
  36 + if tmp, err = upload.Image(request); err != nil {
36 log.Error(err) 37 log.Error(err)
37 return 38 return
38 } 39 }
39 - msg = protocol.NewReturnResponse(upload.Image(request)) 40 + rsp.Paths = append(rsp.Paths, tmp.Paths...)
  41 + }
  42 + msg = protocol.NewReturnResponse(rsp, err)
40 } 43 }
41 44
42 // Voice 45 // Voice
@@ -45,25 +48,27 @@ func (this *UploadController) Voice() { @@ -45,25 +48,27 @@ func (this *UploadController) Voice() {
45 var ( 48 var (
46 msg *protocol.ResponseMessage 49 msg *protocol.ResponseMessage
47 err error 50 err error
  51 + rsp *protocol.FileResponse = &protocol.FileResponse{}
48 ) 52 )
49 defer func() { 53 defer func() {
50 this.Resp(msg) 54 this.Resp(msg)
51 }() 55 }()
52 var request = &protocol.FileRequest{} 56 var request = &protocol.FileRequest{}
53 - //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{  
54 - // log.Error(err)  
55 - // msg = protocol.ReturnResponse(1)  
56 - // return  
57 - //}  
58 - //if b,m :=this.Valid(request);!b{  
59 - // msg = m  
60 - // return  
61 - //}  
62 - if request.Files, err = this.GetFiles("file"); err != nil { 57 + for i := 1; i <= 9; i++ {
  58 + var tmp *protocol.FileResponse
  59 + key := fmt.Sprintf("%v%v", "voice", i)
  60 + if request.Files, err = this.GetFiles(key); err != nil {
  61 + log.Error(key, err)
  62 + err = nil
  63 + break
  64 + }
  65 + if tmp, err = upload.Voice(request); err != nil {
63 log.Error(err) 66 log.Error(err)
64 return 67 return
65 } 68 }
66 - msg = protocol.NewReturnResponse(upload.Voice(request)) 69 + rsp.Paths = append(rsp.Paths, tmp.Paths...)
  70 + }
  71 + msg = protocol.NewReturnResponse(rsp, err)
67 } 72 }
68 73
69 // Video 74 // Video
@@ -76,10 +81,12 @@ func (this *UploadController) Video() { @@ -76,10 +81,12 @@ func (this *UploadController) Video() {
76 defer func() { 81 defer func() {
77 this.Resp(msg) 82 this.Resp(msg)
78 }() 83 }()
  84 + for i := 1; i <= 9; i++ {
79 var request = &protocol.FileRequest{} 85 var request = &protocol.FileRequest{}
80 if request.Files, err = this.GetFiles("file"); err != nil { 86 if request.Files, err = this.GetFiles("file"); err != nil {
81 log.Error(err) 87 log.Error(err)
82 return 88 return
83 } 89 }
84 msg = protocol.NewReturnResponse(upload.Video(request)) 90 msg = protocol.NewReturnResponse(upload.Video(request))
  91 + }
85 } 92 }
@@ -119,7 +119,7 @@ type Form struct { @@ -119,7 +119,7 @@ type Form struct {
119 type ChanceSubmitRequest struct { 119 type ChanceSubmitRequest struct {
120 Id int64 `json:"id"` // = 0添加 >0 编辑 120 Id int64 `json:"id"` // = 0添加 >0 编辑
121 AuditTemplateId int64 `json:"auditTemplateId" valid:"Required"` 121 AuditTemplateId int64 `json:"auditTemplateId" valid:"Required"`
122 - Content string `json:"content" valid:"Required"` 122 + Content string `json:"content"`
123 FormList []*Form `json:"formList" valid:"Required"` 123 FormList []*Form `json:"formList" valid:"Required"`
124 Speechs []Speech `json:"speechs"` 124 Speechs []Speech `json:"speechs"`
125 Pictures []Picture `json:"pictures"` 125 Pictures []Picture `json:"pictures"`