|
- package db
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
- zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
- zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx"
- "fmt"
- "xorm.io/xorm"
- )
-
- // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数
- func OrderListCountByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (int64, error) {
- str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s",
- zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
- fmt.Println("============test订单数=================")
- fmt.Println(str)
- total, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at=0", uid, stime, etime).In("state", state).Count(&model.OrdList{})
- total1, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at>0", uid, stime, etime).Count(&model.OrdList{})
- total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Count(&model.PrivilegeCardOrd{})
-
- fmt.Println(total)
-
- return total + total1 + total2, nil
- }
-
- // 查询用户某时间段内某状态的佣金(ord_id => amount)
- func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) (*map[int64]float64, error) {
- var o []*model.OrdList
- var or []*model.OrdListRelate
- var idAmountMap = make(map[int64]float64)
- // 分佣明细数据
- err := Db.Where("`uid` = ?", uid).Find(&or)
- if err != nil {
- zhios_condition_statistics_logx.Error(err)
- return nil, err
- }
- if len(or) == 0 {
- return &idAmountMap, nil
- }
- var ids []int64
- for _, item := range or {
- ids = append(ids, item.Oid)
- }
- str := fmt.Sprintf("state in (%s) AND create_at >%s AND create_at < %s", state, startTime, endTime)
- fmt.Println("============test佣金数=================")
- fmt.Println(str)
- // 已结算的订单数据
- err = Db.In("ord_id", ids).In("state", state).Where(" create_at > ? AND create_at < ?", startTime, endTime).Find(&o)
- if err != nil {
- zhios_condition_statistics_logx.Error(err)
- return nil, err
- }
- if len(o) == 0 {
- return &idAmountMap, nil
- }
-
- // id => amount
- for _, item := range o {
- for _, i := range or {
- if item.OrdId == i.Oid {
- idAmountMap[i.Oid] = i.Amount
- }
- }
- }
-
- return &idAmountMap, nil
- }
-
- // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
- func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) {
-
- str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s",
- zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
- fmt.Println("============test订单数=================")
- fmt.Println(str)
- total, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at=0", uid, stime, etime).In("state", state).Sum(&model.OrdList{}, "paid_price")
- total1, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at>0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price")
- total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
- fmt.Println(total)
-
- return total + total1 + total2, nil
- }
|