|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "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 GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods {
- var order model.OrderGoods
- get, err := eg.Where("id=?", 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 GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods {
- var order model.OrderGoods
- get, err := sess.Where("id=?", id).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["goods_title"] != "" {
- var orderGoods []model.OrderGoods
- eg.Where("goods_title like ?", "%"+param["goods_title"]+"%").Find(&orderGoods)
- oids := []int64{-1}
- for _, v := range orderGoods {
- oids = append(oids, v.Oid)
- }
- sess.In("oid", 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
- }
|