|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/md"
- "applet/app/utils"
- "xorm.io/xorm"
- )
-
- func GetOrderByOid(eg *xorm.Engine, oid string) *model.CommunityTeamOrder {
- var data model.CommunityTeamOrder
- get, err := eg.Where("oid=?", oid).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func GetOrderEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrder {
- var data model.CommunityTeamOrder
- get, err := eg.Where("oid=?", oid).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func GetOrderPayEg(eg *xorm.Engine, oid string) *model.CommunityTeamPayOrder {
- var data model.CommunityTeamPayOrder
- get, err := eg.Where("oid=?", oid).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func GetOrderPay(sess *xorm.Session, oid string) *model.CommunityTeamPayOrder {
- var data model.CommunityTeamPayOrder
- get, err := sess.Where("oid=?", oid).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func GetOrder(sess *xorm.Session, oid string) *model.CommunityTeamOrder {
- var data model.CommunityTeamOrder
- get, err := sess.Where("oid=?", oid).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func GetOrderInfo(sess *xorm.Session, oid string) *[]model.CommunityTeamOrderInfo {
- var data []model.CommunityTeamOrderInfo
- err := sess.Where("oid=?", oid).Find(&data)
- if err != nil {
- return nil
- }
- return &data
- }
- func GetOrderInfoAllEg(eg *xorm.Engine, oid string) *[]model.CommunityTeamOrderInfo {
- var data []model.CommunityTeamOrderInfo
- err := eg.Where("oid=?", oid).Find(&data)
- if err != nil {
- return nil
- }
- return &data
- }
- func GetOrderInfoEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrderInfo {
- var data model.CommunityTeamOrderInfo
- get, err := eg.Where("oid=?", oid).Asc("id").Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
-
- func GetOrderList(eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeamOrder {
- var data []model.CommunityTeamOrder
- sess := eg.Where("1=1")
- if arg["uid"] != "" {
- sess.And("uid=?", arg["uid"])
- }
- if arg["state"] != "" {
- sess.And("state=?", arg["state"])
- }
- if arg["store_uid"] != "" {
- sess.And("store_uid=?", arg["store_uid"])
- }
- if arg["code"] != "" {
- sess.And("code=?", arg["code"])
- }
- limit := utils.StrToInt(arg["size"])
- start := (utils.StrToInt(arg["p"]) - 1) * limit
- err := sess.OrderBy("id desc").Limit(limit, start).Find(&data)
- if err != nil {
- return nil
- }
- return &data
- }
- func GetStoreOrderList(eg *xorm.Engine, req md.StoreOrder, parent_uid int) (*[]model.CommunityTeamOrder, int64, error) {
- var data []model.CommunityTeamOrder
- sess := eg.Where("1=1")
- if req.Oid != "" {
- sess.And("oid like ?", "%"+req.Oid+"%")
- }
- if req.StoreName != "" {
- var store []model.CommunityTeamStore
- eg.Where("name like ?", "%"+req.StoreName+"%").Find(&store)
- ids := []int{-1}
- for _, v := range store {
- ids = append(ids, v.Id)
- }
- sess.In("store_uid", ids)
- }
- if req.Phone != "" {
- var user []model.User
- eg.Where("phone like ?", "%"+req.Phone+"%").Find(&user)
- ids := []int{-1}
- for _, v := range user {
- ids = append(ids, v.Uid)
- }
- sess.In("uid", ids)
- }
- if req.Nickname != "" {
- var user []model.User
- eg.Where("nickname like ?", "%"+req.Nickname+"%").Find(&user)
- ids := []int{-1}
- for _, v := range user {
- ids = append(ids, v.Uid)
- }
- sess.In("uid", ids)
- }
- if req.StoreUid != "" {
- sess.And("store_uid=?", req.StoreUid)
- }
- if req.StoreType != "" {
- sess.And("store_type=?", req.StoreType)
- }
- if parent_uid > 0 {
- sess.And("parent_uid=?", parent_uid)
- }
-
- if req.StartTime != "" {
- sess.And("create_at>=?", req.StartTime)
- }
- if req.EndTime != "" {
- sess.And("create_at<=?", req.EndTime)
- }
- if req.ConfirmStartTime != "" {
- sess.And("confirm_at>=?", req.ConfirmStartTime)
- }
- if req.ConfirmEndTime != "" {
- sess.And("confirm_at<=?", req.ConfirmEndTime)
- }
- size := utils.StrToInt(req.Size)
- start := (utils.StrToInt(req.P) - 1) * size
- count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&data)
- if err != nil {
- return nil, 0, err
- }
- return &data, count, nil
- }
|