@@ -2,23 +2,42 @@ package db | |||||
import ( | import ( | ||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model" | "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" | zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" | ||||
"fmt" | "fmt" | ||||
"strings" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
func B2cOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { | |||||
total, err := Db.Where("uid = ? AND create_time > ? AND create_time < ?", uid, state, stime, etime).In("state", state).Sum(&model.B2cOrd{}, "cost_price") | |||||
func B2cOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
serializeStr := zhios_condition_statistics_utils.SerializeStr(state) | |||||
if isSettle == 1 { | |||||
sess = sess.And(" settle_time > ? AND settle_time < ?", stime, etime) | |||||
} else if strings.Contains(serializeStr, "1") { | |||||
sess = sess.And(" create_time > ? AND create_time < ?", stime, etime).In("state", state) | |||||
} else { | |||||
sess = sess.And(" confirm_time > ? AND confirm_time < ?", stime, etime).In("state", state) | |||||
} | |||||
total, err := sess.Sum(&model.B2cOrd{}, "cost_price") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
return 0, zhios_condition_statistics_logx.Error(err) | return 0, zhios_condition_statistics_logx.Error(err) | ||||
} | } | ||||
return total, nil | return total, nil | ||||
} | } | ||||
func B2cOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { | |||||
total, err := Db.Where("uid = ? ", uid).In("state", state).Sum(&model.B2cOrd{}, "cost_price") | |||||
func B2cOrd(Db *xorm.Engine, uid, buyType, state interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if isSettle == 1 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Sum(&model.B2cOrd{}, "cost_price") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
@@ -64,12 +64,14 @@ func MallOrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, en | |||||
return &idAmountMap, sum, nil | return &idAmountMap, sum, nil | ||||
} | } | ||||
func MallOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, newState string) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid).In("state", state) | |||||
if newState == "1" { | |||||
sess = sess.And(" create_time > ? AND create_time < ?", stime, etime) | |||||
func MallOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, newState string, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if isSettle == 1 { | |||||
sess = sess.And(" settle_time > ? AND settle_time < ?", stime, etime) | |||||
} else if newState == "1" { | |||||
sess = sess.And(" create_time > ? AND create_time < ?", stime, etime).In("state", state) | |||||
} else { | } else { | ||||
sess = sess.And(" confirm_time > ? AND confirm_time < ?", stime, etime) | |||||
sess = sess.And(" confirm_time > ? AND confirm_time < ?", stime, etime).In("state", state) | |||||
} | } | ||||
if zhios_condition_statistics_utils.AnyToInt64(buyType) > 0 { | if zhios_condition_statistics_utils.AnyToInt64(buyType) > 0 { | ||||
sess.And("order_type=?", buyType) | sess.And("order_type=?", buyType) | ||||
@@ -139,8 +141,13 @@ func MallOrderRelateListByState(Db *xorm.Engine, uid, state interface{}) (*map[i | |||||
return &idAmountMap, sum, nil | return &idAmountMap, sum, nil | ||||
} | } | ||||
func MallOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid).In("state", state) | |||||
func MallOrd(Db *xorm.Engine, uid, buyType, state interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if isSettle == 1 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.In("state", state) | |||||
} | |||||
if zhios_condition_statistics_utils.AnyToInt64(buyType) > 0 { | if zhios_condition_statistics_utils.AnyToInt64(buyType) > 0 { | ||||
sess.And("order_type=?", buyType) | sess.And("order_type=?", buyType) | ||||
} | } | ||||
@@ -2,13 +2,24 @@ package db | |||||
import ( | import ( | ||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model" | "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" | zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" | ||||
"fmt" | "fmt" | ||||
"strings" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
func O2oOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { | |||||
total, err := Db.Where("uid = ? AND create_time > ? AND create_time < ?", uid, stime, etime).In("state", state).Sum(&model.O2oOrd{}, "cost_price") | |||||
func O2oOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
serializeStr := zhios_condition_statistics_utils.SerializeStr(state) | |||||
if isSettle == 1 { | |||||
sess = sess.And(" settle_time > ? AND settle_time < ?", stime, etime) | |||||
} else if strings.Contains(serializeStr, "1") { | |||||
sess = sess.And(" create_time > ? AND create_time < ?", stime, etime).In("state", state) | |||||
} else { | |||||
sess = sess.And(" confirm_time > ? AND confirm_time < ?", stime, etime).In("state", state) | |||||
} | |||||
total, err := sess.Sum(&model.O2oOrd{}, "cost_price") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
@@ -16,8 +27,14 @@ func O2oOrdByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{} | |||||
} | } | ||||
return total, nil | 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") | |||||
func O2oOrdPayToMerchantByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? AND state in (?)", uid, state) | |||||
if isSettle == 1 { | |||||
sess = sess.And(" settle_time > ? AND settle_time < ?", stime, etime) | |||||
} else { | |||||
sess = sess.And(" create_time > ? AND create_time < ?", stime, etime) | |||||
} | |||||
total, err := sess.Sum(&model.O2oPayToMerchant{}, "actual_pay_amount") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
@@ -26,8 +43,14 @@ func O2oOrdPayToMerchantByTime(Db *xorm.Engine, uid, buyType, state, stime, etim | |||||
return total, nil | return total, nil | ||||
} | } | ||||
func O2oOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { | |||||
total, err := Db.Where("uid = ? ", uid).In("state", state).Sum(&model.O2oOrd{}, "cost_price") | |||||
func O2oOrd(Db *xorm.Engine, uid, buyType, state interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ?", uid) | |||||
if isSettle == 1 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Sum(&model.O2oOrd{}, "cost_price") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
@@ -35,8 +58,14 @@ func O2oOrd(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { | |||||
} | } | ||||
return total, nil | 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") | |||||
func O2oOrdPayToMerchant(Db *xorm.Engine, uid, buyType, state interface{}, isSettle int) (float64, error) { | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if isSettle == 1 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.And("state in (?)", state) | |||||
} | |||||
total, err := sess.Sum(&model.O2oPayToMerchant{}, "actual_pay_amount") | |||||
fmt.Println(err) | fmt.Println(err) | ||||
fmt.Println(total) | fmt.Println(total) | ||||
if err != nil { | if err != nil { | ||||
@@ -5,6 +5,7 @@ import ( | |||||
zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils" | 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" | zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx" | ||||
"fmt" | "fmt" | ||||
"strings" | |||||
"time" | "time" | ||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -77,20 +78,40 @@ func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTim | |||||
} | } | ||||
// OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 | // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 | ||||
func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { | |||||
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", | 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.AnyToString(uid), buyType, state, stime, etime) | ||||
fmt.Println("============test订单数=================") | fmt.Println("============test订单数=================") | ||||
fmt.Println(str) | 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") | |||||
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") | |||||
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") | |||||
total = total + total1 + total2 + total4 | |||||
} 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" | |||||
} | |||||
total, _ = Db.Where("uid = ? AND ? > ? AND ? < ? and settle_at=0", uid, types, stime, types, etime).In("state", state).Sum(&model.OrdList{}, "paid_price") | |||||
total1, _ := Db.Where("uid = ? AND ? > ? AND ? < ? and settle_at>0", uid, types, stime, types, 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") | |||||
total = total + total1 + total2 + total4 | |||||
} | |||||
fmt.Println(total) | fmt.Println(total) | ||||
return total + total1 + total2 + total4, nil | |||||
return total, nil | |||||
} | } | ||||
// OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 | // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 | ||||
@@ -159,18 +180,27 @@ func OrderRelateListByState(Db *xorm.Engine, uid, state interface{}) (*map[int64 | |||||
} | } | ||||
// OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 | // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 | ||||
func OrderListPaidPriceByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) { | |||||
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) ", | 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.AnyToString(uid), buyType, state) | ||||
fmt.Println("============test订单数=================") | fmt.Println("============test订单数=================") | ||||
fmt.Println(str) | 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") | |||||
total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount") | |||||
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) | fmt.Println(total) | ||||
return total + total1 + total2 + total4, nil | |||||
return total, nil | |||||
} | } |
@@ -0,0 +1,170 @@ | |||||
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" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 | |||||
func OrderListCountByUIDByOrderTypeByTimeNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (int64, error) { | |||||
state := []string{"1", "2", "3", "5"} | |||||
timeType := "confirm_at" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_at" | |||||
state = []string{"0", "1", "2", "3", "5"} | |||||
} | |||||
timeType2 := "created_at" | |||||
timeType4 := "create_time" | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_at" | |||||
timeType2 = "settle_at" | |||||
timeType4 = "settle_at" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
var total int64 = 0 | |||||
sess := Db.Where("uid = ? and settle_at=0", uid) | |||||
sess1 := Db.Where("uid = ? and settle_at>0", uid) | |||||
sess2 := Db.Where("uid = ?", uid) | |||||
sess4 := Db.Where("uid = ?", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime.Unix(), etime.Unix()) | |||||
sess1.And(" ? > ? AND ? < ?", timeType, timeType, stime.Unix(), etime.Unix()) | |||||
sess2.And(" ? > ? AND ? < ?", timeType2, timeType2, stime.Unix(), etime.Unix()) | |||||
sess4.And(" ? > ? AND ? < ?", timeType4, timeType4, stime.Format("2006-01-02 15:04:05"), etime.Format("2006-01-02 15:04:05")) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess2.And("settle_at>0") | |||||
sess4.And("settle_at>0") | |||||
} | |||||
if task.OrdState != 3 { | |||||
total, _ = sess.In("state", state).Count(&model.OrdList{}) | |||||
total3, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and confirm_at=0", uid, stime, etime).Count(&model.OrdList{}) | |||||
total += total3 | |||||
} | |||||
total1, _ := sess1.Count(&model.OrdList{}) | |||||
total2, _ := sess2.Where("state=?", uid, 1).Count(&model.PrivilegeCardOrd{}) | |||||
total4, _ := sess4.Where("status=?", uid, "已付款").Count(&model.RechargeOrder{}) | |||||
fmt.Println(total) | |||||
return total + total1 + total2 + total4, nil | |||||
} | |||||
func MallOrdWithCountNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (int64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Count(&model.MallOrd{}) | |||||
fmt.Println(err) | |||||
fmt.Println(total) | |||||
if err != nil { | |||||
return 0, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
return total, nil | |||||
} | |||||
func O2oOrdWithCountNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (int64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
timeType1 := "create_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
timeType1 = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Count(&model.O2oOrd{}) | |||||
fmt.Println(err) | |||||
fmt.Println(total) | |||||
if err != nil { | |||||
return 0, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
sess1 := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess1.And(" ? > ? AND ? < ?", timeType1, timeType1, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.And("state in (?)", "1,4") | |||||
} | |||||
total1, err1 := sess1.Count(&model.O2oPayToMerchant{}) | |||||
if err1 != nil { | |||||
return total, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
total += total1 | |||||
return total, nil | |||||
} | |||||
func B2cOrdWithCountNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (int64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Count(&model.B2cOrd{}) | |||||
fmt.Println(err) | |||||
fmt.Println(total) | |||||
if err != nil { | |||||
return 0, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
return total, nil | |||||
} |
@@ -0,0 +1,211 @@ | |||||
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" | |||||
"fmt" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func OrderRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.confirm_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.confirm_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.created_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.created_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.created_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.created_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.settle_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.settle_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
timeStr += " and (ol.settle_at>0 or pco.settle_at>0 or dol.settle_at>0 or ro.settle_at>0 or pso.settle_time>0)" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT cast(SUM(LEFT(olr.amount,LENGTH(olr.amount)-2)) as decimal(50,4)) AS amount | |||||
FROM ord_list_relate olr | |||||
LEFT JOIN ord_list ol ON olr.oid = ol.ord_id | |||||
LEFT JOIN privilege_card_ord pco ON olr.oid =pco.ord_id | |||||
LEFT JOIN duoyou_ord_list dol ON olr.oid =dol.oid | |||||
LEFT JOIN recharge_order ro ON olr.oid =ro.oid | |||||
LEFT JOIN playlet_sale_order pso ON olr.oid =pso.custom_oid | |||||
WHERE olr.uid = ? and olr.level=0 %s AND (ol.state in(%s) or pco.state=1 or dol.id>0 or ro.status<>'已退款' or pso.status<>'订单退款'); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func MallOrderRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
timeStr += " and ol.settle_time is not null" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT cast(SUM(olr.amount) as decimal(50,6)) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN mall_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? and olr.level=0 %s AND ol.state IN (%s); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func O2oOrderRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
timeStr += " and (ol.settle_time is not null or optm.settle_time is not null)" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT cast(SUM(olr.amount) as decimal(50,6)) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN o2o_ord ol ON olr.oid = ol.ord_id | |||||
LEFT JOIN o2o_pay_to_merchant optm ON optm.pay_id = olr.oid | |||||
WHERE olr.uid = ? and olr.level=0 %s AND (ol.state IN (%s) or optm.state>=1); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func B2cOrderRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
timeStr += " and ol.settle_time is not null" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT cast(SUM(olr.amount) as decimal(50,6)) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN b2c_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? and olr.level=0 %s AND ol.state IN (%s); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} |
@@ -0,0 +1,173 @@ | |||||
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" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 | |||||
func OrderListSumByUIDByOrderTypeByTimeNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
state := []string{"1", "2", "3", "5"} | |||||
timeType := "confirm_at" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_at" | |||||
state = []string{"0", "1", "2", "3", "5"} | |||||
} | |||||
timeType2 := "created_at" | |||||
timeType4 := "create_time" | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_at" | |||||
timeType2 = "settle_at" | |||||
timeType4 = "settle_at" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
var total float64 = 0 | |||||
sess := Db.Where("uid = ? and settle_at=0", uid) | |||||
sess1 := Db.Where("uid = ? and settle_at>0", uid) | |||||
sess2 := Db.Where("uid = ?", uid) | |||||
sess4 := Db.Where("uid = ?", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime.Unix(), etime.Unix()) | |||||
sess1.And(" ? > ? AND ? < ?", timeType, timeType, stime.Unix(), etime.Unix()) | |||||
sess2.And(" ? > ? AND ? < ?", timeType2, timeType2, stime.Unix(), etime.Unix()) | |||||
sess4.And(" ? > ? AND ? < ?", timeType4, timeType4, stime.Format("2006-01-02 15:04:05"), etime.Format("2006-01-02 15:04:05")) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess2.And("settle_at>0") | |||||
sess4.And("settle_at>0") | |||||
} | |||||
if task.OrdState != 3 { | |||||
total, _ = sess.In("state", state).Sum(&model.OrdList{}, "paid_price") | |||||
total3, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and confirm_at=0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price") | |||||
total += total3 | |||||
} | |||||
total1, _ := sess1.Sum(&model.OrdList{}, "paid_price") | |||||
total2, _ := sess2.Where("state=?", uid, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price") | |||||
total4, _ := sess4.Where("status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount") | |||||
fmt.Println(total) | |||||
return total + total1 + total2 + total4, nil | |||||
} | |||||
func MallOrdWithSumNew(Db *xorm.Engine, uid interface{}, orderType int, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if zhios_condition_statistics_utils.AnyToInt64(orderType) > 0 { | |||||
sess.And("order_type=?", orderType) | |||||
} | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
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 | |||||
} | |||||
func O2oOrdWithSumNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
timeType1 := "create_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
timeType1 = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.Sum(&model.O2oOrd{}, "cost_price") | |||||
fmt.Println(err) | |||||
fmt.Println(total) | |||||
if err != nil { | |||||
return 0, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
sess1 := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess1.And(" ? > ? AND ? < ?", timeType1, timeType1, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} else { | |||||
sess.And("state in (?)", "1,4") | |||||
} | |||||
total1, err1 := sess1.Sum(&model.O2oPayToMerchant{}, "actual_pay_amount") | |||||
if err1 != nil { | |||||
return total, zhios_condition_statistics_logx.Error(err) | |||||
} | |||||
total += total1 | |||||
return total, nil | |||||
} | |||||
func B2cOrdWithSumNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
state := []string{"2", "3"} | |||||
timeType := "confirm_time" | |||||
if task.OrdState == 1 { //已付款 | |||||
timeType = "create_time" | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 3 { | |||||
timeType = "settle_time" | |||||
} | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05") | |||||
etime := t.Format("2006-01-02 15:04:05") | |||||
sess := Db.Where("uid = ? ", uid) | |||||
if task.WithinDays > 0 { | |||||
sess.And(" ? > ? AND ? < ?", timeType, timeType, stime, etime) | |||||
} | |||||
if task.OrdState == 3 { | |||||
sess.And("settle_time is not null") | |||||
} | |||||
if task.OrdState != 3 { | |||||
sess.In("state", state) | |||||
} | |||||
total, err := sess.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 | |||||
} |
@@ -0,0 +1,214 @@ | |||||
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" | |||||
"fmt" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func OrderTeamRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.confirm_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.confirm_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.created_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.created_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.created_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.created_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.create_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.create_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.create_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.create_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ol.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pco.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pco.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (dol.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and dol.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (ro.settle_at>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and ro.settle_at<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " or (pso.settle_time>=" + zhios_condition_statistics_utils.Int64ToStr(stime.Unix()) + " and pso.settle_time<=" + zhios_condition_statistics_utils.Int64ToStr(etime.Unix()) + ")" | |||||
timeStr += " )" | |||||
} | |||||
timeStr += " and (ol.settle_at>0 or pco.settle_at>0 or dol.settle_at>0 or ro.settle_at>0 or pso.settle_time>0)" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT SUM(ol.paid_price)+SUM(pco.paid_price)+SUM(ro.amount)+SUM(pso.amount) AS amount | |||||
FROM ord_list_relate olr | |||||
LEFT JOIN ord_list ol ON olr.oid = ol.ord_id | |||||
LEFT JOIN privilege_card_ord pco ON olr.oid =pco.ord_id | |||||
LEFT JOIN duoyou_ord_list dol ON olr.oid =dol.oid | |||||
LEFT JOIN recharge_order ro ON olr.oid =ro.oid | |||||
LEFT JOIN playlet_sale_order pso ON olr.oid =pso.custom_oid | |||||
WHERE olr.uid = ? and olr.level>0 %s AND (ol.state in(%s) or pco.state=1 or dol.id>0 or ro.status<>'已退款' or pso.status<>'订单退款'); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func MallOrderTeamRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
timeStr += " and ol.settle_time is not null" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT SUM(ol.cost_price) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN mall_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? and olr.level>0 %s AND ol.state IN (%s); | |||||
` | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) { | |||||
timeStr += " and ol.order_type=" + zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd) | |||||
} | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func O2oOrderTeamRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.create_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and (" | |||||
timeStr += " (ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " (optm.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and optm.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "')" | |||||
timeStr += " )" | |||||
} | |||||
timeStr += " and (ol.settle_time is not null or optm.settle_time is not null)" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT SUM(ol.cost_price)+SUM(optm.actual_pay_amount) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN o2o_ord ol ON olr.oid = ol.ord_id | |||||
LEFT JOIN o2o_pay_to_merchant optm ON optm.pay_id = olr.oid | |||||
WHERE olr.uid = ? and olr.level>0 %s AND (ol.state IN (%s) or optm.state>=1); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} | |||||
func B2cOrderTeamRelateListByTimeByStateNew(Db *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask) (float64, error) { | |||||
timeStr := "" | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
etime := t | |||||
state := "1,2,3" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.confirm_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.confirm_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = "0,1,2,3,5" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.create_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.create_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
} | |||||
if task.OrdState == 3 { | |||||
state = "" | |||||
timeStr = "" | |||||
if task.WithinDays > 0 { | |||||
timeStr += " and ol.settle_time>='" + stime.Format("2006-01-02 15:04:05") + "' and ol.settle_time<='" + etime.Format("2006-01-02 15:04:05") + "'" | |||||
} | |||||
timeStr += " and ol.settle_time is not null" | |||||
} | |||||
var sum float64 = 0 | |||||
// 统计预估 (预估包含结算部分且是有效订单) | |||||
sqlTpl := `SELECT SUM(ol.cost_price) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
LEFT JOIN b2c_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? and olr.level>0 %s AND ol.state IN (%s); | |||||
` | |||||
sqlTpl = fmt.Sprintf(sqlTpl, timeStr, state) | |||||
todayResult, err := QueryNativeString(Db, sqlTpl, uid) | |||||
if err == nil && len(todayResult) > 0 { | |||||
sum = zhios_condition_statistics_utils.StrToFloat64(todayResult[0]["amount"]) | |||||
} | |||||
return sum, nil | |||||
} |
@@ -369,226 +369,88 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, | |||||
return zhios_condition_statistics_utils.Float64ToStr(money), hasPay, payOrdId | return zhios_condition_statistics_utils.Float64ToStr(money), hasPay, payOrdId | ||||
case 1: | case 1: | ||||
// 累计自购数 | // 累计自购数 | ||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() | |||||
etime := t.Unix() | |||||
mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
mallEtime := t | |||||
var total int64 | |||||
var err error | |||||
//联盟结算后的 | |||||
if task.WithinDays <= 0 { | |||||
total, err = db.OrderListCountByUIDByOrderType(engine, uid, 0, []string{"3", "5"}) | |||||
if err != nil { | |||||
return "", hasPay, payOrdId | |||||
} | |||||
//确认收货的才算 | |||||
mallTotal, err := db.MallOrdWithCount(engine, uid, 0, []string{"3"}) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += mallTotal | |||||
} else { | |||||
total, err = db.OrderListCountByUIDByOrderTypeByTime(engine, uid, 0, []string{"3", "5"}, stime, etime) | |||||
if err != nil { | |||||
return "", hasPay, payOrdId | |||||
} | |||||
//确认收货的才算 | |||||
mallTotal, err := db.MallOrdByTimeWithCount(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.Int64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += mallTotal | |||||
total, err := db.OrderListCountByUIDByOrderTypeByTimeNew(engine, uid, task) | |||||
if err != nil { | |||||
return "", hasPay, payOrdId | |||||
} | } | ||||
mallTotal, err := db.MallOrdWithCountNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += mallTotal | |||||
o2oTotal, err := db.O2oOrdWithCountNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += o2oTotal | |||||
b2cTotal, err := db.B2cOrdWithCountNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += b2cTotal | |||||
return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId | ||||
case 10: | case 10: | ||||
// 累计自购消费金额 | // 累计自购消费金额 | ||||
var total float64 = 0 | var total float64 = 0 | ||||
var err error | var err error | ||||
if task.WithinDays <= 0 { | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { | |||||
state := []string{"3", "5"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"0", "1", "2", "3", "5"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"1", "2", "3", "5"} | |||||
} | |||||
total, err = db.OrderListPaidPriceByUIDByOrderType(engine, uid, 0, state) | |||||
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 | |||||
} | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
mallTotal, err := db.MallOrd(engine, uid, orderType, state) | |||||
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"}) { | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
o2oTotal, err := db.O2oOrd(engine, uid, 0, state) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId | |||||
} | |||||
total += o2oTotal | |||||
o2oTotal1, err := db.O2oOrdPayToMerchant(engine, uid, 0, "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"}) { | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
b2cTotal, err := db.B2cOrd(engine, uid, 0, state) | |||||
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() | |||||
state := []string{"3", "5"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"0", "1", "2", "3", "5"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"1", "2", "3", "5"} | |||||
} | |||||
total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, state, 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 | |||||
} | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
mallTotal, err := db.MallOrdByTime(engine, uid, orderType, state, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"), zhios_condition_statistics_utils.IntToStr(task.OrdState)) | |||||
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 | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, state, 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, "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 | |||||
state := []string{"3"} | |||||
if task.OrdState == 1 { //已付款 | |||||
state = []string{"1", "2", "3"} | |||||
} | |||||
if task.OrdState == 2 { //已完成 | |||||
state = []string{"3"} | |||||
} | |||||
//确认收货的才算 | |||||
b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, state, 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 | |||||
} | |||||
} | |||||
return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId | |||||
case 2: | |||||
// 累计已结算佣金 | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix() | |||||
etime := t.Unix() | |||||
mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()) | |||||
mallEtime := t | |||||
var sum float64 | |||||
if task.WithinDays <= 0 { | |||||
// 用户分佣的订单 | |||||
idAmountMap, err := db.OrderRelateListByState(engine, uid, "3,5") | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { | |||||
total, err = db.OrderListSumByUIDByOrderTypeByTimeNew(engine, uid, task) | |||||
if err != nil { | if err != nil { | ||||
return "", hasPay, payOrdId | return "", hasPay, payOrdId | ||||
} | } | ||||
for _, item := range *idAmountMap { | |||||
sum += item | |||||
} | |||||
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 | |||||
} | } | ||||
_, mallSum, err := db.MallOrderRelateListByState(engine, uid, 3) | |||||
secondTotal, err := db.MallOrdWithSumNew(engine, uid, orderType, task) | |||||
if err != nil { | if err != nil { | ||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | |||||
return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId | |||||
} | } | ||||
sum += mallSum | |||||
} else { | |||||
// 用户分佣的订单 | |||||
idAmountMap, err := db.OrderRelateListByTimeByState(engine, uid, "3,5", stime, etime) | |||||
total += secondTotal | |||||
} | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { | |||||
secondTotal, err := db.O2oOrdWithSumNew(engine, uid, task) | |||||
if err != nil { | if err != nil { | ||||
return "", hasPay, payOrdId | |||||
return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId | |||||
} | } | ||||
for _, item := range *idAmountMap { | |||||
sum += item | |||||
} | |||||
_, mallSum, err := db.MallOrderRelateListByTimeByState(engine, uid, 3, mallStime, mallEtime) | |||||
total += secondTotal | |||||
} | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { | |||||
secondTotal, err := db.B2cOrdWithSumNew(engine, uid, task) | |||||
if err != nil { | if err != nil { | ||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | |||||
return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId | |||||
} | } | ||||
sum += mallSum | |||||
total += secondTotal | |||||
} | } | ||||
return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId | |||||
case 2: | |||||
// 累计自购佣金 | |||||
sum, err := db.OrderRelateListByTimeByStateNew(engine, uid, task) | |||||
if err != nil { | |||||
return "", hasPay, payOrdId | |||||
} | |||||
mallSum, err := db.MallOrderRelateListByTimeByStateNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | |||||
} | |||||
sum += mallSum | |||||
o2oSum, err := db.O2oOrderRelateListByTimeByStateNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | |||||
} | |||||
sum += o2oSum | |||||
b2cSum, err := db.B2cOrderRelateListByTimeByStateNew(engine, uid, task) | |||||
if err != nil { | |||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | |||||
} | |||||
sum += b2cSum | |||||
return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId | ||||
case 3: | case 3: | ||||
// 累计直推人数 | // 累计直推人数 | ||||
@@ -708,6 +570,34 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, | |||||
sql := fmt.Sprintf(sqlTpl, condStr) | sql := fmt.Sprintf(sqlTpl, condStr) | ||||
fmt.Println(sql) | fmt.Println(sql) | ||||
results, err := db.QueryNativeString(engine, sql) | |||||
if err != nil { | |||||
return "", hasPay, payOrdId | |||||
} | |||||
count := "" | |||||
if len(results) > 0 { | |||||
count = zhios_condition_statistics_utils.AnyToString(results[0]["count"]) | |||||
} | |||||
return count, hasPay, payOrdId | |||||
case 21: | |||||
// 累计所有下级 | |||||
stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05") | |||||
etime := t.Format("2006-1-02 15:04:05") | |||||
sqlTpl := `SELECT count(*) as count | |||||
FROM user_relate as ur | |||||
LEFT JOIN user as u ON u.uid=ur.uid | |||||
WHERE %s;` | |||||
var condStr string | |||||
if task.WithinDays <= 0 { | |||||
condStr = fmt.Sprintf("ur.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid)) | |||||
} else { | |||||
condStr = fmt.Sprintf("ur.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) | |||||
fmt.Println(sql) | |||||
results, err := db.QueryNativeString(engine, sql) | results, err := db.QueryNativeString(engine, sql) | ||||
if err != nil { | if err != nil { | ||||
@@ -721,60 +611,22 @@ func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, | |||||
case 12: //累计团队消费金额 | case 12: //累计团队消费金额 | ||||
var total float64 = 0 | var total float64 = 0 | ||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) { | if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) { | ||||
sqlTpl := `SELECT SUM(ol.cost_price) AS amount | |||||
FROM mall_ord_list_relate olr | |||||
JOIN mall_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? | |||||
AND ol.state =3 and olr.level>0 %s; | |||||
` | |||||
str := "" | |||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) { | |||||
str += " and ol.order_type=" + zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd) | |||||
} | |||||
sqlTpl = fmt.Sprintf(sqlTpl, str) | |||||
result, err := db.QueryNativeString(engine, sqlTpl, uid, str) | |||||
if err == nil { | |||||
total += zhios_condition_statistics_utils.StrToFloat64(result[0]["amount"]) | |||||
} | |||||
secondTotal, _ := db.MallOrderTeamRelateListByTimeByStateNew(engine, uid, task) | |||||
total += secondTotal | |||||
} | } | ||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { | if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) { | ||||
o2oSqlTpl := `SELECT SUM(ol.cost_price) AS amount | |||||
FROM o2o_ord_list_relate olr | |||||
JOIN o2o_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? | |||||
AND ol.state =3 and olr.level>0; | |||||
` | |||||
o2oResult, err := db.QueryNativeString(engine, o2oSqlTpl, uid) | |||||
if err == nil { | |||||
total += zhios_condition_statistics_utils.StrToFloat64(o2oResult[0]["amount"]) | |||||
} | |||||
secondTotal, _ := db.O2oOrderTeamRelateListByTimeByStateNew(engine, uid, task) | |||||
total += secondTotal | |||||
} | } | ||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { | if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) { | ||||
b2cSqlTpl := `SELECT SUM(ol.cost_price) AS amount | |||||
FROM b2c_ord_list_relate olr | |||||
JOIN b2c_ord ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? | |||||
AND ol.state =3 and olr.level>0; | |||||
` | |||||
b2cResult, err := db.QueryNativeString(engine, b2cSqlTpl, uid) | |||||
if err == nil { | |||||
total += zhios_condition_statistics_utils.StrToFloat64(b2cResult[0]["amount"]) | |||||
} | |||||
secondTotal, _ := db.B2cOrderTeamRelateListByTimeByStateNew(engine, uid, task) | |||||
total += secondTotal | |||||
} | } | ||||
if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { | if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) { | ||||
guideSqlTpl := `SELECT SUM(ol.paid_price) AS amount | |||||
FROM ord_list_relate olr | |||||
JOIN ord_list ol ON olr.oid = ol.ord_id | |||||
WHERE olr.uid = ? | |||||
AND ol.state in(3,5) and olr.level>0; | |||||
` | |||||
guideResult, err := db.QueryNativeString(engine, guideSqlTpl, uid) | |||||
if err == nil { | |||||
total += zhios_condition_statistics_utils.StrToFloat64(guideResult[0]["amount"]) | |||||
} | |||||
secondTotal, _ := db.OrderTeamRelateListByTimeByStateNew(engine, uid, task) | |||||
total += secondTotal | |||||
} | } | ||||
return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId | return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId | ||||
case 13: | case 13: | ||||