|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "github.com/syyongx/php2go"
- "strings"
- "xorm.io/xorm"
- )
-
- func GetOrderById(eg *xorm.Engine, id string) *model.Order {
- var order model.Order
- get, err := eg.Where("oid=?", id).Get(&order)
- if get == false || err != nil {
- return nil
- }
- return &order
- }
- func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order {
- var order model.Order
- get, err := sess.Where("oid=?", id).Get(&order)
- if get == false || err != nil {
- return nil
- }
- return &order
- }
- func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods {
- var order model.OrderGoods
- get, err := eg.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
- if get == false || err != nil {
- return nil
- }
- return &order
- }
-
- func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
- var order model.OrderGoods
- get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
- if get == false || err != nil {
- return nil
- }
- return &order
- }
-
- func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
- var order []model.Order
- sess := eg.Where("1=1")
- if param["phone"] != "" {
- sess.And("buy_phone like ?", "%"+param["phone"]+"%")
- }
- if param["oid"] != "" {
- sess.And("oid like ?", "%"+param["oid"]+"%")
- }
- if param["state"] != "" {
- sess.And("state =?", param["state"])
- }
- if param["start_at"] != "" {
- sess.And("create_at >= ?", param["start_at"])
- }
- if param["end_at"] != "" {
- sess.And("create_at <= ?", param["end_at"])
- }
- if param["enterprise_name"] != "" {
- var enterprise []model.Enterprise
- eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
- oids := []int{-1}
- for _, v := range enterprise {
- oids = append(oids, v.Id)
- }
- sess.In("enterprise_id", oids)
- }
- size := utils.StrToInt(param["limit"])
- start := (utils.StrToInt(param["page"]) - 1) * size
- count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
-
- func GetOrderListExport(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
- var order []model.Order
- sess := eg.Where("1=1")
- if param["phone"] != "" {
- sess.And("buy_phone like ?", "%"+param["phone"]+"%")
- }
- if param["oid"] != "" {
- sess.And("oid like ?", "%"+param["oid"]+"%")
- }
- if param["state"] != "" {
- sess.And("state =?", param["state"])
- }
- if param["start_at"] != "" {
- sess.And("create_at >= ?", param["start_at"])
- }
- if param["end_at"] != "" {
- sess.And("create_at <= ?", param["end_at"])
- }
- if param["enterprise_name"] != "" {
- var enterprise []model.Enterprise
- eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
- oids := []int{-1}
- for _, v := range enterprise {
- oids = append(oids, v.Id)
- }
- sess.In("enterprise_id", oids)
- }
- count, err := sess.OrderBy("id desc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
-
- func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
- var order []model.Order
- sess := eg.Where("1=1")
- if param["phone"] != "" {
- sess.And("buy_phone like ?", "%"+param["phone"]+"%")
- }
- if param["oid"] != "" {
- sess.And("oid like ?", "%"+param["oid"]+"%")
- }
- if param["state"] != "" {
- sess.And("state =?", param["state"])
- }
- if param["ids"] != "" {
- sess.In("id", strings.Split(param["ids"], ","))
- }
- if param["enterprise_name"] != "" {
- var enterprise []model.Enterprise
- eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
- oids := []int{-1}
- for _, v := range enterprise {
- oids = append(oids, v.Id)
- }
- sess.In("enterprise_id", oids)
- }
- size := 10000
- start := (utils.StrToInt(param["page"]) - 1) * size
- if param["ids"] == "" {
- sess.Limit(size, start)
- }
- err := sess.OrderBy("id asc").Find(&order)
- if err != nil {
- return nil
- }
- return &order
- }
- func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
- var order []model.Order
- sess := eg.Where("state!=5")
-
- if param["keyword"] != "" {
- var data []model.Enterprise
- eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
- ids := []string{"-1"}
- for _, v := range data {
- ids = append(ids, utils.IntToStr(v.Id))
- }
- sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
- }
- if param["state"] != "" && param["state"] != "1" {
- sess.And("state =?", param["state"])
- }
- if param["state"] == "1" {
- sess.In("state", []string{"1", "2"})
- }
- size := utils.StrToInt(param["limit"])
- start := (utils.StrToInt(param["page"]) - 1) * size
- count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
|