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) zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{ "uid": uid, "buyType": buyType, "state": state, "stime": stime, "etime": etime, })) fmt.Println("============test订单数=================") fmt.Println(str) total, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at=0", uid, stime, etime).In("state", state).Count(&model.OrdList{}) total1, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at>0", uid, stime, etime).Count(&model.OrdList{}) total3, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and confirm_at=0", uid, stime, etime).Count(&model.OrdList{}) total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Count(&model.PrivilegeCardOrd{}) fmt.Println(total) return total + total1 + total2 + total3, 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).In("state", state).Where(" confirm_at > ? AND confirm_at < ?", 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, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at=0", uid, stime, etime).In("state", state).Sum(&model.OrdList{}, "paid_price") total1, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at>0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price") total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price") fmt.Println(total) return total + total1 + total2, nil } // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 func OrderListCountByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (int64, error) { str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ", zhios_condition_statistics_utils.AnyToString(uid), buyType, state) zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{ "uid": uid, "buyType": buyType, "state": state, })) fmt.Println("============test订单数=================") fmt.Println(str) total, _ := Db.Where("uid = ? and settle_at=0", uid).In("state", state).Count(&model.OrdList{}) total1, _ := Db.Where("uid = ? and settle_at>0", uid).Count(&model.OrdList{}) total3, _ := Db.Where("uid = ? and confirm_at=0", uid).Count(&model.OrdList{}) total2, _ := Db.Where("uid = ? and state=?", uid, 1).Count(&model.PrivilegeCardOrd{}) fmt.Println(total) return total + total1 + total2 + total3, nil } // 查询用户某时间段内某状态的佣金(ord_id => amount) func OrderRelateListByState(Db *xorm.Engine, uid, state 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) ", state) fmt.Println("============test佣金数=================") fmt.Println(str) // 已结算的订单数据 err = Db.In("ord_id", ids).In("state", state).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 OrderListPaidPriceByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ", zhios_condition_statistics_utils.AnyToString(uid), buyType, state) fmt.Println("============test订单数=================") fmt.Println(str) total, _ := Db.Where("uid = ? and settle_at=0", uid).In("state", state).Sum(&model.OrdList{}, "paid_price") total1, _ := Db.Where("uid = ? and settle_at>0", uid).Sum(&model.OrdList{}, "paid_price") total2, _ := Db.Where("uid = ? and state=?", uid, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price") fmt.Println(total) return total + total1 + total2, nil }