package db import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model" zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils" zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" "fmt" "xorm.io/xorm" ) // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 func OrderListCountByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (int64, error) { str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s", zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime) fmt.Println("============test订单数=================") fmt.Println(str) total, err := Db.Where("uid = ? AND order_type = ? AND ( state in (?) or settle_at>0) AND create_at > ? AND create_at < ?", uid, buyType, state, stime, etime).Count(&model.OrdList{}) fmt.Println(err) fmt.Println(total) if err != nil { return 0, zhios_condition_statistics_logx.Error(err) } return total, nil } // 查询用户某时间段内某状态的佣金(ord_id => amount) func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) (*map[int64]float64, error) { var o []*model.OrdList var or []*model.OrdListRelate var idAmountMap = make(map[int64]float64) // 分佣明细数据 err := Db.Where("`uid` = ?", uid).Find(&or) if err != nil { zhios_condition_statistics_logx.Error(err) return nil, err } if len(or) == 0 { return &idAmountMap, nil } var ids []int64 for _, item := range or { ids = append(ids, item.Oid) } str := fmt.Sprintf("state in (%s) AND create_at >%s AND create_at < %s", state, startTime, endTime) fmt.Println("============test佣金数=================") fmt.Println(str) // 已结算的订单数据 err = Db.In("ord_id", ids).Where("state in (?) AND create_at > ? AND create_at < ?", state, startTime, endTime).Find(&o) if err != nil { zhios_condition_statistics_logx.Error(err) return nil, err } if len(o) == 0 { return &idAmountMap, nil } // id => amount for _, item := range o { for _, i := range or { if item.OrdId == i.Oid { idAmountMap[i.Oid] = i.Amount } } } return &idAmountMap, nil } // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s", zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime) fmt.Println("============test订单数=================") fmt.Println(str) total, err := Db.Where("uid = ? AND order_type = ? AND ( state in (?) or settle_at>0) AND create_at > ? AND create_at < ?", uid, buyType, state, stime, etime).Sum(&model.OrdList{}, "paid_price") fmt.Println(err) fmt.Println(total) if err != nil { return 0, zhios_condition_statistics_logx.Error(err) } return total, nil }