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

2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{
  14. "uid": uid,
  15. "buyType": buyType,
  16. "state": state,
  17. "stime": stime,
  18. "etime": etime,
  19. }))
  20. fmt.Println("============test订单数=================")
  21. fmt.Println(str)
  22. total, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at=0", uid, stime, etime).In("state", state).Count(&model.OrdList{})
  23. total1, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at>0", uid, stime, etime).Count(&model.OrdList{})
  24. total3, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and confirm_at=0", uid, stime, etime).Count(&model.OrdList{})
  25. total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Count(&model.PrivilegeCardOrd{})
  26. fmt.Println(total)
  27. return total + total1 + total2 + total3, nil
  28. }
  29. // 查询用户某时间段内某状态的佣金(ord_id => amount)
  30. func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) (*map[int64]float64, error) {
  31. var o []*model.OrdList
  32. var or []*model.OrdListRelate
  33. var idAmountMap = make(map[int64]float64)
  34. // 分佣明细数据
  35. err := Db.Where("`uid` = ?", uid).Find(&or)
  36. if err != nil {
  37. zhios_condition_statistics_logx.Error(err)
  38. return nil, err
  39. }
  40. if len(or) == 0 {
  41. return &idAmountMap, nil
  42. }
  43. var ids []int64
  44. for _, item := range or {
  45. ids = append(ids, item.Oid)
  46. }
  47. str := fmt.Sprintf("state in (%s) AND create_at >%s AND create_at < %s", state, startTime, endTime)
  48. fmt.Println("============test佣金数=================")
  49. fmt.Println(str)
  50. // 已结算的订单数据
  51. err = Db.In("ord_id", ids).In("state", state).Where(" confirm_at > ? AND confirm_at < ?", startTime, endTime).Find(&o)
  52. if err != nil {
  53. zhios_condition_statistics_logx.Error(err)
  54. return nil, err
  55. }
  56. if len(o) == 0 {
  57. return &idAmountMap, nil
  58. }
  59. // id => amount
  60. for _, item := range o {
  61. for _, i := range or {
  62. if item.OrdId == i.Oid {
  63. idAmountMap[i.Oid] = i.Amount
  64. }
  65. }
  66. }
  67. return &idAmountMap, nil
  68. }
  69. // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
  70. func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) {
  71. 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",
  72. zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
  73. fmt.Println("============test订单数=================")
  74. fmt.Println(str)
  75. 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")
  76. total1, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at>0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price")
  77. total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  78. fmt.Println(total)
  79. return total + total1 + total2, nil
  80. }
  81. // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数
  82. func OrderListCountByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (int64, error) {
  83. str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ",
  84. zhios_condition_statistics_utils.AnyToString(uid), buyType, state)
  85. zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{
  86. "uid": uid,
  87. "buyType": buyType,
  88. "state": state,
  89. }))
  90. fmt.Println("============test订单数=================")
  91. fmt.Println(str)
  92. total, _ := Db.Where("uid = ? and settle_at=0", uid).In("state", state).Count(&model.OrdList{})
  93. total1, _ := Db.Where("uid = ? and settle_at>0", uid).Count(&model.OrdList{})
  94. total3, _ := Db.Where("uid = ? and confirm_at=0", uid).Count(&model.OrdList{})
  95. total2, _ := Db.Where("uid = ? and state=?", uid, 1).Count(&model.PrivilegeCardOrd{})
  96. fmt.Println(total)
  97. return total + total1 + total2 + total3, nil
  98. }
  99. // 查询用户某时间段内某状态的佣金(ord_id => amount)
  100. func OrderRelateListByState(Db *xorm.Engine, uid, state interface{}) (*map[int64]float64, error) {
  101. var o []*model.OrdList
  102. var or []*model.OrdListRelate
  103. var idAmountMap = make(map[int64]float64)
  104. // 分佣明细数据
  105. err := Db.Where("`uid` = ?", uid).Find(&or)
  106. if err != nil {
  107. zhios_condition_statistics_logx.Error(err)
  108. return nil, err
  109. }
  110. if len(or) == 0 {
  111. return &idAmountMap, nil
  112. }
  113. var ids []int64
  114. for _, item := range or {
  115. ids = append(ids, item.Oid)
  116. }
  117. str := fmt.Sprintf("state in (%s) ", state)
  118. fmt.Println("============test佣金数=================")
  119. fmt.Println(str)
  120. // 已结算的订单数据
  121. err = Db.In("ord_id", ids).In("state", state).Find(&o)
  122. if err != nil {
  123. zhios_condition_statistics_logx.Error(err)
  124. return nil, err
  125. }
  126. if len(o) == 0 {
  127. return &idAmountMap, nil
  128. }
  129. // id => amount
  130. for _, item := range o {
  131. for _, i := range or {
  132. if item.OrdId == i.Oid {
  133. idAmountMap[i.Oid] = i.Amount
  134. }
  135. }
  136. }
  137. return &idAmountMap, nil
  138. }
  139. // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
  140. func OrderListPaidPriceByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (float64, error) {
  141. str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ",
  142. zhios_condition_statistics_utils.AnyToString(uid), buyType, state)
  143. fmt.Println("============test订单数=================")
  144. fmt.Println(str)
  145. total, _ := Db.Where("uid = ? and settle_at=0", uid).In("state", state).Sum(&model.OrdList{}, "paid_price")
  146. total1, _ := Db.Where("uid = ? and settle_at>0", uid).Sum(&model.OrdList{}, "paid_price")
  147. total2, _ := Db.Where("uid = ? and state=?", uid, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  148. fmt.Println(total)
  149. return total + total1 + total2, nil
  150. }