From 05032d5e08337ba47fb9851284e29928e599f02c Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 3 Nov 2023 13:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=81=E4=BB=B6=E8=AF=86=E5=88=ABapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- card_pack/api.go | 79 +++++++++++++++++++++++++ db/offical/db_card_pack_num_list.go | 15 +++++ db/offical/model/card_pack_meal_list.go | 12 ++++ db/offical/model/card_pack_num_list.go | 8 +++ db/offical/model/card_pack_record.go | 28 +++++++++ 5 files changed, 142 insertions(+) create mode 100644 card_pack/api.go create mode 100644 db/offical/db_card_pack_num_list.go create mode 100644 db/offical/model/card_pack_meal_list.go create mode 100644 db/offical/model/card_pack_num_list.go create mode 100644 db/offical/model/card_pack_record.go diff --git a/card_pack/api.go b/card_pack/api.go new file mode 100644 index 0000000..7020e50 --- /dev/null +++ b/card_pack/api.go @@ -0,0 +1,79 @@ +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" + "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 + } + //存入记录 + ext := map[string]interface{}{ + "send": send, + "post": args, + } + var record = model.SmsRecord{ + 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 sms_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 +} diff --git a/db/offical/db_card_pack_num_list.go b/db/offical/db_card_pack_num_list.go new file mode 100644 index 0000000..be3435d --- /dev/null +++ b/db/offical/db_card_pack_num_list.go @@ -0,0 +1,15 @@ +package offical + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical/model" + "xorm.io/xorm" +) + +func GetCardPackNum(engine *xorm.Engine, uid interface{}) *model.CardPackNumList { + var data model.CardPackNumList + get, err := engine.Where("uid=? ", uid).Get(&data) + if get == false || err != nil { + return nil + } + return &data +} diff --git a/db/offical/model/card_pack_meal_list.go b/db/offical/model/card_pack_meal_list.go new file mode 100644 index 0000000..9d763da --- /dev/null +++ b/db/offical/model/card_pack_meal_list.go @@ -0,0 +1,12 @@ +package model + +type CardPackMealList struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Money float64 `json:"money" xorm:"default 0.00 comment('金额') DOUBLE(11,2)"` + Num int `json:"num" xorm:"default 0 comment('短信条数') INT(11)"` + Hide int `json:"hide" xorm:"default 0 comment('0否 1是') INT(1)"` + Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` + UpdateTime int `json:"update_time" xorm:"default 0 comment('修改时间') INT(11)"` + Time int `json:"time" xorm:"default 0 comment('创建时间') INT(11)"` + Type string `json:"type" xorm:"default '' comment('普通 putong 营销 yingxiao') VARCHAR(50)"` +} diff --git a/db/offical/model/card_pack_num_list.go b/db/offical/model/card_pack_num_list.go new file mode 100644 index 0000000..add3726 --- /dev/null +++ b/db/offical/model/card_pack_num_list.go @@ -0,0 +1,8 @@ +package model + +type CardPackNumList struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uid int `json:"uid" xorm:"default 0 comment('用户') INT(11)"` + Num int `json:"num" xorm:"default 0 comment('短信条数') INT(11)"` + Type string `json:"type" xorm:"default '' comment('普通 putong 营销 yingxiao') VARCHAR(50)"` +} diff --git a/db/offical/model/card_pack_record.go b/db/offical/model/card_pack_record.go new file mode 100644 index 0000000..03d2c02 --- /dev/null +++ b/db/offical/model/card_pack_record.go @@ -0,0 +1,28 @@ +package model + +import ( + "time" +) + +type CardPackRecord struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + OrdId string `json:"ord_id" xorm:"not null default '' comment('订单id') VARCHAR(100)"` + Uid int `json:"uid" xorm:"not null default 0 comment('主用户id') INT(11)"` + Phone int64 `json:"phone" xorm:"not null default 0 comment('主账号-手机号码') BIGINT(13)"` + Nickname string `json:"nickname" xorm:"not null default '' comment('主账号-昵称') VARCHAR(255)"` + Amount string `json:"amount" xorm:"not null default '0' comment('充值金额') VARCHAR(255)"` + CostPrice string `json:"cost_price" xorm:"not null default '0' comment('付费价格') VARCHAR(255)"` + Balance string `json:"balance" xorm:"not null default '0' comment('当前余额(充值完当前余额)') VARCHAR(255)"` + PayWay int `json:"pay_way" xorm:"not null default 1 comment('支付方式(1:支付宝 2:微信 3:余额)') TINYINT(1)"` + State int `json:"state" xorm:"not null default 0 comment('状态(0:待付款 1:已付款 2:付款失败)') TINYINT(2)"` + Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` + CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') DATETIME"` + UpdateAt time.Time `json:"update_at" xorm:"default CURRENT_TIMESTAMP comment('更新时间') DATETIME"` + TradeNo string `json:"trade_no" xorm:"not null default '' comment('支付平台(支付宝/微信)订单号') VARCHAR(100)"` + Type int `json:"type" xorm:"default 0 comment('0收入 1支出') INT(1)"` + OrdType string `json:"ord_type" xorm:"comment('订单类型') VARCHAR(255)"` + SubUid int `json:"sub_uid" xorm:"default 0 INT(11)"` + Fee string `json:"fee" xorm:"VARCHAR(255)"` + Ext string `json:"ext" xorm:"TEXT"` + SmsType string `json:"sms_type" xorm:"VARCHAR(255)"` +}