wangfei 6 gadus atpakaļ
vecāks
revīzija
bcdb1cadb2

+ 3
- 1
conf/app.conf Parādīt failu

@@ -1,10 +1,11 @@
1 1
 appname = services
2
-httpport = 8080
2
+httpport = 8085
3 3
 runmode = dev
4 4
 autorender = false
5 5
 copyrequestbody = true
6 6
 EnableDocs = true
7 7
 sessionon = true
8
+excelpath = ./
8 9
 
9 10
 
10 11
 [cros]
@@ -20,3 +21,4 @@ prefix = "/api"
20 21
 guest = "/guest/:org"
21 22
 common = "/common/:org"
22 23
 wechat = "/wechat/:org"
24
+

+ 3
- 0
controllers/goods/goods.go Parādīt failu

@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"spaceofcheng/services/controllers"
7
+	"spaceofcheng/services/models/cases"
7 8
 	goodsModel "spaceofcheng/services/models/goods"
8 9
 	"spaceofcheng/services/models/model"
9 10
 	"spaceofcheng/services/service/goods"
@@ -15,6 +16,7 @@ import (
15 16
 type GoodsController struct {
16 17
 	serv *goods.GoodsServ
17 18
 	controllers.BaseController
19
+	caseserv *cases.CaseDAO
18 20
 }
19 21
 
20 22
 // Constructor 初始化 Controller
@@ -22,6 +24,7 @@ type GoodsController struct {
22 24
 // @Description 初始化 Controller, 系统自动调用
23 25
 func (c *GoodsController) Constructor() {
24 26
 	c.serv = goods.NewGoodsServ(c.Context)
27
+	c.caseserv = cases.NewCaseDAO(c.Context)
25 28
 }
26 29
 
27 30
 // GetListByCase 获取案场商品列表

+ 104
- 1
controllers/goods/order.go Parādīt failu

@@ -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
 }

+ 32
- 0
models/cases/record.go Parādīt failu

@@ -84,3 +84,35 @@ func (m *CaseDAO) GetRecordByMonth(caseid, month string) (*model.SysCaseRecord,
84 84
 	}
85 85
 	return nil, nil
86 86
 }
87
+
88
+// GetRecordByID 根据id获取月记录
89
+func (m *CaseDAO) GetRecordByID(recordid string) (*CaseRecord, error) {
90
+	var records []CaseRecord
91
+	sql := `select * from sys_case_record where record_id='` + recordid + `'`
92
+
93
+	err := m.db.Sql(sql).Find(&records)
94
+	if err != nil {
95
+		return nil, err
96
+	}
97
+	if len(records) > 0 {
98
+		var record = records[0]
99
+		orders := new(model.TaGoodsOrders)
100
+		total, err := m.db.Where("case_id=?", record.CaseId).And("status=?", models.STATUS_NORMAL).And("user_type=?", goods.USERTPE_SALES).And("date_format(create_date,'%Y-%m')=?", record.Month).Sums(orders, "orders_num")
101
+		if err != nil {
102
+			return nil, err
103
+		}
104
+		record.ActrualNum = int(total[0])
105
+		var overnum int
106
+		var leftnum int
107
+		if record.ActrualNum > record.Num {
108
+			overnum = record.ActrualNum - record.Num
109
+		} else {
110
+			leftnum = record.Num - record.ActrualNum
111
+		}
112
+		record.OverNum = overnum
113
+		record.LeftNum = leftnum
114
+		return &record, err
115
+	}
116
+
117
+	return nil, nil
118
+}

+ 3
- 1
models/goods/orders.go Parādīt failu

@@ -185,7 +185,9 @@ func (m *GoodsDAO) GetOrderDetailByOrder(orderid string) ([]DetailWithType, erro
185 185
 // GetOrdersByRecord 根据
186 186
 func (m *GoodsDAO) GetOrdersByRecord(recordid string) ([]OrdersWithGoods, error) {
187 187
 	var orderList []OrdersWithGoods
188
-	sql := `select a.* from ta_goods_orders a inner join sys_case_record b on a.case_id=b.case_id and date_format(a.create_date,'%Y-%m')=b.month where b.record_id='` + recordid +
188
+	sql := `select a.*, c.case_name from ta_goods_orders a inner join sys_case_record b on a.case_id=b.case_id and date_format(a.create_date,'%Y-%m')=b.month
189
+	inner join sys_case c on a.case_id=c.case_id
190
+	where b.record_id='` + recordid +
189 191
 		`' and a.user_type='` + USERTPE_SALES + `' and b.status=` + strconv.Itoa(models.STATUS_NORMAL) + ` and a.status=` + strconv.Itoa(models.STATUS_NORMAL)
190 192
 	err := m.db.Sql(sql).Find(&orderList)
191 193
 	if err != nil {

+ 1
- 0
models/goods/types.go Parādīt failu

@@ -41,5 +41,6 @@ type DetailWithType struct {
41 41
 // OrdersWithGoods 订单列表
42 42
 type OrdersWithGoods struct {
43 43
 	model.TaGoodsOrders `xorm:"extends"`
44
+	CaseName            string
44 45
 	Goods               []DetailWithType
45 46
 }

+ 11
- 0
service/cases/record.go Parādīt failu

@@ -2,6 +2,7 @@ package cases
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"spaceofcheng/services/models/cases"
5 6
 	"spaceofcheng/services/models/model"
6 7
 	"spaceofcheng/services/service"
7 8
 	"spaceofcheng/services/utils"
@@ -51,3 +52,13 @@ func (s *CaseServ) AddRecord(record model.SysCaseRecord) (*model.SysCaseRecord,
51 52
 	}
52 53
 	return newinfo, nil
53 54
 }
55
+
56
+// GetRecordByID 获取月记录信息
57
+func (s *CaseServ) GetRecordByID(recordid string) (*cases.CaseRecord, error) {
58
+	record, err := s.dao.GetRecordByID(recordid)
59
+	if err != nil {
60
+		utils.LogError("获取月记录失败: " + err.Error())
61
+		return nil, errors.New("获取月记录失败")
62
+	}
63
+	return record, nil
64
+}