|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "time"
-
- "xorm.io/xorm"
- )
-
- // 获取对应等级未过期的付费订单
- func UserLevelOrderListByUIDByLevelTypeByExpire(Db *xorm.Engine, uid, levelID interface{}) ([]*model.UserLevelOrd, error) {
- var m []*model.UserLevelOrd
- err := Db.Where("uid = ? AND level_id = ? AND state = ? ", uid, levelID, 1).Desc("expire_at").Find(&m)
- if err != nil {
- return nil, err
- }
- return m, nil
- }
-
- // OrderListByPvdAndNoSettledWithPage is 查询未结算订单
- func UserLevelOrderListByUIDByNoSettledWithPage(Db *xorm.Engine, page int) ([]*model.UserLevelOrd, error) {
- perPage := 100
- startPlace := (page - 1) * perPage
- var o []*model.UserLevelOrd
-
- err := Db.Where("settle_at=?", 0).In("state", 1).Limit(perPage, startPlace).Find(&o)
- if err != nil {
- return nil, err
- }
- return o, nil
- }
-
- // 获取一个订单
- func UserLevelOrderById(Db *xorm.Engine, id string) (*model.UserLevelOrd, error) {
- var m *model.UserLevelOrd
- has, err := Db.Where("id = ? ", id).Get(&m)
- if err != nil || has == false {
- return nil, err
- }
- return m, nil
- }
-
- //UserLevelOrderListByUIDByLevelByDateTypeByExpire is 获取某用户某等级的订单,按照过期时间降序排序
- func UserLevelOrderListByUIDByLevelByDateTypeByExpire(Db *xorm.Engine, uid, levelID, t interface{}) ([]*model.UserLevelOrd, error) {
- var m []*model.UserLevelOrd
- err := Db.Where("uid = ? AND level_id = ? AND date_type = ? AND state = ? ", uid, levelID, t, 1).Desc("expire_at").Find(&m)
- if err != nil {
- return nil, err
- }
- return m, nil
- }
-
- //UserLevelOrderOneByUIDByLevelByDateTypeByExpire is 获取某用户某等级的订单,按照过期时间降序排序
- func UserLevelOrderOneByUIDByLevelByDateTypeByExpire(Db *xorm.Engine, uid, levelID interface{}) ([]*model.UserLevelOrd, error) {
- var m []*model.UserLevelOrd
- err := Db.Where("uid = ? AND level_id = ? and state = 1", uid, levelID).Desc("expire_at").Find(&m)
- if err != nil {
- return nil, err
- }
- return m, nil
- }
-
- //UserLevelOrdInsertOne is 插入一个 等级付费升级的订单
- func UserLevelOrdInsertOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) {
- affect, err := Db.InsertOne(order)
- if err != nil {
- return 0, err
- }
- return affect, nil
- }
-
- //UserLevelOrdUpdateOne is 更新付费升级订单
- func UserLevelOrdUpdateOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) {
- affect, err := Db.ID(order.Id).Update(order)
- if err != nil {
- return 0, err
- }
- return affect, nil
- }
-
- func UserLevelOrdUpdateOneWithSession(Db *xorm.Session, order *model.UserLevelOrd) (int64, error) {
- affect, err := Db.ID(order.Id).Update(order)
- if err != nil {
- return 0, err
- }
- return affect, nil
- }
-
- func UserLevelOrdFindOneByOid(Db *xorm.Engine, id int64) (*model.UserLevelOrd, error) {
- var m model.UserLevelOrd
- has, err := Db.Where("id=? AND state=?", id, 1).Get(&m)
-
- if err != nil || !has {
- return nil, err
- }
-
- return &m, nil
- }
-
- func UserLevelOrdFindByUidStateLevelAndNotExpire(Db *xorm.Engine, uid int, state int, level string) (*model.UserLevelOrd, error) {
- var m model.UserLevelOrd
- //过期时间还没到 或者是永久的订单
- if has, err := Db.Where("uid = ? AND level_id = ? AND state = ? AND (expire_at>= ? OR date_type=4)", uid, level, state, time.Now().Unix()).Get(&m); !has || err != nil {
- return nil, logx.Warn(err)
- }
- return &m, nil
- }
-
- // 查询订单状态
- func UserLevelOrdFindByID(Db *xorm.Engine, id int) (*model.UserLevelOrd, error) {
- var m model.UserLevelOrd
- if has, err := Db.Where("id = ?", id).Get(&m); !has || err != nil {
- return nil, logx.Warn(err)
-
- }
- return &m, nil
- }
-
- // 获取对应id订单
- func UserLevelOrdFindByIDs(Db *xorm.Engine, ids []int) ([]*model.UserLevelOrd, error) {
- var m []*model.UserLevelOrd
- err := Db.In("id", ids).Find(&m)
- if err != nil {
- return nil, err
- }
- return m, nil
- }
-
- //session事务修改订单
- func UserLvUpOrderUpdateWithSession(session *xorm.Session, ordId int64, order *model.UserLevelOrd, forceCols ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceCols != nil {
- affected, err = session.Where("id=?", ordId).Cols(forceCols...).Update(order)
- } else {
- affected, err = session.Where("id=?", ordId).Update(order)
- }
- if err != nil {
- return 0, logx.Warn(err)
- }
- return affected, nil
- }
|