|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "fmt"
- "strings"
- )
-
- func GetLifeOrderByOne(oid, mid, types string) *model.LifeOrder {
- var data model.LifeOrder
- get, err := ZhimengDb.Where("uid=? and pvd_oid=? and pvd=?", mid, oid, types).Get(&data)
- if get == false || err != nil {
- fmt.Println(err)
- return nil
- }
- return &data
- }
- func GetLifeOrderList(args map[string]string) []model.LifeOrder {
- /***
- p 页数
- size 个数
- start_time 开始时间
- end_time 结束时间
- ord_type 订单类型
- video_type 视频类型
- status 订单状态
- settle_status 结算状态
- oid 订单号
- sort 排序
- is_to_settle 智盟结算
- to_settle_time 结算上月时间
- */
- var data = make([]model.LifeOrder, 0)
- size := utils.StrToInt(args["size"])
- offet := (utils.StrToInt(args["p"]) - 1) * size
- sess := ZhimengDb.Where("1=1")
- if args["start_time"] != "" {
- sess = sess.And("update_time>=?", args["start_time"])
- }
- if args["end_time"] != "" {
- sess = sess.And("update_time<=?", args["end_time"])
- }
- if args["type"] != "" {
- sess = sess.And("pvd=?", args["type"])
- }
- if args["uid"] != "" {
- sess = sess.And("uid=?", args["uid"])
- }
- if args["pvd"] != "" {
- sess = sess.In("pvd", strings.Split(args["pvd"], ","))
- }
- if args["status"] != "" {
- sess = sess.In("status", strings.Split(args["status"], ","))
- }
- if args["to_settle_time"] != "" {
- if args["is_to_settle"] == "1" {
- sess = sess.And("platform_settle_time<?", args["to_settle_time"])
- }
- if args["is_to_settle"] == "2" {
- sess = sess.And("create_time<?", args["to_settle_time"])
- }
- }
- sort := "update_time desc,id desc"
- if args["sort"] != "" {
- sort = args["sort"]
- }
- if args["is_to_settle"] == "1" {
- sess = sess.And("settle_time=?", 0)
- }
- if args["is_commission"] == "1" {
- sess = sess.And("real_commission>?", 0)
- }
- err := sess.Limit(size, offet).OrderBy(sort).Find(&data)
- fmt.Println(err)
- fmt.Println(sess.LastSQL())
- return data
- }
- func GetLifeOrderListTotal(args map[string]string) ([]model.LifeOrder, int64) {
- var data = make([]model.LifeOrder, 0)
- size := utils.StrToInt(args["size"])
- offet := (utils.StrToInt(args["p"]) - 1) * size
- sess := ZhimengDb.Where("1=1")
- if args["start_time"] != "" {
- sess = sess.And("create_time>=?", utils.TimeStdParseUnix(args["start_time"]))
- }
- if args["end_time"] != "" {
- sess = sess.And("create_time<=?", utils.TimeStdParseUnix(args["end_time"]))
- }
- if args["type"] != "" {
- sess = sess.And("pvd=?", args["type"])
- }
- if args["settle_type"] == "0" {
- sess = sess.And("settle_time=?", 0)
- }
- if args["settle_type"] == "1" {
- sess = sess.And("settle_time>?", 0)
- }
- if args["uid"] != "" {
- sess = sess.And("uid=?", args["uid"])
- }
- if args["oid"] != "" {
- sess = sess.And("pvd_oid like ?", "%"+args["oid"]+"%")
- }
- if args["zuid"] != "" {
- sess = sess.And("station_uid=?", args["zuid"])
- }
- if args["status"] != "" {
- sess = sess.And("status=?", args["status"])
- }
- if args["source"] != "" {
- sess = sess.And("pvd=?", args["source"])
- }
- sort := "create_time desc,id desc"
- if args["sort"] != "" {
- sort = args["sort"]
- }
-
- total, err := sess.Limit(size, offet).OrderBy(sort).FindAndCount(&data)
- fmt.Println(err)
- fmt.Println(sess.LastSQL())
- return data, total
- }
|