From 52bdee83cc3f2725c1ecbf3d134622608572642a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 12 Jul 2022 13:49:25 +0800 Subject: [PATCH] =?UTF-8?q?add=20reverse:for=20v1.0.1=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db_b2c_ord.go | 18 +++++++++++++ db/db_mall_order.go | 15 +++++++++++ db/db_o2o_ord.go | 27 ++++++++++++++++++++ db/db_order.go | 17 +++++++++++++ hdl/hdl_condition.go | 60 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 db/db_b2c_ord.go create mode 100644 db/db_o2o_ord.go diff --git a/db/db_b2c_ord.go b/db/db_b2c_ord.go new file mode 100644 index 0000000..5f44754 --- /dev/null +++ b/db/db_b2c_ord.go @@ -0,0 +1,18 @@ +package db + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model" + zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" + "fmt" + "xorm.io/xorm" +) + +func B2cOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) AND create_time > ? AND create_time < ?", uid, state, stime, etime).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 3264839..c06fba1 100644 --- a/db/db_mall_order.go +++ b/db/db_mall_order.go @@ -2,6 +2,7 @@ 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" @@ -62,3 +63,17 @@ func MallOrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, en } return &idAmountMap, sum, nil } + +func MallOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { + sess := Db.Where("uid = ? AND state in (?) AND create_time > ? AND create_time < ?", uid, state, stime, etime) + 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 +} \ No newline at end of file diff --git a/db/db_o2o_ord.go b/db/db_o2o_ord.go new file mode 100644 index 0000000..5a03051 --- /dev/null +++ b/db/db_o2o_ord.go @@ -0,0 +1,27 @@ +package db + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model" + zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" + "fmt" + "xorm.io/xorm" +) + +func O2oOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) AND create_time > ? AND create_time < ?", uid, state, stime, etime).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 O2oOrdPayToMerchantByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { + total, err := Db.Where("uid = ? AND state in (?) AND create_time > ? AND create_time < ?", uid, state, stime, etime).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 39b8d6a..b90a606 100644 --- a/db/db_order.go +++ b/db/db_order.go @@ -66,3 +66,20 @@ func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTim 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 +} diff --git a/hdl/hdl_condition.go b/hdl/hdl_condition.go index a170cd9..eea5364 100644 --- a/hdl/hdl_condition.go +++ b/hdl/hdl_condition.go @@ -153,6 +153,66 @@ func ExtendByLvCount(engine *xorm.Engine, uid interface{}, task map[string]strin return count } +// 累计自购消费金额 + +func OwnbuySum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string { + var total float64 = 0 + var err error + if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "1"}) { + stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()).Unix() + etime := t.Unix() + total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, "3,5", stime, etime) + if err != nil { + zhios_condition_statistics_logx.Warn(err) + return "" + } + } + if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "2", "8", "9"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + orderType := 0 + if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"8", "9"}) { + orderType = zhios_condition_statistics_utils.StrToInt(task["task_type_pvd"]) + } + //确认收货的才算 + mallTotal, err := db.MallOrdByTime(engine, uid, orderType, "3", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + zhios_condition_statistics_logx.Warn(err) + return zhios_condition_statistics_utils.Float64ToStr(total) + } + total += mallTotal + } + if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "3"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + //确认收货的才算 + o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, "3", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + zhios_condition_statistics_logx.Warn(err) + return zhios_condition_statistics_utils.Float64ToStr(total) + } + total += o2oTotal + o2oTotal1, err := db.O2oOrdPayToMerchantByTime(engine, uid, 0, "1", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + zhios_condition_statistics_logx.Warn(err) + return zhios_condition_statistics_utils.Float64ToStr(total) + } + total += o2oTotal1 + } + if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "4"}) { + mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()) + mallEtime := t + //确认收货的才算 + b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, "3", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05")) + if err != nil { + zhios_condition_statistics_logx.Warn(err) + return zhios_condition_statistics_utils.Float64ToStr(total) + } + total += b2cTotal + } + return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)) +} + //累计团队消费金额 func TeamBuySum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {