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" "strings" "time" "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{}) total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Count(&model.RechargeOrder{}) total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Count(&model.ExpressOrder{}) fmt.Println(total) return total + total1 + total2 + total3 + total4 + total5, 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{}, isSettle int) (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) var total float64 = 0 if isSettle == 1 { total1, _ := Db.Where("uid = ? AND settle_at > ? AND settle_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") total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Sum(&model.RechargeOrder{}, "amount") total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Sum(&model.ExpressOrder{}, "money") total = total + total1 + total2 + total4 + total5 } else { types := "confirm_at" serializeStr := zhios_condition_statistics_utils.SerializeStr(state) if strings.Contains(serializeStr, "3") { types = "pvd_settle_at" } if strings.Contains(serializeStr, "1") || strings.Contains(serializeStr, "2") { types = "confirm_at" } if strings.Contains(serializeStr, "0") { types = "create_at" } sqlStr := fmt.Sprintf(" %s >'%s' AND %s < '%s'", types, stime, types, etime) total, _ = Db.Where("uid = ? AND ? and settle_at=0", uid, sqlStr).In("state", state).Sum(&model.OrdList{}, "paid_price") total1, _ := Db.Where("uid = ? AND ? and settle_at>0", uid, sqlStr).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") total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Sum(&model.RechargeOrder{}, "amount") total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Sum(&model.ExpressOrder{}, "money") total = total + total1 + total2 + total4 + total5 } fmt.Println(total) return total, 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{}) total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Count(&model.RechargeOrder{}) fmt.Println(total) return total + total1 + total2 + total3 + total4, 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{}, isSettle int) (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) var total float64 = 0 if isSettle == 1 { total, _ = 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") total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount") total = total + total2 + total4 } else { 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") total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount") total = total + total1 + total2 + total4 } fmt.Println(total) return total, nil }