package db import ( "applet/app/db/model" "applet/app/utils" "fmt" "time" "xorm.io/xorm" ) type PlayletSaleOrderDb struct { Db *xorm.Engine `json:"db"` } func (playletSaleOrderDb *PlayletSaleOrderDb) Set() { // set方法 playletSaleOrderDb.Db = ZhimengDb } func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderByOid(oid, ordType string) *model.PlayletSaleOrder { var data model.PlayletSaleOrder get, err := playletSaleOrderDb.Db.Where("oid=? and ord_type=?", oid, ordType).Get(&data) if get == false || err != nil { return nil } return &data } func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderUpdate(id int, data *model.PlayletSaleOrder) bool { get, err := playletSaleOrderDb.Db.Where("id=?", id).Update(data) if get == 0 || err != nil { return false } return true } func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderInsert(data *model.PlayletSaleOrder) bool { get, err := playletSaleOrderDb.Db.InsertOne(data) if get == 0 || err != nil { return false } return true } func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderSum(mid, status, timeType string) float64 { sess := playletSaleOrderDb.Db.Where("uid=?", mid) if status != "" { sess = sess.And("status=?", status) } if timeType != "" { timeRange := utils.GetTimeRange(timeType) sess = sess.And("create_time>=?", time.Unix(timeRange["start"], 0).Format("2006-01-02 15:04:05")) sess = sess.And("create_time=?", args["start_time"]) } if args["end_time"] != "" { sess = sess.And("update_time<=?", args["end_time"]) } if args["to_settle_time"] != "" { sess = sess.And("create_time=?", args["start_time"]) } if args["end_time"] != "" { sess = sess.And("create_time>=?", args["end_time"]) } sess = commWhere(sess, args) sort := "update_time desc,id desc" if args["sort"] != "" { sort = args["sort"] } count, err := sess.Limit(size, offet).OrderBy(sort).FindAndCount(&data) if count == 0 || err != nil { return nil, count } return &data, count } func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListWithCreateTime(args map[string]string) *[]model.PlayletSaleOrder { /*** p 页数 size 个数 start_time 开始时间 end_time 结束时间 ord_type 订单类型 video_type 视频类型 status 订单状态 settle_status 结算状态 oid 订单号 sort 排序 */ var data = make([]model.PlayletSaleOrder, 0) size := utils.StrToInt(args["size"]) offet := (utils.StrToInt(args["p"]) - 1) * size sess := playletSaleOrderDb.Db.Where("1=1") if args["start_time"] != "" { sess = sess.And("create_time>=?", args["start_time"]) } if args["end_time"] != "" { sess = sess.And("create_time>=?", args["end_time"]) } sess = commWhere(sess, args) sort := "update_time desc,id desc" if args["sort"] != "" { sort = args["sort"] } err := sess.Limit(size, offet).OrderBy(sort).Find(&data) if err != nil { return nil } return &data } func commWhere(sess *xorm.Session, args map[string]string) *xorm.Session { if args["mid"] != "" { sess = sess.And("uid=?", args["mid"]) } if args["oid"] != "" { sess = sess.And("oid LIKE ? or custom_oid LIKE ?", "%"+args["oid"]+"%", "%"+args["oid"]+"%") } if args["sub_uid"] != "" { sess = sess.And("sub_uid=?", args["sub_uid"]) } if args["ord_type"] != "" { sess = sess.And("ord_type=?", args["ord_type"]) } if args["video_type"] != "" { sess = sess.And("video_type=?", args["video_type"]) } if args["status"] != "" { sess = sess.And("status=?", args["status"]) } if args["settle_status"] != "" { if args["settle_status"] == "未结算" { sess = sess.And("settle_at=?", "0") } else { sess = sess.And("settle_at>?", "0") } } return sess }