func AppOperateOrderList(a *decorator.ApiBase, data *appStruct.AppOperateOrdersListRequest) error { logger.AccessLogger.Info("AppOperateOrderList...") var err error var boids []int64 //where := map[string]interface{}{} resp := appStruct.OperateOrderListResponse{} //orderMains := []appStruct.OperateOrderList{} resp.ResponseCommon = a.NewSuccessResponseCommon() query := rds.DB.Table("business_order_info as a"). Select(`a.boid, a.contract_no, a.bid, b.bname, s.sid, s.sname, w.wid, w.wname, a.order_no, a.ctime, a.sum_num, a.sum_amt, a.pay_amt, a.proc_status, a.status, a.remark`). Joins("left join supplier_base as s on s.sid=a.sid"). Joins("left join business_base as b on b.bid=a.bid"). Joins("left join warehouse_info as w on w.wid=a.wid"). Not("a.status=?", model.Delete) // 订单状态 1待采购2已取消3已下单未付款4已付款未发货5已发货6已到中转仓7中转仓转发中8已到官仓9删除 // 10申请退货11退货中12退货成功退款中13退货成功退款成功 if len(data.Status) > 0 { query = query.Where("a.status in ?", data.Status) //where["a.status"] = data.Status } if len(data.Search) > 0 { query = query. Or("b.bname like ?", fmt.Sprintf("%%%s%%", data.Search)). Or("s.sname like ?", fmt.Sprintf("%%%s%%", data.Search)) } if len(data.OrderNo) > 0 { query = query.Where("a.order_no like ?", fmt.Sprintf("%%%s%%", data.OrderNo)) } if len(data.Keyword) > 0 { kw := fmt.Sprintf("%%%s%%", data.Keyword) query = query.Where("a.order_no like ? or b.bname like ? or s.sname like ?", kw, kw, kw) } logger.AccessLogger.Info("size:", a.Size, "offset:", a.Offset) res := query.Count(&resp.Count) if res.Error != nil { logger.AccessLogger.Error("ERROR:", res.Error.Error()) return a.ReturnPublicErrorResponse("") } res = query.Order("a.boid desc"). Offset(a.Offset). Limit(a.Size). Find(&resp.Data) // 明细数据未处理 for _, v := range resp.Data { boids = append(boids, v.Boid) } // 查询明细SKU信息 tmpRows := []appStruct.OperateOrderDetail{} tmpDetail := []adminStruct.BusinessOrderDetail{} tmpDetail, err = admin_lib.QueryBusinessOrderSku(boids) if err != nil { logger.AccessLogger.Error("ERROR:", err.Error()) return a.ReturnPublicErrorResponse(err.Error()) } copier.Copy(&tmpRows, &tmpDetail) logger.AccessLogger.Info("len:", len(tmpRows)) // sku id数组 //gsids := []int64{} //for _, v := range tmpRows { // gsids = append(gsids, v.Gsid) //} //specs, err := admin_lib.QueryBusinessOrderSpecs(gsids) //utils.Error(err) //logger.AccessLogger.Info("len:", len(specs)) // 匹配返回值 for idx, main := range resp.Data { //dataTmp := adminStruct.BusinessOrderList{} for _, details := range tmpRows { if details.Boid == main.Boid { //details = append(details, k) resp.Data[idx].Detail = append(resp.Data[idx].Detail, details) } } //dataTmp.BusinessOrderMainInfo = main //dataTmp.Detail = details //resp.Data = append(resp.Data, dataTmp) } return a.ReturnSuccessCustomResponse(resp) }
时间: 2024-04-14 15:29:50 浏览: 106
Python 基础课程《16.函数使用进阶》
这是一个名为`AppOperateOrderList`的函数,用于操作订单列表。首先,它初始化了一些变量,并创建了一个`OperateOrderListResponse`结构体和一个成功的响应对象。然后,它构建了一个查询对象`query`,查询的表是`business_order_info`,并选择了一些字段。接下来,根据传入的参数进行条件过滤,并将过滤后的结果存储在`query`中。然后,通过调用`Count`方法获取查询结果的数量,并检查是否有错误。接着,通过调用`Order`、`Offset`和`Limit`方法分页查询数据,并将数据存储在`resp.Data`中。然后,根据查询出的主订单信息,查询其对应的订单明细信息,并将明细信息存储在`tmpRows`中。最后,将明细信息与主订单信息进行匹配,并将匹配后的数据存储在`resp.Data`中。最后,返回成功的响应对象。
阅读全文