Browse Source

下订单

master
黄梓健 5 years ago
parent
commit
95cc3d2233
  1. 8
      controllers/author.go
  2. 16
      controllers/client/live.go
  3. 2
      controllers/client/lottery.go
  4. 11
      controllers/client/shake_red_envelope.go
  5. 2
      controllers/pc/lottery_draw.go
  6. 4
      log/hdzj.log
  7. 5
      models/lottery_draw_record.go
  8. 8
      models/shake_red_envelope_record.go
  9. 1
      services/pay/const.go
  10. 2
      services/pay/order.go
  11. 5
      services/pay/transfer.go
  12. 3
      test/pay_test.go

8
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

16
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)
}

2
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("兑奖成功")
}

11
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")
}
// 通知大屏

2
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)
// 通知直播开始抽奖

4
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 <xml><result_code>FAIL</result_code><err_code>NO_AUTH</err_code><err_code_des>IP地址非你在商户平台设置的可用IP地址</err_code_des></xml>}
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 <nil>} {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 <nil>}
2020-05-21 10:38:01.658 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection <nil>} {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 <nil>}
2020-05-21 10:38:23.165 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection <nil>} {交易订单号 15 0 W1zSTjb10NTYuLM2D4EKOGM25MbbHuG2 <nil>}

5
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").

8
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)
}

1
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`
)

2
services/pay/order.go

@ -18,7 +18,7 @@ import (
)
func init() {
go loopUnifiedOrder()
//go loopUnifiedOrder()
}
var orderDelayQueue = make(chan *OrderDelayQueueParam, math.MaxInt8)

5
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 {

3
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)

Loading…
Cancel
Save