63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package console
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/qit-team/snow-core/command"
|
|
"qteam/app/constants/errorcode"
|
|
"qteam/app/models/ordersmodel"
|
|
"qteam/app/third/youchu"
|
|
"qteam/app/utils"
|
|
"qteam/config"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func RegisterCommand(c *command.Command) {
|
|
c.AddFunc("test", test)
|
|
}
|
|
|
|
func ClearUnpayOrder() {
|
|
var expire = time.Now().Add(-15 * time.Minute).Format(time.DateTime)
|
|
var orders []ordersmodel.Orders
|
|
ordersmodel.GetInstance().GetDb().Where("state = 1 and create_time <= ?", expire).Select("id,product_id").Find(&orders)
|
|
var ids = make([]int, 0)
|
|
var prodIds = make([]string, 0)
|
|
for _, v := range orders {
|
|
ids = append(ids, v.Id)
|
|
prodIds = append(prodIds, strconv.Itoa(v.ProductId))
|
|
}
|
|
if len(prodIds) > 0 {
|
|
var session = ordersmodel.GetInstance().GetDb().NewSession()
|
|
session.Begin()
|
|
_, err := session.In("id", ids).Update(&ordersmodel.Orders{State: 9})
|
|
if err == nil {
|
|
_, err = session.Exec("update Products set stock=stock+1 where id in (" + strings.Join(prodIds, ",") + ")")
|
|
if err == nil {
|
|
session.Commit()
|
|
} else {
|
|
session.Rollback()
|
|
}
|
|
} else {
|
|
session.Rollback()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func DownLoadAccountBill() {
|
|
utils.Log(nil, "down load bill")
|
|
client := youchu.NewYouChuClient(config.GetConf().YouChu)
|
|
code, rs := client.AccountBillQuery()
|
|
fmt.Println(rs)
|
|
if code == errorcode.Success {
|
|
if len(rs.Files) > 0 {
|
|
for k, v := range rs.Files {
|
|
fileId := v["fileId"].(string)
|
|
client.AccountBillDownload(fileId, k)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|