From dbefd981b0ccb4d448ea79df40ccd764d9065b72 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 4 May 2023 17:06:07 +0800 Subject: [PATCH] test --- db/db_b2c_ord.go | 10 ++ db/db_mall_order.go | 70 ++++++++++++ db/db_o2o_ord.go | 19 ++++ db/db_order.go | 79 +++++++++++++ hdl/hdl_upgrade.go | 270 +++++++++++++++++++++++++++++++------------- 5 files changed, 372 insertions(+), 76 deletions(-) diff --git a/db/db_b2c_ord.go b/db/db_b2c_ord.go index 5f44754..1f1a26b 100644 --- a/db/db_b2c_ord.go +++ b/db/db_b2c_ord.go @@ -16,3 +16,13 @@ func B2cOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{} } return total, nil } + +func B2cOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) ", uid, state).Sum(&model.B2cOrd{}, "cost_price") + fmt.Println(err) + fmt.Println(total) + if err != nil { + return 0, zhios_condition_statistics_logx.Error(err) + } + return total, nil +} diff --git a/db/db_mall_order.go b/db/db_mall_order.go index 208cd06..702f3b0 100644 --- a/db/db_mall_order.go +++ b/db/db_mall_order.go @@ -77,3 +77,73 @@ func MallOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{ } return total, nil } + +func MallOrdWithCount(Db *xorm.Engine, uid, buyType, state interface{}) (int64, error) { + total, err := Db.Where("uid = ? AND state in (?) ", uid, state).Count(&model.MallOrd{}) + fmt.Println(err) + fmt.Println(total) + if err != nil { + return 0, zhios_condition_statistics_logx.Error(err) + } + return total, nil +} + +// 查询用户某时间段内某状态的佣金(ord_id => amount) +func MallOrderRelateListByState(Db *xorm.Engine, uid, state interface{}) (*map[int64]float64, float64, error) { + var o []*model.MallOrd + var or []*model.MallOrdListRelate + var idAmountMap = make(map[int64]float64) + // 分佣明细数据 + err := Db.Where("`uid` = ?", uid).Find(&or) + if err != nil { + zhios_condition_statistics_logx.Error(err) + return nil, 0, err + } + if len(or) == 0 { + return &idAmountMap, 0, 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).Where("state in (?) ", state).Find(&o) + if err != nil { + zhios_condition_statistics_logx.Error(err) + return nil, 0, err + } + if len(o) == 0 { + return &idAmountMap, 0, nil + } + + // id => amount + for _, item := range o { + for _, i := range or { + if item.OrdId == i.Oid { + idAmountMap[i.Oid] = i.Amount + } + } + } + var sum float64 + for _, item := range idAmountMap { + sum += item + } + return &idAmountMap, sum, nil +} + +func MallOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { + sess := Db.Where("uid = ? AND state in (?) ", uid, state) + if zhios_condition_statistics_utils.AnyToInt64(buyType) > 0 { + sess.And("order_type", buyType) + } + total, err := sess.Sum(&model.MallOrd{}, "cost_price") + fmt.Println(err) + fmt.Println(total) + if err != nil { + return 0, zhios_condition_statistics_logx.Error(err) + } + return total, nil +} diff --git a/db/db_o2o_ord.go b/db/db_o2o_ord.go index 5a03051..c0eb8ae 100644 --- a/db/db_o2o_ord.go +++ b/db/db_o2o_ord.go @@ -25,3 +25,22 @@ func O2oOrdPayToMerchantByTime(Db *xorm.Engine, uid, buyType, state, stime, etim } return total, nil } + +func O2oOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) ", uid, state).Sum(&model.O2oOrd{}, "cost_price") + fmt.Println(err) + fmt.Println(total) + if err != nil { + return 0, zhios_condition_statistics_logx.Error(err) + } + return total, nil +} +func O2oOrdPayToMerchant(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) ", uid, state).Sum(&model.O2oPayToMerchant{}, "actual_pay_amount") + fmt.Println(err) + fmt.Println(total) + if err != nil { + return 0, zhios_condition_statistics_logx.Error(err) + } + return total, nil +} diff --git a/db/db_order.go b/db/db_order.go index 9a4b0ad..ee08944 100644 --- a/db/db_order.go +++ b/db/db_order.go @@ -88,3 +88,82 @@ func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, sta 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 +} diff --git a/hdl/hdl_upgrade.go b/hdl/hdl_upgrade.go index 87cc132..1c47198 100644 --- a/hdl/hdl_upgrade.go +++ b/hdl/hdl_upgrade.go @@ -347,70 +347,128 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, // 累计自购数 stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() etime := t.Unix() - //联盟结算后的 - total, err := db.OrderListCountByUIDByOrderTypeByTime(engine, uid, 0, "3,5", stime, etime) - if err != nil { - return "", hasPay, payOrdId - } mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) mallEtime := t - //确认收货的才算 - mallTotal, err := db.MallOrdByTimeWithCount(engine, uid, 0, "3", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) - if err != nil { - return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId - } - total += mallTotal - return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId - case 10: - // 累计自购消费金额 - var total float64 = 0 + var total int64 var err error - if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { - stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() - etime := t.Unix() - total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, []string{"3", "5"}, stime, etime) + //联盟结算后的 + if task.WithinDays <= 0 { + total, err = db.OrderListCountByUIDByOrderType(engine, uid, 0, "3,5") if err != nil { return "", hasPay, payOrdId } - } - if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) { - mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) - mallEtime := t - orderType := 0 - if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) { - orderType = task.TaskTypePvd - } //确认收货的才算 - mallTotal, err := db.MallOrdByTime(engine, uid, orderType, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + mallTotal, err := db.MallOrdWithCount(engine, uid, 0, "3") if err != nil { - return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId } total += mallTotal - } - if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { - mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) - mallEtime := t - //确认收货的才算 - o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + } else { + total, err = db.OrderListCountByUIDByOrderTypeByTime(engine, uid, 0, "3,5", stime, etime) if err != nil { - return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + return "", hasPay, payOrdId } - total += o2oTotal - o2oTotal1, err := db.O2oOrdPayToMerchantByTime(engine, uid, 0, []string{"1", "4"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + //确认收货的才算 + mallTotal, err := db.MallOrdByTimeWithCount(engine, uid, 0, "3", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) if err != nil { - return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId } - total += o2oTotal1 + total += mallTotal } - if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { - mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) - mallEtime := t - //确认收货的才算 - b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) - if err != nil { - return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + + return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId + case 10: + // 累计自购消费金额 + var total float64 = 0 + var err error + if task.WithinDays <= 0 { + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { + total, err = db.OrderListPaidPriceByUIDByOrderType(engine, uid, 0, []string{"3", "5"}) + if err != nil { + return "", hasPay, payOrdId + } + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) { + orderType := 0 + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) { + orderType = task.TaskTypePvd + } + //确认收货的才算 + mallTotal, err := db.MallOrd(engine, uid, orderType, []string{"3"}) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += mallTotal + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { + //确认收货的才算 + o2oTotal, err := db.O2oOrd(engine, uid, 0, []string{"3"}) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += o2oTotal + o2oTotal1, err := db.O2oOrdPayToMerchant(engine, uid, 0, []string{"1", "4"}) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += o2oTotal1 + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { + //确认收货的才算 + b2cTotal, err := db.B2cOrd(engine, uid, 0, []string{"3"}) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += b2cTotal + } + } else { + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { + stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() + etime := t.Unix() + total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, []string{"3", "5"}, stime, etime) + if err != nil { + return "", hasPay, payOrdId + } + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + orderType := 0 + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) { + orderType = task.TaskTypePvd + } + //确认收货的才算 + mallTotal, err := db.MallOrdByTime(engine, uid, orderType, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += mallTotal + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + //确认收货的才算 + o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += o2oTotal + o2oTotal1, err := db.O2oOrdPayToMerchantByTime(engine, uid, 0, []string{"1", "4"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += o2oTotal1 + } + if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + //确认收货的才算 + b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId + } + total += b2cTotal } - total += b2cTotal } return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId @@ -418,22 +476,39 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, // 累计已结算佣金 stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() etime := t.Unix() - // 用户分佣的订单 - idAmountMap, err := db.OrderRelateListByTimeByState(engine, uid, "3,5", stime, etime) - if err != nil { - return "", hasPay, payOrdId - } - var sum float64 - for _, item := range *idAmountMap { - sum += item - } mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) mallEtime := t - _, mallSum, err := db.MallOrderRelateListByTimeByState(engine, uid, 3, mallStime, mallEtime) - if err != nil { - return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId + var sum float64 + if task.WithinDays <= 0 { + // 用户分佣的订单 + idAmountMap, err := db.OrderRelateListByState(engine, uid, "3,5") + if err != nil { + return "", hasPay, payOrdId + } + for _, item := range *idAmountMap { + sum += item + } + _, mallSum, err := db.MallOrderRelateListByState(engine, uid, 3) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId + } + sum += mallSum + } else { + // 用户分佣的订单 + idAmountMap, err := db.OrderRelateListByTimeByState(engine, uid, "3,5", stime, etime) + if err != nil { + return "", hasPay, payOrdId + } + for _, item := range *idAmountMap { + sum += item + } + _, mallSum, err := db.MallOrderRelateListByTimeByState(engine, uid, 3, mallStime, mallEtime) + if err != nil { + return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId + } + sum += mallSum } - sum += mallSum + return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId case 3: // 累计直推人数 @@ -443,7 +518,12 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, FROM user_profile as up LEFT JOIN user as u ON u.uid=up.uid WHERE %s;` - condStr := fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), stime, etime) + var condStr string + if task.WithinDays <= 0 { + condStr = fmt.Sprintf("up.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid)) + } else { + condStr = fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), stime, etime) + } sql := fmt.Sprintf(sqlTpl, condStr) results, err := db.QueryNativeString(engine, sql) if err != nil { @@ -462,7 +542,13 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, FROM user_profile as up LEFT JOIN user as u ON u.uid=up.uid WHERE %s;` - condStr := fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s' and up.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), stime, etime, 1) + var condStr string + if task.WithinDays <= 0 { + condStr = fmt.Sprintf("up.parent_uid=%s and up.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), 1) + + } else { + condStr = fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s' and up.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), stime, etime, 1) + } sql := fmt.Sprintf(sqlTpl, condStr) results, err := db.QueryNativeString(engine, sql) if err != nil { @@ -487,10 +573,17 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, if levelList != nil { levelWeight = levelList.LevelWeight } - condStr := fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) - - if blockStarChain == "1" { - condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + var condStr string + if task.WithinDays <= 0 { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight)) + if blockStarChain == "1" { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight)) + } + } else { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + if blockStarChain == "1" { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + } } sql := fmt.Sprintf(sqlTpl, condStr) fmt.Println(sql) @@ -519,10 +612,18 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, if levelList != nil { levelWeight = levelList.LevelWeight } - condStr := fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + var condStr string + if task.WithinDays <= 0 { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight)) + if blockStarChain == "1" { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight)) + } + } else { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) - if blockStarChain == "1" { - condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + if blockStarChain == "1" { + condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + } } sql := fmt.Sprintf(sqlTpl, condStr) fmt.Println(sql) @@ -687,13 +788,20 @@ WHERE olr.uid = ? sqlTpl := `select ur.parent_uid,COUNT(*) as count FROM user_relate ur LEFT JOIN user u on u.uid=ur.uid LEFT JOIN user_level ul on u.level=ul.id -where ur.parent_uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1 ) and ul.level_weight>=%s and u.level_arrive_at>='%s' and u.level_arrive_at<='%s' GROUP BY ur.parent_uid;` +where ur.parent_uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1 ) and ul.level_weight>=%s %s GROUP BY ur.parent_uid;` + levelList := allLvMap[task.TaskTypeLevelId] levelWeight := 0 if levelList != nil { levelWeight = levelList.LevelWeight } - sql := fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) + sql := "" + if task.WithinDays <= 0 { + sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "") + } else { + sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "and u.level_arrive_at>='"+stime+"' and u.level_arrive_at<='"+etime+"'") + } + results, err := db.QueryNativeString(engine, sql) if err != nil { @@ -702,8 +810,13 @@ where ur.parent_uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and leve sqlTpl1 := `select ur.uid FROM user_relate ur LEFT JOIN user u on u.uid=ur.uid LEFT JOIN user_level ul on u.level=ul.id -where ur.parent_uid=%s and ur.level=1 and ul.level_weight>=%s and u.level_arrive_at>='%s' and u.level_arrive_at<='%s' ;` - sql1 := fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime) +where ur.parent_uid=%s and ur.level=1 and ul.level_weight>=%s %s ;` + sql1 := "" + if task.WithinDays <= 0 { + sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "") + } else { + sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "and u.level_arrive_at>='"+stime+"' and u.level_arrive_at<='"+etime+"'") + } results1, err1 := db.QueryNativeString(engine, sql1) if err1 != nil { return "", hasPay, payOrdId @@ -734,7 +847,7 @@ where ur.parent_uid=%s and ur.level=1 and ul.level_weight>=%s and u.level_arri // 小区消费金额 sqlTpl := `SELECT SUM(molr.goods_price) as price FROM mall_ord_list_relate molr LEFT JOIN mall_ord mo on mo.ord_id=molr.oid and mo.state in (%s) -WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) and mo.create_time>='%s' and mo.create_time<='%s' GROUP BY molr.uid ;` +WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) %s GROUP BY molr.uid ;` state := "1,2,3" if task.TaskTypePvd == 1 { state = "2,3" @@ -742,7 +855,12 @@ WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) if task.TaskTypePvd == 2 { state = "3" } - sql := fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), stime, etime) + sql := "" + if task.WithinDays <= 0 { + sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "") + } else { + sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "and mo.create_time>='"+stime+"' and mo.create_time<='"+etime+"'") + } results, err := db.QueryNativeString(engine, sql) if err != nil {