diff --git a/controllers/client/order.go b/controllers/client/good.go similarity index 93% rename from controllers/client/order.go rename to controllers/client/good.go index 25d702b..5b75547 100644 --- a/controllers/client/order.go +++ b/controllers/client/good.go @@ -88,6 +88,7 @@ func (t *GoodCtl) Order() { order.GoodsName = good.Name order.ActivityId = activity.Id order.TotalAmount = float64(num) * good.Price + order.PayAmount = order.TotalAmount order.OutTradeNo = res["out_trade_no"].(string) order.GoodsNum = num order.Address = address @@ -104,3 +105,12 @@ func (t *GoodCtl) Order() { res["order_id"] = order.Id t.JSON(res) } + +// 为支付的重新支付 +func (t *GoodCtl) Reorder() { + outTradeNo := t.MustGet("out_trade_no") + + res, err := pay_service.ReOrder(outTradeNo) + t.CheckErr(err) + t.JSON(res) +} diff --git a/controllers/client/live.go b/controllers/client/live.go index 66d58ff..40969a6 100644 --- a/controllers/client/live.go +++ b/controllers/client/live.go @@ -21,7 +21,6 @@ type NoticeRedPackEvent struct { type LiveCtl struct { controllers.AuthorCtl - //controllers.BaseCtl } // 详情 diff --git a/libs/im/im.go b/libs/im/im.go index 8fc3385..fe99c30 100644 --- a/libs/im/im.go +++ b/libs/im/im.go @@ -18,13 +18,13 @@ var ( TxImHostV4 = "https://console.tim.qq.com/v4" ) -type NoticeType int +type NoticeStatus int -const NoticeLiveRedPackStart NoticeType = 256 // 通知直播用户红包开始了 -const NoticeLiveRedPackEnd NoticeType = 257 // 通知直播用户红包结束了 -const NoticeLiveRedPackGet NoticeType = 258 // 某人摇中红包 -const NoticeShakeRedPackStart NoticeType = 259 // 通知摇红包开始了 -const NoticeShakeRedPackEnd NoticeType = 260 // 通知摇红包结束了 +const NoticeLiveRedPackStart NoticeStatus = 256 // 通知直播用户红包开始了 +const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结束了 +const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包 +const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了 +const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了 type CommonResult struct { ActionStatus string `json:"ActionStatus"` @@ -80,7 +80,7 @@ type SendGroupSystemNotificationParam struct { ToMembersAccount []string `json:"ToMembers_Account,omitempty"` } -func SendGroupSystemNotification(groupId string, noticeType NoticeType, data map[string]interface{}, members ...string) error { +func SendGroupSystemNotification(groupId string, status NoticeStatus, data map[string]interface{}, members ...string) error { sig, err := GenSig("admin") if err != nil { return err @@ -90,7 +90,7 @@ func SendGroupSystemNotification(groupId string, noticeType NoticeType, data map TxImHostV4, SdkAppid, sig, random) var m = make(map[string]interface{}) - m["type"] = noticeType + m["status"] = status m["data"] = data content, err := json.Marshal(&m) if err != nil { diff --git a/models/customer_order.go b/models/customer_order.go index 637aee3..840d8fb 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -26,6 +26,7 @@ type CustomerOrder struct { GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"` GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"` TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额') DECIMAL(18)"` + PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额') DECIMAL(18)"` Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]') DECIMAL(18)"` Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付2待发货3已发货4确认收货5申请退款6已退款]')"` // 快递信息 diff --git a/services/im/im.go b/services/im/im.go index f0f2ede..3f84947 100644 --- a/services/im/im.go +++ b/services/im/im.go @@ -6,7 +6,7 @@ import ( "hudongzhuanjia/models" ) -func SendNoticeByActivityId(activityId int64, _type im.NoticeType, data map[string]interface{}, members ...string) error { +func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[string]interface{}, members ...string) error { live := new(models.LiveConfig) exist, err := live.GetByActivityId(activityId) if err != nil { diff --git a/services/pay/order.go b/services/pay/order.go index ba426ad..53a3dbb 100644 --- a/services/pay/order.go +++ b/services/pay/order.go @@ -38,6 +38,10 @@ func PutOrderDelayQueue(body, outTradeNo, openId string, amount, status int, exp expires = time.Now().Add(2 * time.Hour).Unix() // 2 个小时 } + if delay == 0 { + delay = 100 + } + orderDelayQueue <- &orderDelayQueueParam{ First: true, Expires: expires, @@ -83,7 +87,7 @@ func loopUnifiedOrder() { // 首次进入不延迟 if !param.First { - time.Sleep(time.Duration(param.Delay) * time.Second) + time.Sleep(time.Duration(param.Delay) * time.Millisecond) } param.First = false @@ -192,6 +196,37 @@ func UnifiedOrder(body, openid string, fee, goodType, userId, activityId int64) }, nil } +func ReOrder(outTradeNo string) (map[string]interface{}, error) { + userOrder := new(models.UserOrder) + exist, err := userOrder.GetByOutTradeNo(outTradeNo) + if err != nil { + return nil, err + } + if !exist { + return nil, errors.New("订单不存在") + } + + timestamp := strconv.FormatInt(time.Now().Unix(), 10) + nonceStr := utils.RandomStr(32) + //获取H5支付需要的paySign + pac := "prepay_id=" + userOrder.PrepayId + paySign := core2.JsapiSign(Appid, timestamp, nonceStr, pac, core2.SignType_MD5, ApiKey) + if userOrder.TimeExpire <= core2.FormatTime(time.Now()) { + go PutOrderDelayQueue(userOrder.Body, userOrder.OutTradeNo, userOrder.OpenId, int(userOrder.TotalFee), userOrder.Status, 0, 0) + } + return map[string]interface{}{ + "appid": Appid, + "timestamp": timestamp, + "nonce_str": nonceStr, + "package": pac, + "sign_type": core2.SignType_MD5, + "pay_sign": paySign, + "out_trade_no": outTradeNo, + "user_order_id": userOrder.Id, + }, nil + +} + // Notify type NotifyRequest struct { ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`