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

2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. }