You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.1 KiB
61 lines
2.1 KiB
package internal |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"github.com/gogf/gf/v2/os/gtime" |
|
"go.mongodb.org/mongo-driver/bson" |
|
"go.mongodb.org/mongo-driver/bson/primitive" |
|
"log" |
|
"strconv" |
|
) |
|
|
|
func GetMonthlyLottery(ctx context.Context, date string) (all []map[string]interface{}, err error) { |
|
filter := bson.M{} |
|
filter["Date"] = bson.M{"$regex": primitive.Regex{Pattern: ".*" + date + ".*", Options: "i"}} |
|
//log.Print("MonthlyLottery", filter) |
|
err = MongoDatabaseList["0"].Collection("MonthlyLottery").Find(ctx, filter).All(&all) |
|
for _, v := range all { |
|
v["StringId"] = fmt.Sprint(v["_id"]) |
|
} |
|
if err != nil { |
|
log.Print("MonthlyLottery db err: ", err) |
|
return |
|
} |
|
return all, err |
|
} |
|
|
|
func UpdateMonthlyLottery(ctx context.Context, data map[string]interface{}) (err error) { |
|
filter := bson.M{} |
|
filter["Date"] = data["Date"] |
|
//log.Print("MonthlyLottery: %s, %s, %s", filter, data) |
|
err = MongoDatabaseList["0"].Collection("MonthlyLottery").UpdateOne(ctx, filter, bson.M{"$set": data}) |
|
return |
|
} |
|
|
|
func InsertMonthlyLottery(ctx context.Context, data map[string]interface{}) (err error) { |
|
query := bson.M{"_t": "MonthlyLottery"} |
|
filter := bson.M{} |
|
if data["Date"] != "" { |
|
query["Date"] = bson.M{"$regex": primitive.Regex{Pattern: ".*" + fmt.Sprint(data["Date"]) + ".*", Options: "i"}} |
|
filter = bson.M{"BeginTime": 1, "EndTime": 1, "_id": 1} |
|
} |
|
log.Print("GetPropExchange", query, filter) |
|
|
|
all := map[string]interface{}{} |
|
err = MongoDatabaseList["0"].Collection("MonthlyLottery").Find(ctx, query).Select(filter).One(&all) |
|
if all != nil && all["_id"] != nil { |
|
filter := bson.M{"_t": "MonthlyLottery"} |
|
filter["_id"], _ = strconv.ParseInt(fmt.Sprint(all["_id"]), 10, 64) |
|
log.Print("UpdatePropExchange: %s, %s, %s", filter, data) |
|
err = MongoDatabaseList["0"].Collection("MonthlyLottery").UpdateOne(ctx, filter, bson.M{"$set": data}) |
|
return |
|
} |
|
|
|
data["_id"] = gtime.TimestampNano() |
|
data["_t"] = "MonthlyLottery" |
|
//log.Print("MonthlyLottery", data) |
|
ss, err := MongoDatabaseList["0"].Collection("MonthlyLottery").InsertOne(ctx, data) |
|
log.Print("InsertMonthlyLottery %v", ss) |
|
return |
|
}
|
|
|