|
- 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["date"] != "" {
- param["date"] = strings.ReplaceAll(param["date"], "-", "")
- sess.And("date = ?", param["date"])
- }
- 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["start_at"] != "" {
- sess.And("create_at >= ?", param["start_at"])
- }
- if param["end_at"] != "" {
- sess.And("create_at <= ?", param["end_at"])
- }
- if param["date"] != "" {
- param["date"] = strings.ReplaceAll(param["date"], "-", "")
- sess.And("date = ?", param["date"])
- }
- 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)
- }
- 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
- }
|