diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 696dbc0e2..1ca9f8344 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -752,7 +752,7 @@ func RefreshOrdersWithoutJxStoreID(ctx *jxcontext.Context, fromDate, toDate stri return hint, err } -func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs []int, vendorOrderID, fromTime, toTime string, status, stype, IsReverse, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { +func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs, statuss []int, vendorOrderID, fromTime, toTime string, stype, IsReverse, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { var ( db = dao.GetDB() fromTimeP time.Time @@ -767,7 +767,7 @@ func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs []int, vendo if fromTimeP.After(toTimeP) { return nil, fmt.Errorf("时间范围不合法!开始时间:[%v],结束时间:[%v]", fromTimeP, toTimeP) } - result, totalCount, err := dao.GetOrdersSupplement(db, storIDs, vendorIDs, vendorOrderID, fromTimeP, toTimeP, status, stype, IsReverse, offset, pageSize) + result, totalCount, err := dao.GetOrdersSupplement(db, storIDs, vendorIDs, statuss, vendorOrderID, fromTimeP, toTimeP, stype, IsReverse, offset, pageSize) pageInfo = &model.PagedInfo{ Data: result, TotalCount: totalCount, @@ -781,6 +781,9 @@ func AddUpdateOrdersSupplement(ctx *jxcontext.Context, ordersSupplement *model.O id = ordersSupplement.ID ) now := time.Now() + if *ordersSupplement.VendorID == -1 { + ordersSupplement.VendorID = nil + } ordersSupplement.SupplementTime = &now defer func() { if r := recover(); r != nil || err != nil { @@ -791,11 +794,16 @@ func AddUpdateOrdersSupplement(ctx *jxcontext.Context, ordersSupplement *model.O } }() if id > 0 { - if ordersSupplement.Status == 1 { - return 0, fmt.Errorf("已结账的扣款信息不允许修改!门店ID:[%v],订单号:[%v]", ordersSupplement.StoreID, ordersSupplement.VendorOrderID) + orderSupplementFee, _ := dao.GetOrdersSupplementNoPage(db, id, nil, nil, nil, "", utils.ZeroTimeValue, utils.ZeroTimeValue, 0, 0) + if len(orderSupplementFee) > 2 || len(orderSupplementFee) == 0 { + return 0, fmt.Errorf("查询扣款记录有误,请联系技术部!") + } + if orderSupplementFee[0].Status == 1 { + return 0, fmt.Errorf("已结账的扣款信息不允许修改!门店ID:[%v],订单号:[%v]", ordersSupplement.StoreID, *ordersSupplement.VendorOrderID) } ordersSupplement.UpdatedAt = time.Now() ordersSupplement.LastOperator = ctx.GetUserName() + ordersSupplement.CreatedAt = orderSupplementFee[0].CreatedAt if ordersSupplement.Status == -1 { ordersSupplement.DeletedAt = time.Now() } else { diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 321ca7d9a..6a6b0e0e9 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1053,7 +1053,7 @@ func GetWayBillByOrderID(db *DaoDB, orderStatus, vendorID, waybillVendorID int, return wayBillList, err } -func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID string, fromTime, toTime time.Time, status, stype, IsReverse, offset, pageSize int) (orderSupplementFee []*model.OrderSupplementFee, totalCount int, err error) { +func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs, statuss []int, vendorOrderID string, fromTime, toTime time.Time, stype, IsReverse, offset, pageSize int) (orderSupplementFee []*model.OrderSupplementFee, totalCount int, err error) { sql := ` SELECT SQL_CALC_FOUND_ROWS * FROM order_supplement_fee @@ -1083,9 +1083,9 @@ func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID stri sql += " AND vendor_order_id = ?" sqlParams = append(sqlParams, vendorOrderID) } - if status >= 0 { - sql += " AND status = ?" - sqlParams = append(sqlParams, status) + if len(statuss) > 0 { + sql += " AND status IN (" + GenQuestionMarks(len(vendorIDs)) + ")" + sqlParams = append(sqlParams, statuss) } if stype > 0 { sql += " AND type = ?" @@ -1106,3 +1106,54 @@ func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID stri } return orderSupplementFee, totalCount, err } + +func GetOrdersSupplementNoPage(db *DaoDB, ID int, storIDs, vendorIDs, statuss []int, vendorOrderID string, fromTime, toTime time.Time, stype, IsReverse int) (orderSupplementFee []*model.OrderSupplementFee, err error) { + sql := ` + SELECT * + FROM order_supplement_fee + WHERE 1=1 + AND deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if !utils.IsTimeZero(fromTime) { + sql += " AND supplement_time >= ?" + sqlParams = append(sqlParams, fromTime) + } + if !utils.IsTimeZero(toTime) { + sql += " AND supplement_time <= ?" + sqlParams = append(sqlParams, toTime) + } + if len(storIDs) > 0 { + sql += " AND store_id IN (" + GenQuestionMarks(len(storIDs)) + ")" + sqlParams = append(sqlParams, storIDs) + } + if len(vendorIDs) > 0 { + sql += " AND vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")" + sqlParams = append(sqlParams, vendorIDs) + } + if vendorOrderID != "" { + sql += " AND vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) + } + if len(statuss) > 0 { + sql += " AND status IN (" + GenQuestionMarks(len(vendorIDs)) + ")" + sqlParams = append(sqlParams, statuss) + } + if stype > 0 { + sql += " AND type = ?" + sqlParams = append(sqlParams, stype) + } + if ID > 0 { + sql += " AND id = ?" + sqlParams = append(sqlParams, ID) + } + if IsReverse == -1 { + sql += " AND link_id = 0" + } else if IsReverse == 1 { + sql += " AND link_id <> 0" + } + err = GetRows(db, &orderSupplementFee, sql, sqlParams...) + return orderSupplementFee, err +} diff --git a/business/model/order.go b/business/model/order.go index 0b1428818..c4a7fd214 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -348,7 +348,7 @@ type OrderSupplementFee struct { ModelIDCULD StoreID int `orm:"column(store_id)" json:"storeID"` VendorOrderID *string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` - VendorID *string `orm:"column(vendor_id)" json:"vendorID"` + VendorID *int `orm:"column(vendor_id);null" json:"vendorID"` Status int `json:"status"` //账单状态,若已结账则不允许再修改 ,暂时 0为未结账,1为已结账,-1为作废 LinkID int `orm:"column(link_id)" json:"linkID"` //作为冲账标志关联某条扣款记录 SupplementTime *time.Time `orm:"type(datetime);null" json:"supplementTime"` diff --git a/controllers/jx_order.go b/controllers/jx_order.go index e9372bfab..c0f3a7bb6 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -934,7 +934,7 @@ func (c *OrderController) ComplaintRider() { // @Param vendorIDs query string false "订单所属厂商ID列表" // @Param fromTime query string false "开始日期(包含),格式(2006-01-02),如果订单号为空此项必须要求" // @Param toTime query string false "结束日期(包含),格式(2006-01-02),如果订单号为空此项必须要求" -// @Param status query int false "账单状态,0是未结账,1是已结账" +// @Param statuss query string false "账单状态列表,0是未结账,1是已结账,-1为作废" // @Param type query int false "扣款类型,1为差评补贴,2为优惠券" // @Param isReverse query int false "只查冲账记录,0为默认都查,1为只查冲账,-1为不查冲账" // @Param offset query int false "结果起始序号(以0开始,缺省为0)" @@ -943,10 +943,10 @@ func (c *OrderController) ComplaintRider() { // @Failure 200 {object} controllers.CallResult // @router /GetOrdersSupplement [get] func (c *OrderController) GetOrdersSupplement() { - var vendorIDList, storeIDList []int + var vendorIDList, storeIDList, statusList []int c.callGetOrdersSupplement(func(params *tOrderGetOrdersSupplementParams) (retVal interface{}, errCode string, err error) { - if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil { - retVal, err = orderman.GetOrdersSupplement(params.Ctx, storeIDList, vendorIDList, params.VendorOrderID, params.FromTime, params.ToTime, params.Status, params.Type, params.IsReverse, params.Offset, params.PageSize) + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList, params.Statuss, statusList); err == nil { + retVal, err = orderman.GetOrdersSupplement(params.Ctx, storeIDList, vendorIDList, statusList, params.VendorOrderID, params.FromTime, params.ToTime, params.Type, params.IsReverse, params.Offset, params.PageSize) } return retVal, "", err })