|
@@ -1,11 +1,17 @@
|
1
|
1
|
package goods
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "budget/helper"
|
|
5
|
+ "cdkj-check/models"
|
4
|
6
|
"encoding/json"
|
5
|
7
|
"errors"
|
6
|
8
|
"spaceofcheng/services/models/model"
|
7
|
9
|
"spaceofcheng/services/utils"
|
|
10
|
+ "strconv"
|
8
|
11
|
"time"
|
|
12
|
+
|
|
13
|
+ "github.com/astaxie/beego"
|
|
14
|
+ "github.com/tealeg/xlsx"
|
9
|
15
|
)
|
10
|
16
|
|
11
|
17
|
// GetOrderList 获取商品订单
|
|
@@ -125,12 +131,109 @@ func (c *GoodsController) PostOrder() {
|
125
|
131
|
c.ResponseJSON("ok")
|
126
|
132
|
}
|
127
|
133
|
|
128
|
|
-// GetOrdersByRecord 根据月记录获取订单信息
|
|
134
|
+// GetOrdersByRecord 根据月记录导出订单信息
|
129
|
135
|
func (c *GoodsController) GetOrdersByRecord() {
|
130
|
136
|
recordid := c.GetString(":recordid")
|
|
137
|
+
|
|
138
|
+ record, err := c.caseserv.GetRecordByID(recordid)
|
|
139
|
+ if err != nil {
|
|
140
|
+ c.ResponseError(err)
|
|
141
|
+ }
|
|
142
|
+ if record == nil {
|
|
143
|
+ c.ResponseError(errors.New("不存在对应的月记录!"))
|
|
144
|
+ }
|
|
145
|
+
|
131
|
146
|
orders, err := c.serv.GetOrdersByRecord(recordid)
|
132
|
147
|
if err != nil {
|
133
|
148
|
c.ResponseError(err)
|
134
|
149
|
}
|
|
150
|
+
|
|
151
|
+ file := xlsx.NewFile()
|
|
152
|
+ sheet, _ := file.AddSheet("Sheet1")
|
|
153
|
+ row := sheet.AddRow()
|
|
154
|
+ row.SetHeightCM(0.8) //设置每行的高度
|
|
155
|
+ cell := row.AddCell()
|
|
156
|
+ cell.Value = "归属案场"
|
|
157
|
+ cell = row.AddCell()
|
|
158
|
+ cell.Value = "商品分类"
|
|
159
|
+ cell = row.AddCell()
|
|
160
|
+ cell.Value = "商品名称"
|
|
161
|
+ cell = row.AddCell()
|
|
162
|
+ cell.Value = "商品规格"
|
|
163
|
+ cell = row.AddCell()
|
|
164
|
+ cell.Value = "下单人"
|
|
165
|
+ cell = row.AddCell()
|
|
166
|
+ cell.Value = "销售数量"
|
|
167
|
+ cell = row.AddCell()
|
|
168
|
+ cell.Value = "商品单价"
|
|
169
|
+ cell = row.AddCell()
|
|
170
|
+ cell.Value = "商品总价"
|
|
171
|
+ cell = row.AddCell()
|
|
172
|
+ cell.Value = "订单状态"
|
|
173
|
+ cell = row.AddCell()
|
|
174
|
+ cell.Value = "下单时间"
|
|
175
|
+ cell = row.AddCell()
|
|
176
|
+ cell.Value = "订单号"
|
|
177
|
+ var amount float64
|
|
178
|
+ amount = 0
|
|
179
|
+ for _, order := range orders {
|
|
180
|
+ for _, good := range order.Goods {
|
|
181
|
+ row := sheet.AddRow()
|
|
182
|
+ row.SetHeightCM(0.8) //设置每行的高度
|
|
183
|
+ cell := row.AddCell()
|
|
184
|
+ cell.Value = order.CaseName
|
|
185
|
+ cell = row.AddCell()
|
|
186
|
+ cell.Value = good.TypeName
|
|
187
|
+ cell = row.AddCell()
|
|
188
|
+ cell.Value = good.GoodsName
|
|
189
|
+ cell = row.AddCell()
|
|
190
|
+ cell.Value = good.SpecName
|
|
191
|
+ cell = row.AddCell()
|
|
192
|
+ cell.Value = order.UserName
|
|
193
|
+ cell = row.AddCell()
|
|
194
|
+ cell.Value = strconv.Itoa(good.Number)
|
|
195
|
+ cell = row.AddCell()
|
|
196
|
+ cell.Value = good.Price
|
|
197
|
+ cell = row.AddCell()
|
|
198
|
+ price, err := strconv.ParseFloat(good.Price, 64)
|
|
199
|
+ if err != nil {
|
|
200
|
+ c.ResponseError(errors.New("金额类型不正确!"))
|
|
201
|
+ }
|
|
202
|
+ num, err := strconv.ParseFloat(strconv.Itoa(good.Number), 64)
|
|
203
|
+ if err != nil {
|
|
204
|
+ c.ResponseError(errors.New("金额类型不正确!"))
|
|
205
|
+ }
|
|
206
|
+ amount = amount + price*num
|
|
207
|
+ cell.Value = strconv.FormatFloat(price*num, 'f', -1, 64)
|
|
208
|
+ cell = row.AddCell()
|
|
209
|
+ var status = "未完成"
|
|
210
|
+ if order.Status == models.STATUS_NOMAL {
|
|
211
|
+ status = "已完成"
|
|
212
|
+ }
|
|
213
|
+ cell.Value = status
|
|
214
|
+ cell = row.AddCell()
|
|
215
|
+ cell.Value = order.CreateDate.Format("2006-01-02 15:04:05")
|
|
216
|
+ cell = row.AddCell()
|
|
217
|
+ cell.Value = order.OrdersNo
|
|
218
|
+ }
|
|
219
|
+ }
|
|
220
|
+ row = sheet.AddRow()
|
|
221
|
+ row.SetHeightCM(0.8)
|
|
222
|
+ cell = row.AddCell()
|
|
223
|
+ cell.Value = "总规定次数"
|
|
224
|
+ cell = row.AddCell()
|
|
225
|
+ cell.Value = strconv.Itoa(record.Num)
|
|
226
|
+ cell = row.AddCell()
|
|
227
|
+ cell.Value = "实际使用总数"
|
|
228
|
+ cell = row.AddCell()
|
|
229
|
+ cell.Value = strconv.Itoa(record.ActrualNum)
|
|
230
|
+ cell = row.AddCell()
|
|
231
|
+ cell.Value = "总价"
|
|
232
|
+ cell = row.AddCell()
|
|
233
|
+ cell.Value = strconv.FormatFloat(amount, 'f', -1, 64)
|
|
234
|
+
|
|
235
|
+ excelpath := beego.AppConfig.String("excelpath") + helper.GetGuid() + ".xlsx"
|
|
236
|
+ err = file.Save(excelpath)
|
|
237
|
+
|
135
|
238
|
c.ResponseJSON(orders)
|
136
|
239
|
}
|