相关条件的统计
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

db_order.go 10 KiB

1 år sedan
1 år sedan
2 år sedan
2 år sedan
1 år sedan
1 år sedan
5 månader sedan
5 månader sedan
1 år sedan
1 år sedan
5 månader sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
5 månader sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. "strings"
  8. "time"
  9. "xorm.io/xorm"
  10. )
  11. // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数
  12. func OrderListCountByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (int64, error) {
  13. 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",
  14. zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
  15. zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{
  16. "uid": uid,
  17. "buyType": buyType,
  18. "state": state,
  19. "stime": stime,
  20. "etime": etime,
  21. }))
  22. fmt.Println("============test订单数=================")
  23. fmt.Println(str)
  24. total, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at=0", uid, stime, etime).In("state", state).Count(&model.OrdList{})
  25. total1, _ := Db.Where("uid = ? AND confirm_at > ? AND confirm_at < ? and settle_at>0", uid, stime, etime).Count(&model.OrdList{})
  26. total3, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and confirm_at=0", uid, stime, etime).Count(&model.OrdList{})
  27. total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Count(&model.PrivilegeCardOrd{})
  28. total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Count(&model.RechargeOrder{})
  29. total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Count(&model.ExpressOrder{})
  30. fmt.Println(total)
  31. return total + total1 + total2 + total3 + total4 + total5, nil
  32. }
  33. // 查询用户某时间段内某状态的佣金(ord_id => amount)
  34. func OrderRelateListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) (*map[int64]float64, error) {
  35. var o []*model.OrdList
  36. var or []*model.OrdListRelate
  37. var idAmountMap = make(map[int64]float64)
  38. // 分佣明细数据
  39. err := Db.Where("`uid` = ?", uid).Find(&or)
  40. if err != nil {
  41. zhios_condition_statistics_logx.Error(err)
  42. return nil, err
  43. }
  44. if len(or) == 0 {
  45. return &idAmountMap, nil
  46. }
  47. var ids []int64
  48. for _, item := range or {
  49. ids = append(ids, item.Oid)
  50. }
  51. str := fmt.Sprintf("state in (%s) AND create_at >%s AND create_at < %s", state, startTime, endTime)
  52. fmt.Println("============test佣金数=================")
  53. fmt.Println(str)
  54. // 已结算的订单数据
  55. err = Db.In("ord_id", ids).In("state", state).Where(" confirm_at > ? AND confirm_at < ?", startTime, endTime).Find(&o)
  56. if err != nil {
  57. zhios_condition_statistics_logx.Error(err)
  58. return nil, err
  59. }
  60. if len(o) == 0 {
  61. return &idAmountMap, nil
  62. }
  63. // id => amount
  64. for _, item := range o {
  65. for _, i := range or {
  66. if item.OrdId == i.Oid {
  67. idAmountMap[i.Oid] = i.Amount
  68. }
  69. }
  70. }
  71. return &idAmountMap, nil
  72. }
  73. // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
  74. func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}, isSettle int) (float64, error) {
  75. 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",
  76. zhios_condition_statistics_utils.AnyToString(uid), buyType, state, stime, etime)
  77. fmt.Println("============test订单数=================")
  78. fmt.Println(str)
  79. var total float64 = 0
  80. if isSettle == 1 {
  81. total1, _ := Db.Where("uid = ? AND settle_at > ? AND settle_at < ? and settle_at>0", uid, stime, etime).Sum(&model.OrdList{}, "paid_price")
  82. total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  83. total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Sum(&model.RechargeOrder{}, "amount")
  84. total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Sum(&model.ExpressOrder{}, "money")
  85. total = total + total1 + total2 + total4 + total5
  86. } else {
  87. types := "confirm_at"
  88. serializeStr := zhios_condition_statistics_utils.SerializeStr(state)
  89. if strings.Contains(serializeStr, "3") {
  90. types = "pvd_settle_at"
  91. }
  92. if strings.Contains(serializeStr, "1") || strings.Contains(serializeStr, "2") {
  93. types = "confirm_at"
  94. }
  95. if strings.Contains(serializeStr, "0") {
  96. types = "create_at"
  97. }
  98. sqlStr := fmt.Sprintf(" %s >'%s' AND %s < '%s'", types, stime, types, etime)
  99. total, _ = Db.Where("uid = ? AND ? and settle_at=0", uid, sqlStr).In("state", state).Sum(&model.OrdList{}, "paid_price")
  100. total1, _ := Db.Where("uid = ? AND ? and settle_at>0", uid, sqlStr).Sum(&model.OrdList{}, "paid_price")
  101. total2, _ := Db.Where("uid = ? AND created_at > ? AND created_at < ? and state=?", uid, stime, etime, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  102. total4, _ := Db.Where("uid = ? AND create_time > ? AND create_time < ? and status=?", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05"), "已付款").Sum(&model.RechargeOrder{}, "amount")
  103. total5, _ := Db.In("status", []string{"待取件", "运输中", "已完成"}).Where("uid = ? AND create_time > ? AND create_time < ? ", uid, time.Unix(zhios_condition_statistics_utils.AnyToInt64(stime), 0).Format("2006-01-02 15:04:05"), time.Unix(zhios_condition_statistics_utils.AnyToInt64(etime), 0).Format("2006-01-02 15:04:05")).Sum(&model.ExpressOrder{}, "money")
  104. total = total + total1 + total2 + total4 + total5
  105. }
  106. fmt.Println(total)
  107. return total, nil
  108. }
  109. // OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数
  110. func OrderListCountByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}) (int64, error) {
  111. str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ",
  112. zhios_condition_statistics_utils.AnyToString(uid), buyType, state)
  113. zhios_condition_statistics_utils.FilePutContents("OrderListCountByUIDByOrderTypeByTime", zhios_condition_statistics_utils.SerializeStr(map[string]interface{}{
  114. "uid": uid,
  115. "buyType": buyType,
  116. "state": state,
  117. }))
  118. fmt.Println("============test订单数=================")
  119. fmt.Println(str)
  120. total, _ := Db.Where("uid = ? and settle_at=0", uid).In("state", state).Count(&model.OrdList{})
  121. total1, _ := Db.Where("uid = ? and settle_at>0", uid).Count(&model.OrdList{})
  122. total3, _ := Db.Where("uid = ? and confirm_at=0", uid).Count(&model.OrdList{})
  123. total2, _ := Db.Where("uid = ? and state=?", uid, 1).Count(&model.PrivilegeCardOrd{})
  124. total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Count(&model.RechargeOrder{})
  125. fmt.Println(total)
  126. return total + total1 + total2 + total3 + total4, nil
  127. }
  128. // 查询用户某时间段内某状态的佣金(ord_id => amount)
  129. func OrderRelateListByState(Db *xorm.Engine, uid, state interface{}) (*map[int64]float64, error) {
  130. var o []*model.OrdList
  131. var or []*model.OrdListRelate
  132. var idAmountMap = make(map[int64]float64)
  133. // 分佣明细数据
  134. err := Db.Where("`uid` = ?", uid).Find(&or)
  135. if err != nil {
  136. zhios_condition_statistics_logx.Error(err)
  137. return nil, err
  138. }
  139. if len(or) == 0 {
  140. return &idAmountMap, nil
  141. }
  142. var ids []int64
  143. for _, item := range or {
  144. ids = append(ids, item.Oid)
  145. }
  146. str := fmt.Sprintf("state in (%s) ", state)
  147. fmt.Println("============test佣金数=================")
  148. fmt.Println(str)
  149. // 已结算的订单数据
  150. err = Db.In("ord_id", ids).In("state", state).Find(&o)
  151. if err != nil {
  152. zhios_condition_statistics_logx.Error(err)
  153. return nil, err
  154. }
  155. if len(o) == 0 {
  156. return &idAmountMap, nil
  157. }
  158. // id => amount
  159. for _, item := range o {
  160. for _, i := range or {
  161. if item.OrdId == i.Oid {
  162. idAmountMap[i.Oid] = i.Amount
  163. }
  164. }
  165. }
  166. return &idAmountMap, nil
  167. }
  168. // OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额
  169. func OrderListPaidPriceByUIDByOrderType(Db *xorm.Engine, uid, buyType, state interface{}, isSettle int) (float64, error) {
  170. str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) ",
  171. zhios_condition_statistics_utils.AnyToString(uid), buyType, state)
  172. fmt.Println("============test订单数=================")
  173. fmt.Println(str)
  174. var total float64 = 0
  175. if isSettle == 1 {
  176. total, _ = Db.Where("uid = ? and settle_at>0", uid).Sum(&model.OrdList{}, "paid_price")
  177. total2, _ := Db.Where("uid = ? and state=?", uid, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  178. total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount")
  179. total = total + total2 + total4
  180. } else {
  181. total, _ = Db.Where("uid = ? and settle_at=0", uid).In("state", state).Sum(&model.OrdList{}, "paid_price")
  182. total1, _ := Db.Where("uid = ? and settle_at>0", uid).Sum(&model.OrdList{}, "paid_price")
  183. total2, _ := Db.Where("uid = ? and state=?", uid, 1).Sum(&model.PrivilegeCardOrd{}, "paid_price")
  184. total4, _ := Db.Where("uid = ? and status=?", uid, "已付款").Sum(&model.RechargeOrder{}, "amount")
  185. total = total + total1 + total2 + total4
  186. }
  187. fmt.Println(total)
  188. return total, nil
  189. }