|
- package card_pack
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical/model"
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "errors"
- "fmt"
- "github.com/tidwall/gjson"
- "time"
- "xorm.io/xorm"
- )
-
- //数量
- func CardPackNumGetNum(engine *xorm.Engine, uid interface{}) int {
- numData := offical.GetCardPackNum(engine, uid)
- num := 0
- if numData != nil {
- num = numData.Num
- }
- if num < 0 {
- num = 0
- }
- return num
- }
-
- //识别
- func CardPackSend(engine *xorm.Engine, args map[string]interface{}) (string, error) {
- num := CardPackNumGetNum(engine, args["uid"])
- if num < 1 {
- return "", errors.New("数量不足")
- }
- send, err2 := Send(args["method"].(string), args["appcode"].(string), args["body"].(string))
- if err2 != nil {
- return "", err2
- }
- if gjson.Get(send, "success").Bool() == false {
- return "", errors.New("识别失败")
- }
- //存入记录
- ext := map[string]interface{}{
- "send": send,
- "post": args,
- }
- var record = model.CardPackRecord{
- OrdId: "",
- Uid: int(zhios_third_party_utils.AnyToInt64(args["uid"])),
- Amount: "1",
- CostPrice: "",
- Balance: zhios_third_party_utils.IntToStr(num - 1),
- PayWay: 0,
- State: 1,
- Memo: args["name"].(string),
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- TradeNo: "",
- Type: 1,
- OrdType: "buy",
- Fee: "",
- Ext: zhios_third_party_utils.SerializeStr(ext),
- }
- engine.InsertOne(&record)
- sql := `UPDATE card_pack_num_list set num=num-%d WHERE uid=%s ;`
- sql = fmt.Sprintf(sql, 1, args["uid"])
- fmt.Println(sql)
- nativeString, err := db.QueryNativeString(engine, sql)
- fmt.Println(nativeString)
- fmt.Println(err)
- return send, nil
- }
- func Send(method, appcode, body string) (string, error) {
- host := "https://cardpack.market.alicloudapi.com"
- headers := map[string]string{
- "Authorization": "APPCODE " + appcode,
- "Content-Type": "application/json; charset=UTF-8",
- }
- url := host + method
- post, err := zhios_third_party_utils.CurlPost(url, body, headers)
- fmt.Println(string(post))
- fmt.Println(err)
- return string(post), err
- }
|