|
- 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["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 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 (?) or oid like ?", php2go.Implode(",", ids), "%"+param["keyword"]+"%")
- }
- if param["state"] != "" {
- sess.And("state =?", param["state"])
- }
- size := utils.StrToInt(param["limit"])
- start := (utils.StrToInt(param["page"]) - 1) * size
- count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
|