相关条件的统计
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.

db_order.go 3.2 KiB

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