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

198 lines
5.4 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. if args["is_commission"] == "1" {
  87. sess = sess.And("commission>?", 0)
  88. }
  89. err := sess.Limit(size, offet).OrderBy(sort).Find(&data)
  90. fmt.Println(err)
  91. fmt.Println(sess.LastSQL())
  92. return data
  93. }
  94. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListAndTotal(args map[string]string) (*[]model.PlayletSaleOrder, int64) {
  95. /***
  96. p 页数
  97. size 个数
  98. start_time 开始时间
  99. end_time 结束时间
  100. ord_type 订单类型
  101. video_type 视频类型
  102. status 订单状态
  103. settle_status 结算状态
  104. oid 订单号
  105. sort 排序
  106. */
  107. var data = make([]model.PlayletSaleOrder, 0)
  108. size := utils.StrToInt(args["size"])
  109. offet := (utils.StrToInt(args["p"]) - 1) * size
  110. sess := playletSaleOrderDb.Db.Where("1=1")
  111. if args["start_time"] != "" {
  112. sess = sess.And("create_time>=?", args["start_time"])
  113. }
  114. if args["end_time"] != "" {
  115. sess = sess.And("create_time>=?", args["end_time"])
  116. }
  117. sess = commWhere(sess, args)
  118. sort := "update_time desc,id desc"
  119. if args["sort"] != "" {
  120. sort = args["sort"]
  121. }
  122. count, err := sess.Limit(size, offet).OrderBy(sort).FindAndCount(&data)
  123. if count == 0 || err != nil {
  124. return nil, count
  125. }
  126. return &data, count
  127. }
  128. func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListWithCreateTime(args map[string]string) *[]model.PlayletSaleOrder {
  129. /***
  130. p 页数
  131. size 个数
  132. start_time 开始时间
  133. end_time 结束时间
  134. ord_type 订单类型
  135. video_type 视频类型
  136. status 订单状态
  137. settle_status 结算状态
  138. oid 订单号
  139. sort 排序
  140. */
  141. var data = make([]model.PlayletSaleOrder, 0)
  142. size := utils.StrToInt(args["size"])
  143. offet := (utils.StrToInt(args["p"]) - 1) * size
  144. sess := playletSaleOrderDb.Db.Where("1=1")
  145. if args["start_time"] != "" {
  146. sess = sess.And("create_time>=?", args["start_time"])
  147. }
  148. if args["end_time"] != "" {
  149. sess = sess.And("create_time>=?", args["end_time"])
  150. }
  151. sess = commWhere(sess, args)
  152. sort := "update_time desc,id desc"
  153. if args["sort"] != "" {
  154. sort = args["sort"]
  155. }
  156. err := sess.Limit(size, offet).OrderBy(sort).Find(&data)
  157. if err != nil {
  158. return nil
  159. }
  160. return &data
  161. }
  162. func commWhere(sess *xorm.Session, args map[string]string) *xorm.Session {
  163. if args["mid"] != "" {
  164. sess = sess.And("uid=?", args["mid"])
  165. }
  166. if args["oid"] != "" {
  167. sess = sess.And("oid LIKE ? or custom_oid LIKE ?", "%"+args["oid"]+"%", "%"+args["oid"]+"%")
  168. }
  169. if args["sub_uid"] != "" {
  170. sess = sess.And("sub_uid=?", args["sub_uid"])
  171. }
  172. if args["ord_type"] != "" {
  173. sess = sess.And("ord_type=?", args["ord_type"])
  174. }
  175. if args["video_type"] != "" {
  176. sess = sess.And("video_type=?", args["video_type"])
  177. }
  178. if args["status"] != "" {
  179. sess = sess.And("status=?", args["status"])
  180. }
  181. if args["settle_status"] != "" {
  182. if args["settle_status"] == "未结算" {
  183. sess = sess.And("settle_at=?", "0")
  184. } else {
  185. sess = sess.And("settle_at>?", "0")
  186. }
  187. }
  188. return sess
  189. }