智盟项目
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

194 righe
5.3 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "fmt"
  6. "time"
  7. "xorm.io/xorm"
  8. )
  9. type PlayletSaleOrderDb struct {
  10. Db *xorm.Engine `json:"db"`
  11. }
  12. func (playletSaleOrderDb *PlayletSaleOrderDb) Set() { // set方法
  13. playletSaleOrderDb.Db = ZhimengDb
  14. }
  15. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderByOid(oid, ordType string) *model.PlayletSaleOrder {
  16. var data model.PlayletSaleOrder
  17. get, err := playletSaleOrderDb.Db.Where("oid=? and ord_type=?", oid, ordType).Get(&data)
  18. if get == false || err != nil {
  19. return nil
  20. }
  21. return &data
  22. }
  23. func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderUpdate(id int, data *model.PlayletSaleOrder) bool {
  24. get, err := playletSaleOrderDb.Db.Where("id=?", id).AllCols().Update(data)
  25. if get == 0 || err != nil {
  26. return false
  27. }
  28. return true
  29. }
  30. func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderInsert(data *model.PlayletSaleOrder) bool {
  31. get, err := playletSaleOrderDb.Db.InsertOne(data)
  32. if get == 0 || err != nil {
  33. return false
  34. }
  35. return true
  36. }
  37. func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderSum(mid, status, timeType string) float64 {
  38. sess := playletSaleOrderDb.Db.Where("uid=?", mid)
  39. if status != "" {
  40. sess = sess.And("status=?", status)
  41. }
  42. if timeType != "" {
  43. timeRange := utils.GetTimeRange(timeType)
  44. sess = sess.And("create_time>=?", time.Unix(timeRange["start"], 0).Format("2006-01-02 15:04:05"))
  45. sess = sess.And("create_time<?", time.Unix(timeRange["end"], 0).Format("2006-01-02 15:04:05"))
  46. }
  47. sum, _ := sess.Sum(&model.PlayletSaleOrder{}, "commission")
  48. return sum
  49. }
  50. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderList(args map[string]string) []model.PlayletSaleOrder {
  51. /***
  52. p 页数
  53. size 个数
  54. start_time 开始时间
  55. end_time 结束时间
  56. ord_type 订单类型
  57. video_type 视频类型
  58. status 订单状态
  59. settle_status 结算状态
  60. oid 订单号
  61. sort 排序
  62. is_to_settle 智盟结算
  63. to_settle_time 结算上月时间
  64. */
  65. var data = make([]model.PlayletSaleOrder, 0)
  66. size := utils.StrToInt(args["size"])
  67. offet := (utils.StrToInt(args["p"]) - 1) * size
  68. sess := playletSaleOrderDb.Db.Where("1=1")
  69. if args["start_time"] != "" {
  70. sess = sess.And("update_time>=?", args["start_time"])
  71. }
  72. if args["end_time"] != "" {
  73. sess = sess.And("update_time<=?", args["end_time"])
  74. }
  75. if args["to_settle_time"] != "" {
  76. sess = sess.And("create_time<?", args["to_settle_time"])
  77. }
  78. sess = commWhere(sess, args)
  79. sort := "update_time desc,id desc"
  80. if args["sort"] != "" {
  81. sort = args["sort"]
  82. }
  83. if args["is_to_settle"] == "1" {
  84. sess = sess.And("settle_time=?", 0)
  85. }
  86. sess.Limit(size, offet).OrderBy(sort).Find(&data)
  87. fmt.Println(sess.LastSQL())
  88. return data
  89. }
  90. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListAndTotal(args map[string]string) (*[]model.PlayletSaleOrder, int64) {
  91. /***
  92. p 页数
  93. size 个数
  94. start_time 开始时间
  95. end_time 结束时间
  96. ord_type 订单类型
  97. video_type 视频类型
  98. status 订单状态
  99. settle_status 结算状态
  100. oid 订单号
  101. sort 排序
  102. */
  103. var data = make([]model.PlayletSaleOrder, 0)
  104. size := utils.StrToInt(args["size"])
  105. offet := (utils.StrToInt(args["p"]) - 1) * size
  106. sess := playletSaleOrderDb.Db.Where("1=1")
  107. if args["start_time"] != "" {
  108. sess = sess.And("create_time>=?", args["start_time"])
  109. }
  110. if args["end_time"] != "" {
  111. sess = sess.And("create_time>=?", args["end_time"])
  112. }
  113. sess = commWhere(sess, args)
  114. sort := "update_time desc,id desc"
  115. if args["sort"] != "" {
  116. sort = args["sort"]
  117. }
  118. count, err := sess.Limit(size, offet).OrderBy(sort).FindAndCount(&data)
  119. if count == 0 || err != nil {
  120. return nil, count
  121. }
  122. return &data, count
  123. }
  124. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListWithCreateTime(args map[string]string) *[]model.PlayletSaleOrder {
  125. /***
  126. p 页数
  127. size 个数
  128. start_time 开始时间
  129. end_time 结束时间
  130. ord_type 订单类型
  131. video_type 视频类型
  132. status 订单状态
  133. settle_status 结算状态
  134. oid 订单号
  135. sort 排序
  136. */
  137. var data = make([]model.PlayletSaleOrder, 0)
  138. size := utils.StrToInt(args["size"])
  139. offet := (utils.StrToInt(args["p"]) - 1) * size
  140. sess := playletSaleOrderDb.Db.Where("1=1")
  141. if args["start_time"] != "" {
  142. sess = sess.And("create_time>=?", args["start_time"])
  143. }
  144. if args["end_time"] != "" {
  145. sess = sess.And("create_time>=?", args["end_time"])
  146. }
  147. sess = commWhere(sess, args)
  148. sort := "update_time desc,id desc"
  149. if args["sort"] != "" {
  150. sort = args["sort"]
  151. }
  152. err := sess.Limit(size, offet).OrderBy(sort).Find(&data)
  153. if err != nil {
  154. return nil
  155. }
  156. return &data
  157. }
  158. func commWhere(sess *xorm.Session, args map[string]string) *xorm.Session {
  159. if args["mid"] != "" {
  160. sess = sess.And("uid=?", args["mid"])
  161. }
  162. if args["oid"] != "" {
  163. sess = sess.And("oid LIKE ? or custom_oid LIKE ?", "%"+args["oid"]+"%", "%"+args["oid"]+"%")
  164. }
  165. if args["sub_uid"] != "" {
  166. sess = sess.And("sub_uid=?", args["sub_uid"])
  167. }
  168. if args["ord_type"] != "" {
  169. sess = sess.And("ord_type=?", args["ord_type"])
  170. }
  171. if args["video_type"] != "" {
  172. sess = sess.And("video_type=?", args["video_type"])
  173. }
  174. if args["status"] != "" {
  175. sess = sess.And("status=?", args["status"])
  176. }
  177. if args["settle_status"] != "" {
  178. if args["settle_status"] == "未结算" {
  179. sess = sess.And("settle_at=?", "0")
  180. } else {
  181. sess = sess.And("settle_at>?", "0")
  182. }
  183. }
  184. return sess
  185. }