相关条件的统计
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 rivejä
3.5 KiB

  1. package db
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
  4. zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
  5. zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx"
  6. "fmt"
  7. "xorm.io/xorm"
  8. )
  9. // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数
  10. func OrderListCountByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (int64, error) {
  11. 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",
  12. zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
  13. fmt.Println("============test订单数=================")
  14. fmt.Println(str)
  15. total, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at=0", uid, stime, etime).In("state", state).Count(&model.OrdList{})
  16. total1, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at>0", uid, stime, etime).Count(&model.OrdList{})
  17. total2, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and state=?", uid, stime, etime, 1).Count(&model.PrivilegeCardOrd{})
  18. fmt.Println(total)
  19. return total + total1 + total2, nil
  20. }
  21. // 查询用户某时间段内某状态的佣金(ord_id => amount)
  22. func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) (*map[int64]float64, error) {
  23. var o []*model.OrdList
  24. var or []*model.OrdListRelate
  25. var idAmountMap = make(map[int64]float64)
  26. // 分佣明细数据
  27. err := Db.Where("`uid` = ?", uid).Find(&or)
  28. if err != nil {
  29. zhios_condition_statistics_logx.Error(err)
  30. return nil, err
  31. }
  32. if len(or) == 0 {
  33. return &idAmountMap, nil
  34. }
  35. var ids []int64
  36. for _, item := range or {
  37. ids = append(ids, item.Oid)
  38. }
  39. str := fmt.Sprintf("state in (%s) AND create_at >%s AND create_at < %s", state, startTime, endTime)
  40. fmt.Println("============test佣金数=================")
  41. fmt.Println(str)
  42. // 已结算的订单数据
  43. err = Db.In("ord_id", ids).In("state", state).Where(" create_at > ? AND create_at < ?", startTime, endTime).Find(&o)
  44. if err != nil {
  45. zhios_condition_statistics_logx.Error(err)
  46. return nil, err
  47. }
  48. if len(o) == 0 {
  49. return &idAmountMap, nil
  50. }
  51. // id => amount
  52. for _, item := range o {
  53. for _, i := range or {
  54. if item.OrdId == i.Oid {
  55. idAmountMap[i.Oid] = i.Amount
  56. }
  57. }
  58. }
  59. return &idAmountMap, nil
  60. }
  61. // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
  62. func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) {
  63. 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",
  64. zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
  65. fmt.Println("============test订单数=================")
  66. fmt.Println(str)
  67. 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")
  68. total1, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and settle_at>0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price")
  69. total2, _ := Db.Where("uid = ? AND create_at > ? AND create_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  70. fmt.Println(total)
  71. return total + total1 + total2, nil
  72. }