From 95cc3d2233241abc540bfb10eee45aca93814f0d Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Thu, 21 May 2020 11:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/author.go | 8 ++++---- controllers/client/live.go | 16 +++++++--------- controllers/client/lottery.go | 2 +- controllers/client/shake_red_envelope.go | 11 ++++------- controllers/pc/lottery_draw.go | 2 +- log/hdzj.log | 4 ++++ models/lottery_draw_record.go | 5 ----- models/shake_red_envelope_record.go | 8 ++++---- services/pay/const.go | 1 + services/pay/order.go | 2 +- services/pay/transfer.go | 5 ++--- test/pay_test.go | 3 ++- 12 files changed, 31 insertions(+), 36 deletions(-) diff --git a/controllers/author.go b/controllers/author.go index 3e0f37d..83fabc6 100644 --- a/controllers/author.go +++ b/controllers/author.go @@ -19,11 +19,11 @@ func (t *AuthorCtl) Prepare() { if skip == 1 { t.claims = &jwt.Claims{ AccountType: "customer", - AccountId: 16, - CustomerId: 16, + AccountId: 1, + CustomerId: 1, CustomerPid: 0, - ActivityId: 101, - AreaId: 101, + ActivityId: 1, + AreaId: 1, StandardClaims: jwt2.StandardClaims{}, } return diff --git a/controllers/client/live.go b/controllers/client/live.go index 90b5512..dd8500d 100644 --- a/controllers/client/live.go +++ b/controllers/client/live.go @@ -10,7 +10,6 @@ import ( "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" - "strings" "time" ) @@ -195,16 +194,15 @@ func (t *LiveCtl) GetLiveRedPack() { // 乐观锁 ==> 防止并发 record.UserId = user.Id record.IsDraw = 0 - row, err := record.UpdateById(record.Id, "version, user_id, is_draw") + row, err := models.Update(record.Id, record, "user_id", "is_draw") t.CheckErr(err) t.Assert(row == 1, code.MSG_SHAKERB_RECORD_NOT_HIT, "红包被领完了") - addr := strings.Split(t.Request.OriginRequest.RemoteAddr, ":") - result, err := pay_service.SendRedPack("欧轩互动", user.Openid, rule.Prompt, addr[0], "直播抢红包活动", - "抢的多,赚得多", int(record.Amount*100), 1, 2) - t.CheckErr(err) - record.MchBillno = result.MchBillno - record.Version += 1 - record.UpdateById(record.Id, "version, mch_billno") + //result, err := pay_service.SendRedPack("欧轩互动", user.Openid, rule.Prompt, "直播抢红包活动", + // "抢的多,赚得多", int(record.Amount*100), 1, 2) + //t.CheckErr(err) + //record.MchBillno = result.MchBillno + record.IsDraw = 1 + models.Update(record.Id, record, "mch_billno", "is_draw") t.JSON(record) } diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index b4d90cc..bb3061c 100644 --- a/controllers/client/lottery.go +++ b/controllers/client/lottery.go @@ -53,7 +53,7 @@ func (t *LotteryCtl) CashLottery() { record.WxNo = wxNo record.Address = address record.Status = 1 - _, err = record.Update(record.Id, "name", "phone", "wx_no", "address", "status") + _, err = models.Update(record.Id, record, "name", "phone", "wx_no", "address", "status") t.CheckErr(err) t.SUCCESS("兑奖成功") } diff --git a/controllers/client/shake_red_envelope.go b/controllers/client/shake_red_envelope.go index e836bbc..6133278 100644 --- a/controllers/client/shake_red_envelope.go +++ b/controllers/client/shake_red_envelope.go @@ -10,7 +10,6 @@ import ( "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" "math/rand" - "strings" "time" ) @@ -80,24 +79,22 @@ func (t *ShakeRedEnvelopeCtl) Shake() { t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") - record.IsDraw = 1 + record.IsDraw = 0 record.UserId = userId record.AreaId = areaId - row, err := record.UpdateById(record.Id, "version,is_draw, user_id, area_id") + row, err := models.Update(record.Id, record, "is_draw", "user_id", "area_id") t.CheckErr(err) t.Assert(row == 1, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 那么 row == 1 为已经成功抢到 // 记录红包 ---> 非彩排才能 if activity.RehearsalId == 0 { - addr := strings.Split(t.Request.OriginRequest.RemoteAddr, ":") - result, err := pay_service.SendRedPack("欧轩互动", user.Openid, "红包只会越抢越多", addr[0], + result, err := pay_service.SendRedPack("欧轩互动", user.Openid, "红包只会越抢越多", "直播抢红包活动", "抢的多,赚得多", int(record.Amount*100), 1, 2) if err != nil { t.ERROR("红包被领完了", code.MSG_SHAKERB_RECORD_NOT_HIT) } record.MchBillno = result.MchBillno - record.Version += 1 - record.UpdateById(record.Id, "version, mch_billno") + models.Update(record.Id, record, "mch_billno") } // 通知大屏 diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index c6e6345..ab90aa9 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -118,7 +118,7 @@ func (t *LotteryDrawCtl) Stop() { ladder.Status = define.StatusEnding ladder.UpdatedAt = time.Now() ladder.RollNum = 0 - _, err = models.Update(ladder.Id, ladder, "status, updated_at, roll_num") + _, err = models.Update(ladder.Id, ladder, "status", "updated_at", "roll_num") t.CheckErr(err) // 通知直播开始抽奖 diff --git a/log/hdzj.log b/log/hdzj.log index e843239..7e9434c 100644 --- a/log/hdzj.log +++ b/log/hdzj.log @@ -88,3 +88,7 @@ 2020-05-18 14:09:10.578 ERROR logger/logger.go:87 user:===>%+v&{1 阳江 广东 中国 oYJTvt9Pz9blsITPp1q9V8E9HoQs o9XM41s_NN8Y0QK6_MbM-aYMV3TE 疯狂疯狂@黄梓健 http://thirdwx.qlogo.cn/mmopen/vi_32/U8krFYdib9PITkDicbaNPnJHKpUMJ8unribzyPcUKWKGyJovoKmES6UHW1Zl6bVsUUtY7I404UNQXG7ll5rWy6Fmg/132 男 0 127 127 主会场 false 2020-05-18 13:37:14 +0800 CST 2020-05-18 13:37:40 +0800 CST} 2020-05-18 14:09:10.578 ERROR logger/logger.go:87 token:==>%veyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50VHlwZSI6Img1dXNlciIsIkFjY291bnRJZCI6MSwiQ3VzdG9tZXJJZCI6MCwiQ3VzdG9tZXJQaWQiOjAsIkFjdGl2aXR5SWQiOjAsIkFyZWFJZCI6MCwiYXVkIjoib3NtYW50aHVzd2luZS1hdWRpZW5jZS1veCIsImV4cCI6MTY3NDU0ODE1NCwianRpIjoiMDkwNGY0ODItNTdkOC00NGNmLTg1MzEtYmFjMTk5ZjU1ZDdmIiwiaXNzIjoib3NtYW50aHVzd2luZS1pc3N1ZXItb3giLCJzdWIiOiJvc21hbnRodXN3aW5lLXN1YmplY3Qtb3gifQ.OVJtS0emjP4pkhR8hFGsUCJu6AicDSOh0IfPv27epKk 2020-05-18 14:09:10.578 ERROR logger/logger.go:87 user_id:===>%v1 +2020-05-21 10:31:06.559 ERROR logger/logger.go:87 check err{error 25 0 FAILNO_AUTHIP地址非你在商户平台设置的可用IP地址} +2020-05-21 10:36:20.616 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 Post https://api2.mch.weixin.qq.com/pay/orderquery: context deadline exceeded } {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 } +2020-05-21 10:38:01.658 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection } {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 } +2020-05-21 10:38:23.165 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection } {交易订单号 15 0 W1zSTjb10NTYuLM2D4EKOGM25MbbHuG2 } diff --git a/models/lottery_draw_record.go b/models/lottery_draw_record.go index c6aad0d..abce086 100644 --- a/models/lottery_draw_record.go +++ b/models/lottery_draw_record.go @@ -53,11 +53,6 @@ func (t *LotteryDrawRecord) GetByUserPrizeId(upId int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and user_prize_id=?", upId).Get(t) } -func (t *LotteryDrawRecord) Update(id interface{}, field ...string) (int64, error) { - t.Id = 0 - return core.GetXormAuto().Where("id=?", id).Update(t) -} - func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}, rollNum int) error { session := core.GetXormAuto().Table(new(LotteryDrawRecord)).Alias("r"). Join("LEFT", new(User).Alias("u"), "u.id=r.user_id"). diff --git a/models/shake_red_envelope_record.go b/models/shake_red_envelope_record.go index cf302ff..55c2200 100644 --- a/models/shake_red_envelope_record.go +++ b/models/shake_red_envelope_record.go @@ -24,9 +24,9 @@ type ShakeRedEnvelopeRecord struct { UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"` Amount float64 `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(18)"` IsValid bool `json:"is_valid,omitempty" xorm:"-"` - IsDraw int `json:"is_draw" xorm:"not null default 0 comment('-1未被摇中,0已被摇中')"` - MchBillno string `json:"mch_billno" xorm:"not null default"` - Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"` + IsDraw int `json:"is_draw" xorm:"not null default 0 comment('-1未被摇中,0已被摇中1被提取')"` + MchBillno string `json:"mch_billno" xorm:"not null default '' comment('微信红包订单号') VARCHAR(128)"` + Version int `json:"version" xorm:"not null version default 0 comment('乐观锁') INT(11)"` // 无关变量 } @@ -62,7 +62,7 @@ func (t *ShakeRedEnvelopeRecord) Count(aid, rid, said, srid int64, status int64) } func (t *ShakeRedEnvelopeRecord) GetByRuleId(ruleId, rehearsalId, _type interface{}) (bool, error) { - return core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and red_envelope_type = ? and "+ + return core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and shake_red_envelope_type = ? and "+ "shake_red_envelope_rule_id=? and rehearsal_id=?", _type, ruleId, rehearsalId).Get(t) } diff --git a/services/pay/const.go b/services/pay/const.go index 918c66a..bea5987 100644 --- a/services/pay/const.go +++ b/services/pay/const.go @@ -13,6 +13,7 @@ var ( Secret = "f6aabdd40ea25272f4442603a7dc8028" Mchid = `1394404502` ApiKey = `2c82c64ceec6ba89ffc9f593c671a12f` + ClientIp = `123.207.246.51` mainHost = `https://api.mch.weixin.qq.com` backHost = `https://api2.mch.weixin.qq.com` ) diff --git a/services/pay/order.go b/services/pay/order.go index af9d790..529ff39 100644 --- a/services/pay/order.go +++ b/services/pay/order.go @@ -18,7 +18,7 @@ import ( ) func init() { - go loopUnifiedOrder() + //go loopUnifiedOrder() } var orderDelayQueue = make(chan *OrderDelayQueueParam, math.MaxInt8) diff --git a/services/pay/transfer.go b/services/pay/transfer.go index ca8f958..6f927ea 100644 --- a/services/pay/transfer.go +++ b/services/pay/transfer.go @@ -265,7 +265,7 @@ type RedPackResult struct { } // 发送红包 -func SendRedPack(sendName, openId, wishing, ip, actName, remark string, totalAmount, totalNum, scene int) (*RedPackResult, error) { +func SendRedPack(sendName, openId, wishing, actName, remark string, totalAmount, totalNum, scene int) (*RedPackResult, error) { client, err := Client() if err != nil { logger.Error("client init error: %v", err) @@ -285,7 +285,7 @@ func SendRedPack(sendName, openId, wishing, ip, actName, remark string, totalAmo body["total_amount"] = fmt.Sprintf("%d", totalAmount) body["total_num"] = fmt.Sprintf("%d", totalNum) body["wishing"] = wishing - body["client_ip"] = ip + body["client_ip"] = ClientIp body["act_name"] = actName body["remark"] = remark body["scene_id"] = fmt.Sprintf("PRODUCT_%d", scene) @@ -303,7 +303,6 @@ func SendRedPack(sendName, openId, wishing, ip, actName, remark string, totalAmo } return res, nil - } type QueryRedPackResult struct { diff --git a/test/pay_test.go b/test/pay_test.go index 743660c..a76fb6f 100644 --- a/test/pay_test.go +++ b/test/pay_test.go @@ -22,7 +22,8 @@ func TestTransfer(t *testing.T) { } func TestSendRedPack(t *testing.T) { - res, err := pay_service.SendRedPack("欧轩互动-红包测试", openId, "你好测试", "192.168.1.103", "tommy", + res, err := pay_service.SendRedPack("欧轩互动-红包测试", openId, + "你好测试", "tommy", "哈哈哈哈哈", 1, 1, 1) fmt.Println(err) fmt.Printf("%+v\n", res)