Browse Source

rehearsal_id

master
黄梓健 5 years ago
parent
commit
639d24abe4
  1. 83
      controllers/client/good.go
  2. 33
      controllers/client/live.go
  3. 3
      controllers/client/reward.go
  4. 20
      controllers/client/sign.go
  5. 6
      controllers/common/im.go
  6. 24
      controllers/pc/lottery_draw.go
  7. 3
      controllers/pc/reward.go
  8. 5
      controllers/pc/shake_red_envelope.go
  9. 2
      libs/im/im.go
  10. 10
      libs/im/status.go
  11. 1
      models/area_store.go
  12. 24
      services/im/im.go
  13. 3
      services/pay/handle.go
  14. 2
      test/pay_test.go

83
controllers/client/good.go

@ -149,39 +149,47 @@ func (t *GoodCtl) Order() {
defer session.Close()
session.Begin()
subOrders := make([]*models.CustomerOrderSub, 0)
var price = 0
goodIds := make([]interface{}, 0)
for _, g := range param.Goods {
good := new(models.CustomerGoods)
exist, err = session.Where("is_delete=0 and id=?", g["id"]).Get(good)
if err != nil || !exist {
session.Rollback()
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)
}
if good.Stock-g["num"] < 0 {
session.Rollback()
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
}
goodIds = append(goodIds, g["id"])
}
goods := make([]*models.CustomerGoods, 0)
err = session.Where("is_delete=0").In("id", goodIds).Find(&goods)
if err != nil || len(goods) != len(goodIds) || len(goods) <= 0 {
session.Rollback()
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)
}
if good.Stock > 0 {
_, err = session.ID(good.Id).Decr("stock", g["num"]).Cols("stock").Update(good)
if err != nil {
session.Rollback()
t.CheckErr(err)
subOrders := make([]*models.CustomerOrderSub, 0)
var price = 0
// 检测库存
for _, good := range goods {
for _, g := range param.Goods {
if good.Id == int64(g["id"]) {
if good.Stock-g["num"] < 0 {
session.Rollback()
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
} else {
_, err = session.ID(good.Id).Decr("stock", g["num"]).Cols("stock").Update(good)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
price += int(good.Price*100) * g["num"]
subOrders = append(subOrders, &models.CustomerOrderSub{
IsDelete: false,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
OrderNo: "",
GoodsId: good.Id,
GoodsNum: g["num"],
GoodName: good.Name,
GoodPrice: good.Price,
})
break
}
}
}
price += int(good.Price*100) * g["num"]
subOrders = append(subOrders, &models.CustomerOrderSub{
IsDelete: false,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
OrderNo: "",
GoodsId: good.Id,
GoodsNum: g["num"],
GoodName: good.Name,
GoodPrice: good.Price,
})
}
res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid,
@ -222,16 +230,21 @@ func (t *GoodCtl) Order() {
session.Rollback()
t.CheckErr(err)
}
// 批量插入
beans := make([]interface{}, 0)
for _, subOrder := range subOrders {
subOrder.OrderNo = order.OrderNo
_, err = session.InsertOne(subOrder)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
beans = append(beans, subOrder)
}
session.Insert(beans...)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
session.Commit()
err = session.Commit()
t.CheckErr(err)
res["order_id"] = order.Id
t.JSON(res)

33
controllers/client/live.go

@ -1,13 +1,10 @@
package client
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/filter"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/models"
im_service "hudongzhuanjia/services/im"
pay_service "hudongzhuanjia/services/pay"
red_envelope_service "hudongzhuanjia/services/red_envelope"
"hudongzhuanjia/utils"
@ -131,15 +128,11 @@ func (t *LiveCtl) SendLiveRedPack() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
var res = make(map[string]interface{}, 0)
res["out_trade_no"] = ""
if activity.RehearsalId == 0 {
res, err = pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int64(amount*100), 3, userId, activityId)
t.CheckErr(err)
}
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int64(amount*100), 3, userId, activityId)
t.CheckErr(err)
rule := new(models.LiveRedEnvelopeRule)
rule.OutTradeNo = res["out_trade_no"].(string) // 彩排为空
rule.OutTradeNo = res["out_trade_no"].(string)
rule.ActivityId = activityId
rule.RehearsalId = activity.RehearsalId
rule.AreaId = areaId
@ -148,26 +141,12 @@ func (t *LiveCtl) SendLiveRedPack() {
rule.Num = num
rule.Prompt = filter.Replace(prompt)
rule.IsDelete = false
if activity.RehearsalId == 0 {
rule.Status = 0
} else {
rule.Status = 1 // 彩排
}
rule.Status = 0
rule.UpdatedAt = time.Now()
rule.CreatedAt = time.Now()
_, err = models.Add(rule)
t.CheckErr(err)
if activity.RehearsalId != 0 { // 彩排不过钱
err = im_service.SendGroupCustomMessage(fmt.Sprint(user.Id), activityId, im.NoticeLiveRedPackStart,
map[string]interface{}{
"live_red_envelope_rule_id": rule.Id,
"prompt": rule.Prompt,
"timestamp": time.Now().Unix(),
})
t.CheckErr(err)
}
records := red_envelope_service.GenRedPack(int(amount*100), num)
for _, v := range records {
record := new(models.ShakeRedEnvelopeRecord)
@ -230,9 +209,5 @@ func (t *LiveCtl) GetLiveRedPack() {
return
}
if rule.RehearsalId == 0 { // 非彩排
go pay_service.PutTransferDelayQueue("欧轩互动-红包活动", user.Openid, redPack.PartnerTradeNo, int(redPack.Amount*100), 5, 5*60)
}
t.JSON(redPack)
}

3
controllers/client/reward.go

@ -23,6 +23,7 @@ func (t *RewardCtl) Reward() {
content := t.MustGet("content")
amount := t.MustGetDouble("amount")
uid := t.MustGetUID()
_type := t.DefaultInt("type", 0)
if amount <= 0 {
t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param)
@ -56,7 +57,7 @@ func (t *RewardCtl) Reward() {
var res = make(map[string]interface{}, 0)
res["out_trade_no"] = ""
if activity.RehearsalId == 0 {
if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2, user.Id, activityId)
t.CheckErr(err)
}

20
controllers/client/sign.go

@ -94,15 +94,8 @@ func (t *SignCtl) Setting() {
func (t *SignCtl) Sign() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
_type := t.DefaultInt("_type", 0) // 默认 0
// 适配直播
var areaId int64 = 0
if _type == 0 {
areaId = t.MustGetAreaId()
} else {
areaId = t.MustGetInt64("area_id")
}
_type := t.DefaultInt("type", 0) // 默认 0
areaId := t.MustGetAreaId()
//根据activity_id查找主活动的信息
activity := new(models.Activity)
@ -110,11 +103,10 @@ func (t *SignCtl) Sign() {
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
// 根据areaId
customer := new(models.Customer)
exist, err = customer.GetByActivityIdAndAreaId(activityId, areaId)
area := new(models.AreaStore)
exist, err = models.GetById(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
user := new(models.User)
exist, err = models.GetById(user, uid)
@ -168,7 +160,7 @@ func (t *SignCtl) Sign() {
go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
"type": "sign_up",
"customer_id": customer.Id,
"customer_id": area.CustomerId,
"data": map[string]interface{}{
"avatar": user.Avatar,
"sign_total": signTotal + 1,

6
controllers/common/im.go

@ -1,9 +1,7 @@
package common
import (
"fmt"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/im"
im_service "hudongzhuanjia/services/im"
"time"
)
@ -16,7 +14,7 @@ func (t *ImTestCtl) SendNotice() {
activityId := t.MustGetInt64("activity_id")
status := t.MustGetInt("status")
im_service.SendGroupCustomMessage(fmt.Sprint(1), activityId, im.NoticeStatus(status), map[string]interface{}{
im_service.SendGroupCustomMessage(1, activityId, im_service.NoticeStatus(status), map[string]interface{}{
"customer_id": 16,
"shake_red_envelope_rule_id": 5,
"timestamp": time.Now().Unix(),
@ -28,7 +26,7 @@ func (t *ImTestCtl) SendRedPack() {
activityId := t.MustGetInt64("activity_id")
prompt := t.MustGet("prompt")
im_service.SendGroupCustomMessage(fmt.Sprint(1), activityId, im.NoticeLiveRedPackStart,
im_service.SendGroupCustomMessage(1, activityId, im_service.NoticeLiveRedPackStart,
map[string]interface{}{
"live_red_envelope_rule_id": 1,
"prompt": prompt,

24
controllers/pc/lottery_draw.go

@ -5,6 +5,7 @@ import (
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
im_service "hudongzhuanjia/services/im"
lottery_service "hudongzhuanjia/services/lottery"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
@ -21,6 +22,7 @@ type LotteryDrawCtl struct {
//开始抽奖
func (t *LotteryDrawCtl) Start() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
ladder := new(models.LotteryDrawRuleLadder)
exist, err := models.GetById(ladder, ladderId)
@ -36,12 +38,19 @@ func (t *LotteryDrawCtl) Start() {
"id=": ladderId,
}, ladder, "status", "updated_at"))
// 通知直播开始抽奖
im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStart,
map[string]interface{}{
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
})
t.SUCCESS("操作成功")
}
//停止抽奖
func (t *LotteryDrawCtl) Stop() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
ladder := new(models.LotteryDrawRuleLadder)
exist, err := models.GetById(ladder, ladderId)
@ -58,6 +67,13 @@ func (t *LotteryDrawCtl) Stop() {
"id=": ladderId,
}, ladder, "status", "updated_at"))
// 通知直播开始抽奖
im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStop,
map[string]interface{}{
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
})
t.SUCCESS("操作成功")
}
@ -379,6 +395,14 @@ func (t *LotteryDrawCtl) Lottery() {
t.CheckErr(err)
}
// 通知直播开始抽奖
im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawResult,
map[string]interface{}{
"winners": winners,
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
})
t.RAW(winners)
}

3
controllers/pc/reward.go

@ -3,7 +3,6 @@ package pc
import (
"fmt"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/models"
bully_reward_service "hudongzhuanjia/services/bully_reward"
im_service "hudongzhuanjia/services/im"
@ -115,7 +114,7 @@ func (t *RewardCtl) Review() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
go im_service.SendGroupCustomMessage(fmt.Sprint(user.Id), v.ActivityId, im.NoticeReward,
go im_service.SendGroupCustomMessage(user.Id, v.ActivityId, im_service.NoticeReward,
map[string]interface{}{
"amount": v.Amount,
"content": v.Content,

5
controllers/pc/shake_red_envelope.go

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/models"
im_service "hudongzhuanjia/services/im"
red_envelope_service "hudongzhuanjia/services/red_envelope"
@ -87,7 +86,7 @@ func (t *ShakeRedEnvelopeCtl) Start() {
err = red_envelope_service.GenRedEnvelope(activity.Id, activity.RehearsalId, rule)
t.CheckErr(err)
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im.NoticeShakeRedPackStart,
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackStart,
map[string]interface{}{
"customer_id": uid,
"shake_red_envelope_rule_id": rule.Id,
@ -116,7 +115,7 @@ func (t *ShakeRedEnvelopeCtl) Stop() {
_, err = rule.UpdateStatus(ruleId, rule.ShakeRedEnvelopeStatus)
t.CheckErr(err)
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im.NoticeShakeRedPackEnd,
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackEnd,
map[string]interface{}{
"customer_id": uid,
"shake_red_envelope_rule_id": rule.Id,

2
libs/im/im.go

@ -46,7 +46,7 @@ type SendGroupSystemNotificationParam struct {
ToMembersAccount []string `json:"ToMembers_Account,omitempty"`
}
func SendGroupSystemNotification(groupId string, status NoticeStatus, data map[string]interface{}, members ...string) error {
func SendGroupSystemNotification(groupId string, status int, data map[string]interface{}, members ...string) error {
sig, err := GenSig("admin")
if err != nil {
return err

10
libs/im/status.go

@ -1,11 +1 @@
package im
// 定义一些通知或者数据状态
type NoticeStatus int
const NoticeLiveRedPackStart NoticeStatus = 256 // 通知直播用户红包开始了
const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结束了
const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包
const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了
const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了
const NoticeReward NoticeStatus = 261 // 打赏

1
models/area_store.go

@ -15,6 +15,7 @@ type AreaStore struct {
Type string `json:"type" xorm:"not null default('') comment('地区类型') VARCHAR(255)"`
Address string `json:"address" xorm:"not null default('') comment('地址') VARCHAR(255)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id') BIGINT(20)"`
CustomerId int64 `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"`
IsMainArea bool `json:"is_main_area" xorm:"not null default(0) comment('是否主地区1是') TINYINT(1)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`

24
services/im/im.go

@ -8,10 +8,22 @@ import (
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
"strconv"
)
func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[string]interface{}, members ...string) error {
// 定义一些通知或者数据状态
type NoticeStatus int
const NoticeLiveRedPackStart NoticeStatus = 256 // 通知直播用户红包开始了
const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结束了
const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包
const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了
const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了
const NoticeReward NoticeStatus = 261 // 打赏
const NoticeLotteryDrawStart = 262 // 抽奖开始
const NoticeLotteryDrawStop = 263 // 抽奖开始
const NoticeLotteryDrawResult = 264 // 抽奖结果
func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error {
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
if err != nil {
@ -21,10 +33,10 @@ func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[st
return errors.New("直播信息不存在")
}
groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
return im.SendGroupSystemNotification(groupId, _type, data, members...)
return im.SendGroupSystemNotification(groupId, int(_type), data, members...)
}
func SendGroupCustomMessage(userId string, activityId int64, _type im.NoticeStatus, data map[string]interface{}) error {
func SendGroupCustomMessage(userId interface{}, activityId int64, _type NoticeStatus, data map[string]interface{}) error {
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
if err != nil || !exist {
@ -43,13 +55,13 @@ func SendGroupCustomMessage(userId string, activityId int64, _type im.NoticeStat
GroupId: groupId,
Random: utils.RandomInt(6),
MsgPriority: "High",
FromAccount: userId,
FromAccount: fmt.Sprint(userId),
MsgBody: []im.MsgBody{
{
MsgType: "TIMCustomElem",
MsgContent: im.MsgBodyContent{
Data: string(bs),
Desc: strconv.Itoa(int(_type)),
Desc: fmt.Sprint(_type),
Ext: "",
Sound: "",
},

3
services/pay/handle.go

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
im_service "hudongzhuanjia/services/im"
@ -100,7 +99,7 @@ func HandleSuccess(param *OrderDelayQueueParam) (err error) {
return
}
err = im_service.SendGroupCustomMessage(fmt.Sprint(info.UserId), param.Order.ActivityId, im.NoticeLiveRedPackStart,
err = im_service.SendGroupCustomMessage(info.UserId, param.Order.ActivityId, im_service.NoticeLiveRedPackStart,
map[string]interface{}{
"live_red_envelope_rule_id": info.Id,
"prompt": info.Prompt,

2
test/pay_test.go

@ -54,7 +54,7 @@ func TestTimeExpire(t *testing.T) {
func TestSendNotice(t *testing.T) {
for {
err := im_service.SendGroupCustomMessage(fmt.Sprint(4), 118, im.NoticeReward,
err := im_service.SendGroupCustomMessage(4, 118, im_service.NoticeReward,
map[string]interface{}{
"amount": 20.01,
"content": "恭喜你发出",

Loading…
Cancel
Save