智盟项目
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.

183 lines
5.0 KiB

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