NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package main

import (
"bufio"
"encoding/csv"
"os"
"fmt"
"io"
"strconv"
"strings"
"labix.org/v2/mgo/bson"
. "./service/worker"
"time"
)

var XuMapVoucher = map[int]int{}

var startDate int64 = 1515430800
var endDate int64 = 1515776399

type Voucher struct {
VoucherId int `json:"voucher_id" bson:"voucher_id"`
MinOrder int `json:"min_order" bson:"min_order"`
Code string `json:"code"`
Quantity int `json:"quantity"`
Remain int `json:"remain"`
Value int `json:"value"`
Xu int `json:"xu"`
ShopId int `json:"shop_id" bson:"shop_id"`
StartDate int64 `json:"start_date" bson:"start_date"`
EndDate int64 `json:"end_date" bson:"end_date"`
}

func main() {
var timeStart int64 = int64(time.Now().Unix())
var timeTotal int64 = 0
strStart := "cron started at " + time.Now().String() + "n"
fmt.Println(strStart)
// Load a TXT file.
f, err := os.Open("./public/files/voucher_sendo.csv")
if err != nil {
fmt.Println("Open files err: ", err)
return
}

// Create a new reader.
r := csv.NewReader(bufio.NewReader(f))

session, db, err1 := GetCollection("Mongo_Event")
if err1 != nil {
fmt.Println("can not connect to Mongo_Event, ", err1)
return
}
defer session.Close()

type voucher_config struct {
Key string
Value_voucher int
Total int
}

var voucherConfig []voucher_config

db.C("event_voucher_config").Find(bson.M{"key": "xu_voucher_sendo"}).All(&voucherConfig)

for _, voucher := range voucherConfig {
XuMapVoucher[voucher.Value_voucher] = voucher.Total
}

i := 0
for {
record, err2 := r.Read()
// Stop at EOF.
if err2 == io.EOF {
break
}

if (len(record) > 2 && len(record[0]) > 0) {
if i > 0 {
voucherId, _ := strconv.Atoi(record[0])
value, _ := strconv.Atoi(record[8])
quantity, _ := strconv.Atoi(record[9])
minOrder, _ := strconv.Atoi(record[7])
code := record[1]

voucher := Voucher{
VoucherId: voucherId,
Value: value,
Code: code,
Quantity: quantity,
Remain: quantity,
MinOrder: minOrder,
ShopId: 0,
Xu: XuMapVoucher[value],
StartDate: startDate,
EndDate: endDate,
}

fmt.Println("STT: ", i," voucherId: ", voucherId)
db.C("event_voucher_sendo_flat").Upsert(bson.M{"voucher_id": voucherId}, &voucher)
}
i ++
}
}

timeTotal = int64(time.Now().Unix()) - timeStart
fmt.Println("Total Time: ", timeTotal)
fmt.Println("cron done at " + time.Now().String() + "n")
}

func RemoveCHSA(text string) string {
s := strings.Replace(text, "CH", "PM", -1)
s = strings.Replace(s, "SA", "AM", -1)
return s
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.