正在显示
4 个修改的文件
包含
262 行增加
和
5 行删除
@@ -871,6 +871,7 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde | @@ -871,6 +871,7 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde | ||
871 | listIndex := listOrderQuery.Offset + (1 + i) | 871 | listIndex := listOrderQuery.Offset + (1 + i) |
872 | listItem := map[string]interface{}{ | 872 | listItem := map[string]interface{}{ |
873 | "index": listIndex, | 873 | "index": listIndex, |
874 | + "createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"), | ||
874 | "updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"), | 875 | "updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"), |
875 | "id": orders[i].Id, | 876 | "id": orders[i].Id, |
876 | "shipmentsId": orders[i].DeliveryCode, | 877 | "shipmentsId": orders[i].DeliveryCode, |
@@ -1315,7 +1316,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List | @@ -1315,7 +1316,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List | ||
1315 | [2]string{"delivery_code", "发货单号"}, | 1316 | [2]string{"delivery_code", "发货单号"}, |
1316 | [2]string{"partner_name", "合伙人"}, | 1317 | [2]string{"partner_name", "合伙人"}, |
1317 | [2]string{"bonus_status", "支付状态"}, | 1318 | [2]string{"bonus_status", "支付状态"}, |
1318 | - [2]string{"update_time", "最后操作时间"}, | 1319 | + [2]string{"create_time", "创建时间"}, |
1319 | [2]string{"partner_bonus", "应收分红"}, | 1320 | [2]string{"partner_bonus", "应收分红"}, |
1320 | [2]string{"partner_bonus_has", "已收分红"}, | 1321 | [2]string{"partner_bonus_has", "已收分红"}, |
1321 | [2]string{"partner_bonus_not", "未收分红"}, | 1322 | [2]string{"partner_bonus_not", "未收分红"}, |
@@ -1323,3 +1324,74 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List | @@ -1323,3 +1324,74 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List | ||
1323 | } | 1324 | } |
1324 | return resultMaps, column, nil | 1325 | return resultMaps, column, nil |
1325 | } | 1326 | } |
1327 | + | ||
1328 | +func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrderBaseQuery) ([]map[string]string, [][2]string, error) { | ||
1329 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
1330 | + if err != nil { | ||
1331 | + return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
1332 | + } | ||
1333 | + if err = transactionContext.StartTransaction(); err != nil { | ||
1334 | + return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
1335 | + } | ||
1336 | + defer func() { | ||
1337 | + transactionContext.RollbackTransaction() | ||
1338 | + }() | ||
1339 | + var ( | ||
1340 | + orderBaseDao *dao.OrderBaseDao | ||
1341 | + ) | ||
1342 | + | ||
1343 | + if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{ | ||
1344 | + "transactionContext": transactionContext, | ||
1345 | + }); err != nil { | ||
1346 | + return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
1347 | + } | ||
1348 | + ordersData, err := orderBaseDao.OrderListForExcel( | ||
1349 | + listOrderQuery.CompanyId, | ||
1350 | + listOrderQuery.PartnerOrCode, | ||
1351 | + [2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd}, | ||
1352 | + [2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.UpdateTimeEnd}, | ||
1353 | + listOrderQuery.PartnerCategory, | ||
1354 | + ) | ||
1355 | + if err != nil { | ||
1356 | + return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
1357 | + } | ||
1358 | + err = transactionContext.CommitTransaction() | ||
1359 | + if err != nil { | ||
1360 | + return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
1361 | + } | ||
1362 | + var resultMaps []map[string]string | ||
1363 | + for i := range ordersData { | ||
1364 | + m := map[string]string{ | ||
1365 | + "num": fmt.Sprint(i + 1), | ||
1366 | + "order_code": ordersData[i].OrderCode, | ||
1367 | + "delivery_code": ordersData[i].DeliveryCode, | ||
1368 | + "partner_name": ordersData[i].PartnerName, | ||
1369 | + "update_time": ordersData[i].UpdateTime, | ||
1370 | + "create_time": ordersData[i].CreateTime, | ||
1371 | + "plan_order_count": fmt.Sprint(ordersData[i].PlanOrderCount), | ||
1372 | + "use_order_count": fmt.Sprint(ordersData[i].UseOrderCount), | ||
1373 | + "region_name": fmt.Sprint(ordersData[i].RegionName), | ||
1374 | + "plan_order_amount": fmt.Sprint(ordersData[i].PlanOrderAmount), | ||
1375 | + "user_order_amount": fmt.Sprint(ordersData[i].UseOrderAmount), | ||
1376 | + "partner_category": ordersData[i].PartnerCategory, | ||
1377 | + "buyer_name": ordersData[i].BuyerName, | ||
1378 | + } | ||
1379 | + resultMaps = append(resultMaps, m) | ||
1380 | + } | ||
1381 | + column := [][2]string{ | ||
1382 | + [2]string{"num", "序号"}, | ||
1383 | + [2]string{"order_code", "订单号"}, | ||
1384 | + [2]string{"delivery_code", "发货单号"}, | ||
1385 | + [2]string{"create_time", "创建时间"}, | ||
1386 | + [2]string{"update_time", "更新时间"}, | ||
1387 | + [2]string{"plan_order_count", "订单数量"}, | ||
1388 | + [2]string{"use_order_count", "数量调整"}, | ||
1389 | + [2]string{"plan_order_amount", "订单金额"}, | ||
1390 | + [2]string{"use_order_amount", "金额调整"}, | ||
1391 | + [2]string{"region_name", "订单区域"}, | ||
1392 | + [2]string{"partner_category", "合伙人类型"}, | ||
1393 | + [2]string{"buyer_name", "客户"}, | ||
1394 | + [2]string{"partner_name", "合伙人"}, | ||
1395 | + } | ||
1396 | + return resultMaps, column, nil | ||
1397 | +} |
@@ -47,9 +47,12 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId .. | @@ -47,9 +47,12 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId .. | ||
47 | return ok, err | 47 | return ok, err |
48 | } | 48 | } |
49 | 49 | ||
50 | -//OrderListByCondition 根据条件获取订单分红列表 | ||
51 | -//orderType 订单类型 | ||
52 | -//partnerOrCode 合伙人姓名或订单号或发货单号 | 50 | +//OrderBonusListByCondition 根据条件获取订单分红列表 |
51 | +//@param orderType 订单类型 | ||
52 | +//@param partnerOrCode 合伙人姓名或订单号或发货单号 | ||
53 | +//@param companyId 公司id | ||
54 | +//@param partnerCategory 合伙人类型 | ||
55 | +//@param createTime 创建时间 | ||
53 | func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string, | 56 | func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string, |
54 | partnerCategory int, createTime [2]string, limit, offset int) ([]models.OrderBase, int, error) { | 57 | partnerCategory int, createTime [2]string, limit, offset int) ([]models.OrderBase, int, error) { |
55 | tx := dao.transactionContext.GetDB() | 58 | tx := dao.transactionContext.GetDB() |
@@ -97,6 +100,7 @@ type CustomOrderBonusForExcel struct { | @@ -97,6 +100,7 @@ type CustomOrderBonusForExcel struct { | ||
97 | BonusStatus int | 100 | BonusStatus int |
98 | DeliveryCode string | 101 | DeliveryCode string |
99 | UpdateTime string | 102 | UpdateTime string |
103 | + CreateTime string | ||
100 | PartnerBonus float64 | 104 | PartnerBonus float64 |
101 | PartnerBonusHas float64 | 105 | PartnerBonusHas float64 |
102 | PartnerBonusNot float64 | 106 | PartnerBonusNot float64 |
@@ -122,6 +126,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p | @@ -122,6 +126,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p | ||
122 | t1.delivery_code, | 126 | t1.delivery_code, |
123 | t1.bonus_status, | 127 | t1.bonus_status, |
124 | to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time, | 128 | to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time, |
129 | + to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time, | ||
125 | (CASE | 130 | (CASE |
126 | WHEN t1.use_partner_bonus>0 | 131 | WHEN t1.use_partner_bonus>0 |
127 | THEN | 132 | THEN |
@@ -214,7 +219,7 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par | @@ -214,7 +219,7 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par | ||
214 | return q, nil | 219 | return q, nil |
215 | }) | 220 | }) |
216 | } | 221 | } |
217 | - query = query.Order("order_base.update_time DESC"). | 222 | + query = query.Order("order_base.create_time DESC"). |
218 | Offset(offset). | 223 | Offset(offset). |
219 | Limit(limit) | 224 | Limit(limit) |
220 | 225 | ||
@@ -222,3 +227,80 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par | @@ -222,3 +227,80 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par | ||
222 | return orders, cnt, err | 227 | return orders, cnt, err |
223 | 228 | ||
224 | } | 229 | } |
230 | + | ||
231 | +//CustomOrderListForExcel 导出实际订单列表所用的结构 | ||
232 | +type CustomOrderListForExcel struct { | ||
233 | + OrderCode string //订单编号 | ||
234 | + DeliveryCode string //发货编号 | ||
235 | + UpdateTime string //更新时间 | ||
236 | + CreateTime string //创建时间 | ||
237 | + PlanOrderCount int64 //货品总数 | ||
238 | + UseOrderCount int64 //货品总数调整 | ||
239 | + RegionName string //订单区域 | ||
240 | + PlanOrderAmount int64 //订单金额 | ||
241 | + UseOrderAmount int64 //订单金额调整 | ||
242 | + PartnerCategory string //合伙人类型 | ||
243 | + BuyerName string //买家 | ||
244 | + PartnerName string //合伙人 | ||
245 | +} | ||
246 | + | ||
247 | +//OrderListForExcel 获取实际订单列表用于excel导出 | ||
248 | +//@param companyId 公司id | ||
249 | +//@param orderType 订单类型 | ||
250 | +//@param partnerOrCode 合伙人姓名或订单号或发货单号 | ||
251 | +//@param partnerCategory 合伙人类型id | ||
252 | +//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07" | ||
253 | +//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07" | ||
254 | +func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerOrCode string, | ||
255 | + updateTime [2]string, createTime [2]string, partnerCategory int) ( | ||
256 | + result []CustomOrderListForExcel, err error) { | ||
257 | + sqlstr := ` | ||
258 | + SELECT t1.order_code,t1.delivery_code | ||
259 | + ,to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time | ||
260 | + ,to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time | ||
261 | + ,t1.plan_order_count,t1.use_order_count,t1.plan_order_amount,t1.use_order_amount | ||
262 | + ,t1.region_info->'regionName' AS region_name,t1.buyer->'buyerName' AS buyer_name | ||
263 | + ,t1.partner_category->'name' AS partner_category | ||
264 | + ,t2.partner_name | ||
265 | + FROM "order_base" AS t1 | ||
266 | + LEFT JOIN partner_info as t2 ON t1.partner_id=t2.id | ||
267 | + WHERE 1=1 AND t1.order_type = 1 | ||
268 | + ` | ||
269 | + params := []interface{}{companyId} | ||
270 | + if len(partnerOrCode) > 0 { | ||
271 | + like := "%" + partnerOrCode + "%" | ||
272 | + params = append(params, like, like, like) | ||
273 | + sqlstr += " AND (t1.order_code like ? OR t1.delivery_code like ? OR t2.partner_name like ? )" | ||
274 | + } | ||
275 | + | ||
276 | + if partnerCategory > 0 { | ||
277 | + params = append(params, partnerCategory) | ||
278 | + sqlstr += ` AND t1.partner_category@>'{"id":?}'` | ||
279 | + } | ||
280 | + | ||
281 | + if len(updateTime[0]) > 0 { | ||
282 | + params = append(params, updateTime[0]) | ||
283 | + sqlstr += ` AND t1.update_time>=?` | ||
284 | + } | ||
285 | + | ||
286 | + if len(updateTime[1]) > 0 { | ||
287 | + params = append(params, updateTime[1]) | ||
288 | + sqlstr += ` AND t1.update_time<=?` | ||
289 | + } | ||
290 | + | ||
291 | + if len(createTime[0]) > 0 { | ||
292 | + params = append(params, createTime[0]) | ||
293 | + sqlstr += `AND t1.create_time>=?` | ||
294 | + } | ||
295 | + if len(createTime[1]) > 0 { | ||
296 | + params = append(params, createTime[1]) | ||
297 | + sqlstr += ` AND t1.create_time<=?` | ||
298 | + } | ||
299 | + sqlstr += ` t1.create_time DESC limit 10000` | ||
300 | + tx := dao.transactionContext.GetDB() | ||
301 | + _, err = tx.Query(&result, sqlstr, params...) | ||
302 | + if err != nil { | ||
303 | + return result, err | ||
304 | + } | ||
305 | + return result, nil | ||
306 | +} |
@@ -15,6 +15,7 @@ import ( | @@ -15,6 +15,7 @@ import ( | ||
15 | orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service" | 15 | orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service" |
16 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 16 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
17 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | 17 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" |
18 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib/exceltool" | ||
18 | ) | 19 | ) |
19 | 20 | ||
20 | type OrderInfoController struct { | 21 | type OrderInfoController struct { |
@@ -768,3 +769,104 @@ func (c *OrderInfoController) RemoveOrderReal() { | @@ -768,3 +769,104 @@ func (c *OrderInfoController) RemoveOrderReal() { | ||
768 | } | 769 | } |
769 | c.ResponseData(nil) | 770 | c.ResponseData(nil) |
770 | } | 771 | } |
772 | + | ||
773 | +//ListOrderForExcel excel 导出实际订单的列表 | ||
774 | +func (c *OrderInfoController) ListOrderForExcel() { | ||
775 | + type Parameter struct { | ||
776 | + SearchText string `json:"searchText"` | ||
777 | + PartnerCategory int `json:"PartnerCategory"` | ||
778 | + UpdateTime []string `json:"updateTime"` | ||
779 | + CreateTime []string `json:"createTime"` | ||
780 | + } | ||
781 | + var ( | ||
782 | + param Parameter | ||
783 | + err error | ||
784 | + ) | ||
785 | + if err = c.BindJsonData(¶m); err != nil { | ||
786 | + logs.Error(err) | ||
787 | + c.ResponseError(errors.New("json数据解析失败")) | ||
788 | + return | ||
789 | + } | ||
790 | + var ( | ||
791 | + updateTimeBegin string | ||
792 | + updateTimeEnd string | ||
793 | + ) | ||
794 | + if len(param.UpdateTime) > 0 { | ||
795 | + if len(param.UpdateTime[0]) > 0 { | ||
796 | + t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[0], time.Local) | ||
797 | + if err != nil { | ||
798 | + c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误")) | ||
799 | + return | ||
800 | + } | ||
801 | + updateTimeBegin = t.Format("2006-01-02 15:04:05-07") | ||
802 | + } | ||
803 | + } | ||
804 | + if len(param.UpdateTime) > 1 { | ||
805 | + if len(param.UpdateTime[1]) > 0 { | ||
806 | + t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[1], time.Local) | ||
807 | + if err != nil { | ||
808 | + c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误")) | ||
809 | + return | ||
810 | + } | ||
811 | + //设定时间边界 | ||
812 | + t = t.Add(86399 * time.Second) | ||
813 | + updateTimeEnd = t.Format("2006-01-02 15:04:05-07") | ||
814 | + } | ||
815 | + } | ||
816 | + var ( | ||
817 | + createTimeBegin string | ||
818 | + createTimeEnd string | ||
819 | + ) | ||
820 | + if len(param.CreateTime) > 0 { | ||
821 | + if len(param.CreateTime[0]) > 0 { | ||
822 | + t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local) | ||
823 | + if err != nil { | ||
824 | + c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误")) | ||
825 | + return | ||
826 | + } | ||
827 | + createTimeBegin = t.Format("2006-01-02 15:04:05-07") | ||
828 | + } | ||
829 | + } | ||
830 | + if len(param.CreateTime) > 1 { | ||
831 | + if len(param.CreateTime[1]) > 0 { | ||
832 | + t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local) | ||
833 | + if err != nil { | ||
834 | + c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误")) | ||
835 | + return | ||
836 | + } | ||
837 | + //设定时间边界 | ||
838 | + t = t.Add(86399 * time.Second) | ||
839 | + createTimeEnd = t.Format("2006-01-02 15:04:05-07") | ||
840 | + } | ||
841 | + } | ||
842 | + | ||
843 | + companyId := c.GetUserCompany() | ||
844 | + orderSrv := orderService.NewOrderInfoService(nil) | ||
845 | + orderinfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{ | ||
846 | + PartnerOrCode: param.SearchText, | ||
847 | + OrderType: domain.OrderReal, | ||
848 | + CompanyId: companyId, | ||
849 | + PartnerCategory: param.PartnerCategory, | ||
850 | + UpdateTimeBegin: updateTimeBegin, | ||
851 | + UpdateTimeEnd: updateTimeEnd, | ||
852 | + CreateTimeBegin: createTimeBegin, | ||
853 | + CreateTimeEnd: createTimeEnd, | ||
854 | + }) | ||
855 | + if err != nil { | ||
856 | + c.ResponseError(err) | ||
857 | + return | ||
858 | + } | ||
859 | + var excelHeaders []exceltool.ExcelHead | ||
860 | + for i := range columns { | ||
861 | + h := exceltool.ExcelHead{ | ||
862 | + Key: columns[i][0], | ||
863 | + Name: columns[i][1], | ||
864 | + } | ||
865 | + excelHeaders = append(excelHeaders, h) | ||
866 | + } | ||
867 | + excelMaker := exceltool.NewExcelMaker() | ||
868 | + excelMaker.SetListHead(excelHeaders) | ||
869 | + excelMaker.MakeListExcel(orderinfos) | ||
870 | + c.ResponseExcelByFile(c.Ctx, excelMaker) | ||
871 | + return | ||
872 | +} |
@@ -45,6 +45,7 @@ func init() { | @@ -45,6 +45,7 @@ func init() { | ||
45 | // beego.NSRouter("/purpose/del", &controllers.OrderInfoController{}, "POST:RemoveOrderPurpose"), | 45 | // beego.NSRouter("/purpose/del", &controllers.OrderInfoController{}, "POST:RemoveOrderPurpose"), |
46 | // beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"), | 46 | // beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"), |
47 | beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"), | 47 | beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"), |
48 | + beego.NSRouter("/actual/list/excel", &controllers.OrderInfoController{}, "POST:ListOrderForExcel"), | ||
48 | beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"), | 49 | beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"), |
49 | beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"), | 50 | beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"), |
50 | beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"), | 51 | beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"), |
-
请 注册 或 登录 后发表评论