作者 唐旭辉

更新 实际列表导出

... ... @@ -871,6 +871,7 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde
listIndex := listOrderQuery.Offset + (1 + i)
listItem := map[string]interface{}{
"index": listIndex,
"createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"),
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
"id": orders[i].Id,
"shipmentsId": orders[i].DeliveryCode,
... ... @@ -1315,7 +1316,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List
[2]string{"delivery_code", "发货单号"},
[2]string{"partner_name", "合伙人"},
[2]string{"bonus_status", "支付状态"},
[2]string{"update_time", "最后操作时间"},
[2]string{"create_time", "创建时间"},
[2]string{"partner_bonus", "应收分红"},
[2]string{"partner_bonus_has", "已收分红"},
[2]string{"partner_bonus_not", "未收分红"},
... ... @@ -1323,3 +1324,74 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List
}
return resultMaps, column, nil
}
func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrderBaseQuery) ([]map[string]string, [][2]string, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBaseDao *dao.OrderBaseDao
)
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
ordersData, err := orderBaseDao.OrderListForExcel(
listOrderQuery.CompanyId,
listOrderQuery.PartnerOrCode,
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.UpdateTimeEnd},
listOrderQuery.PartnerCategory,
)
if err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var resultMaps []map[string]string
for i := range ordersData {
m := map[string]string{
"num": fmt.Sprint(i + 1),
"order_code": ordersData[i].OrderCode,
"delivery_code": ordersData[i].DeliveryCode,
"partner_name": ordersData[i].PartnerName,
"update_time": ordersData[i].UpdateTime,
"create_time": ordersData[i].CreateTime,
"plan_order_count": fmt.Sprint(ordersData[i].PlanOrderCount),
"use_order_count": fmt.Sprint(ordersData[i].UseOrderCount),
"region_name": fmt.Sprint(ordersData[i].RegionName),
"plan_order_amount": fmt.Sprint(ordersData[i].PlanOrderAmount),
"user_order_amount": fmt.Sprint(ordersData[i].UseOrderAmount),
"partner_category": ordersData[i].PartnerCategory,
"buyer_name": ordersData[i].BuyerName,
}
resultMaps = append(resultMaps, m)
}
column := [][2]string{
[2]string{"num", "序号"},
[2]string{"order_code", "订单号"},
[2]string{"delivery_code", "发货单号"},
[2]string{"create_time", "创建时间"},
[2]string{"update_time", "更新时间"},
[2]string{"plan_order_count", "订单数量"},
[2]string{"use_order_count", "数量调整"},
[2]string{"plan_order_amount", "订单金额"},
[2]string{"use_order_amount", "金额调整"},
[2]string{"region_name", "订单区域"},
[2]string{"partner_category", "合伙人类型"},
[2]string{"buyer_name", "客户"},
[2]string{"partner_name", "合伙人"},
}
return resultMaps, column, nil
}
... ...
... ... @@ -47,9 +47,12 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ..
return ok, err
}
//OrderListByCondition 根据条件获取订单分红列表
//orderType 订单类型
//partnerOrCode 合伙人姓名或订单号或发货单号
//OrderBonusListByCondition 根据条件获取订单分红列表
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param companyId 公司id
//@param partnerCategory 合伙人类型
//@param createTime 创建时间
func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string,
partnerCategory int, createTime [2]string, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
... ... @@ -97,6 +100,7 @@ type CustomOrderBonusForExcel struct {
BonusStatus int
DeliveryCode string
UpdateTime string
CreateTime string
PartnerBonus float64
PartnerBonusHas float64
PartnerBonusNot float64
... ... @@ -122,6 +126,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
t1.delivery_code,
t1.bonus_status,
to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time,
to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time,
(CASE
WHEN t1.use_partner_bonus>0
THEN
... ... @@ -214,7 +219,7 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
return q, nil
})
}
query = query.Order("order_base.update_time DESC").
query = query.Order("order_base.create_time DESC").
Offset(offset).
Limit(limit)
... ... @@ -222,3 +227,80 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
return orders, cnt, err
}
//CustomOrderListForExcel 导出实际订单列表所用的结构
type CustomOrderListForExcel struct {
OrderCode string //订单编号
DeliveryCode string //发货编号
UpdateTime string //更新时间
CreateTime string //创建时间
PlanOrderCount int64 //货品总数
UseOrderCount int64 //货品总数调整
RegionName string //订单区域
PlanOrderAmount int64 //订单金额
UseOrderAmount int64 //订单金额调整
PartnerCategory string //合伙人类型
BuyerName string //买家
PartnerName string //合伙人
}
//OrderListForExcel 获取实际订单列表用于excel导出
//@param companyId 公司id
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerOrCode string,
updateTime [2]string, createTime [2]string, partnerCategory int) (
result []CustomOrderListForExcel, err error) {
sqlstr := `
SELECT t1.order_code,t1.delivery_code
,to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time
,to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time
,t1.plan_order_count,t1.use_order_count,t1.plan_order_amount,t1.use_order_amount
,t1.region_info->'regionName' AS region_name,t1.buyer->'buyerName' AS buyer_name
,t1.partner_category->'name' AS partner_category
,t2.partner_name
FROM "order_base" AS t1
LEFT JOIN partner_info as t2 ON t1.partner_id=t2.id
WHERE 1=1 AND t1.order_type = 1
`
params := []interface{}{companyId}
if len(partnerOrCode) > 0 {
like := "%" + partnerOrCode + "%"
params = append(params, like, like, like)
sqlstr += " AND (t1.order_code like ? OR t1.delivery_code like ? OR t2.partner_name like ? )"
}
if partnerCategory > 0 {
params = append(params, partnerCategory)
sqlstr += ` AND t1.partner_category@>'{"id":?}'`
}
if len(updateTime[0]) > 0 {
params = append(params, updateTime[0])
sqlstr += ` AND t1.update_time>=?`
}
if len(updateTime[1]) > 0 {
params = append(params, updateTime[1])
sqlstr += ` AND t1.update_time<=?`
}
if len(createTime[0]) > 0 {
params = append(params, createTime[0])
sqlstr += `AND t1.create_time>=?`
}
if len(createTime[1]) > 0 {
params = append(params, createTime[1])
sqlstr += ` AND t1.create_time<=?`
}
sqlstr += ` t1.create_time DESC limit 10000`
tx := dao.transactionContext.GetDB()
_, err = tx.Query(&result, sqlstr, params...)
if err != nil {
return result, err
}
return result, nil
}
... ...
... ... @@ -15,6 +15,7 @@ import (
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib/exceltool"
)
type OrderInfoController struct {
... ... @@ -768,3 +769,104 @@ func (c *OrderInfoController) RemoveOrderReal() {
}
c.ResponseData(nil)
}
//ListOrderForExcel excel 导出实际订单的列表
func (c *OrderInfoController) ListOrderForExcel() {
type Parameter struct {
SearchText string `json:"searchText"`
PartnerCategory int `json:"PartnerCategory"`
UpdateTime []string `json:"updateTime"`
CreateTime []string `json:"createTime"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
var (
updateTimeBegin string
updateTimeEnd string
)
if len(param.UpdateTime) > 0 {
if len(param.UpdateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
updateTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.UpdateTime) > 1 {
if len(param.UpdateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
updateTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{
PartnerOrCode: param.SearchText,
OrderType: domain.OrderReal,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
if err != nil {
c.ResponseError(err)
return
}
var excelHeaders []exceltool.ExcelHead
for i := range columns {
h := exceltool.ExcelHead{
Key: columns[i][0],
Name: columns[i][1],
}
excelHeaders = append(excelHeaders, h)
}
excelMaker := exceltool.NewExcelMaker()
excelMaker.SetListHead(excelHeaders)
excelMaker.MakeListExcel(orderinfos)
c.ResponseExcelByFile(c.Ctx, excelMaker)
return
}
... ...
... ... @@ -45,6 +45,7 @@ func init() {
// beego.NSRouter("/purpose/del", &controllers.OrderInfoController{}, "POST:RemoveOrderPurpose"),
// beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"),
beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"),
beego.NSRouter("/actual/list/excel", &controllers.OrderInfoController{}, "POST:ListOrderForExcel"),
beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"),
beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"),
beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"),
... ...