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

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