|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "xorm.io/xorm"
- )
-
- func GetCoupon(eg *xorm.Engine, req map[string]string) *[]model.CommunityTeamCoupon {
- var data []model.CommunityTeamCoupon
- limit := 10
- start := (utils.StrToInt(req["p"]) - 1) * limit
- sess := eg.Where("uid=0 and num>0 and is_use=1").OrderBy("sort desc,id desc").Limit(limit, start)
- if req["name"] != "" {
- sess.And("name like ?", "%"+req["name"]+"%")
- }
- if req["start_time"] != "" {
- sess.And("created_time>=?", req["start_time"])
- }
- if req["end_time"] != "" {
- sess.And("created_time<=?", req["end_time"])
- }
- err := sess.Find(&data)
- if err != nil {
- return nil
- }
- return &data
- }
- func GetCouponById(eg *xorm.Engine, id string) *model.CommunityTeamCoupon {
- var data model.CommunityTeamCoupon
- get, err := eg.Where("id=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
|