diff --git a/leanwork_request.go b/leanwork_request.go index 5968c9b..c7e833c 100644 --- a/leanwork_request.go +++ b/leanwork_request.go @@ -1,5 +1,11 @@ package main +import ( + "errors" + + "github.com/go-sql-driver/mysql" +) + type LeanworkRequest struct { Id int64 PickupUrl string @@ -11,5 +17,38 @@ type LeanworkRequest struct { CustomerId string Sign string Valid bool + Ts mysql.NullTime Ip4 uint32 + Ip4Location string +} + +// +func lrIsIdMatchSign(id string, sign string) bool { + _, err := getRequestRowByIdAndSign(id, sign) + return err == nil +} + +func getRequestRowByIdAndSign(id string, sign string) (row LeanworkRequest, err error) { + //retrieve form DB + row = LeanworkRequest{} + db.conn(Config) + selDB, err := db.h.Query("SELECT * FROM request WHERE id=? and sign=?", id, sign) + if err != nil { + return + } + count := 0 + for selDB.Next() { + err = selDB.Scan(&row.Id, &row.PickupUrl, &row.ReceiveUrl, &row.SignType, + &row.OrderNo, &row.OrderAmount, &row.OrderCurrency, &row.CustomerId, + &row.Sign, &row.Valid, &row.Ts, &row.Ip4, &row.Ip4Location) + if err != nil { + return + } + count++ + } + + if count <= 0 { + err = errors.New("no record found by the given id (" + id + ") and sign(" + sign + ")") + } + return }