Compare commits

...

96 Commits

Author SHA1 Message Date
Tooooommy db53e536f1 fix:bug 5 years ago
Tooooommy 33b5eb548a fix:bug 5 years ago
Tooooommy 460ec0d9f2 fix:bug 5 years ago
Tooooommy 1b88707365 fix;bug 5 years ago
Tooooommy 779cd208b9 fix:bug 5 years ago
Tooooommy 643e0c46f0 fix;bug 5 years ago
Tooooommy c3747b0748 fix:bug 5 years ago
Tooooommy c3a7aa213a fix:bug 5 years ago
Tooooommy 9cb50a61a0 fix:bug 5 years ago
Tooooommy bc8231404b fix:bug 5 years ago
Tooooommy af856f81c5 fix:bug 5 years ago
Tooooommy 09be522af9 fix;bug 5 years ago
Tooooommy 10bc945b35 fix:bug 5 years ago
Tooooommy 685ba61fb9 fix:bug 5 years ago
Tooooommy 798712c12d check live user 5 years ago
Tooooommy 882699fc06 replace token with jwt token 5 years ago
黄梓健 ab73dff8ae fix:bug 5 years ago
黄梓健 51f35b11c5 fix:bug 5 years ago
黄梓健 3eed0107be fix:bug 5 years ago
黄梓健 174847d235 fix:bug 5 years ago
黄梓健 cb87980b35 fix:bug 5 years ago
黄梓健 4b4f985553 fix:bug 5 years ago
黄梓健 d34844eb5a fix:bug 5 years ago
黄梓健 db7caf3f3d fix:bug 5 years ago
黄梓健 bc6fd148c1 rm price = 0 5 years ago
黄梓健 84da3c378b add amout = 0 5 years ago
黄梓健 795528cd8e fix:bug 5 years ago
黄梓健 63127b2b40 fix:bug 5 years ago
黄梓健 1892bc4676 fix:bug 5 years ago
黄梓健 648c1b13d9 fix:bug 5 years ago
黄梓健 e51dcf0949 fix:bug 5 years ago
黄梓健 7b6a8182c2 fix:bug 5 years ago
黄梓健 faa8bdf698 fix:bug 5 years ago
黄梓健 975f51f6d2 update: login 5 years ago
黄梓健 9597bcd7b5 add area admin login 5 years ago
黄梓健 c9d1f656df fix:bug 5 years ago
黄梓健 d17355a24c fix:bug 5 years ago
黄梓健 0ad3e8e8c5 fix:bug 5 years ago
黄梓健 af8672ad6a fix:bug 5 years ago
黄梓健 28bdea2be0 fix:bug 5 years ago
黄梓健 b47f62efe0 fix:bug 5 years ago
黄梓健 96c24128b4 fix:bug 5 years ago
黄梓健 d0409fe251 fix:bug 5 years ago
黄梓健 df45d21e38 fix:bug 5 years ago
黄梓健 f81253a676 fix:bug 5 years ago
黄梓健 4aea07e0b1 fix:bug 5 years ago
黄梓健 9981ec119e fix:bug 5 years ago
黄梓健 b164b50d3b fix:bug 5 years ago
黄梓健 5e611b1c82 fix:bug 5 years ago
黄梓健 f79f066576 fix:bug 5 years ago
黄梓健 8128d9eaf6 fix:bug 5 years ago
黄梓健 8ce0790e7a fix:bug 5 years ago
黄梓健 33d9f05d5f fix:bug 5 years ago
黄梓健 7583a775ea fix:bug 5 years ago
黄梓健 2564262cc2 fix:bug 5 years ago
黄梓健 af33e2c1bb fix:bug 5 years ago
黄梓健 b862560488 fix:bug 5 years ago
黄梓健 c64e5e0143 fix:bug 5 years ago
黄梓健 6e944a1251 fix:bug 5 years ago
黄梓健 0f20633682 fix:bug 5 years ago
黄梓健 0128c61d38 fix:bug 5 years ago
黄梓健 d97a73546d fix:bug 5 years ago
黄梓健 0e98389f57 fix:bug 5 years ago
黄梓健 859e2fa5d4 fix:bug 5 years ago
黄梓健 e8377b37ad fix:bug 5 years ago
黄梓健 ce68ab2037 fix:bug 5 years ago
黄梓健 f32ed2e395 fix:bug 5 years ago
黄梓健 163ea3d7d9 fix:bug 5 years ago
黄梓健 fa021089ce fix:bug 5 years ago
黄梓健 ab87e1afb6 fix:bug 5 years ago
黄梓健 bb707a00cf fix:bug 5 years ago
黄梓健 9dce358f22 fix:bug 5 years ago
黄梓健 c335d1d4e0 fix;bug 5 years ago
黄梓健 af5f359371 fix:bug 5 years ago
黄梓健 8584e3a0e0 fix:bug 5 years ago
黄梓健 153624bd83 fix:bug 5 years ago
黄梓健 3a776e0063 fix:Bug 5 years ago
黄梓健 f5eba23be2 fix:bug 5 years ago
黄梓健 770af7326d fix:bug 5 years ago
黄梓健 500e3db14a fix:bug 5 years ago
黄梓健 a6c3407ad7 fix:bug 5 years ago
黄梓健 90853deae5 fix:bug 5 years ago
黄梓健 0dadd944f6 fix:bug 5 years ago
黄梓健 fae2d56161 fix:bug 5 years ago
黄梓健 7dbf87949a fix:bug 5 years ago
黄梓健 d085813f67 fix:bug 5 years ago
黄梓健 e2cb972241 fix:bug 5 years ago
黄梓健 3aab2012e4 fix:bug 5 years ago
黄梓健 e6c5f98dab fix:bug 5 years ago
黄梓健 cfcbe81153 fix:bug 5 years ago
黄梓健 8d7ffbcfe8 fix:bug 5 years ago
黄梓健 ec4931b98f fix:bug 5 years ago
黄梓健 261ca26c50 fix:bug 5 years ago
黄梓健 a81a2aa69b 归档 5 years ago
黄梓健 211a00884a fix;bug 5 years ago
黄梓健 bafc8131b2 add: 归档 5 years ago
  1. 104
      controllers/author.go
  2. 4
      controllers/base.go
  3. 14
      controllers/client/activity.go
  4. 37
      controllers/client/area.go
  5. 27
      controllers/client/auction.go
  6. 7
      controllers/client/barrage.go
  7. 17
      controllers/client/bully_screen.go
  8. 14
      controllers/client/calorie.go
  9. 85
      controllers/client/good.go
  10. 16
      controllers/client/invite_envelope.go
  11. 41
      controllers/client/live.go
  12. 203
      controllers/client/login.go
  13. 53
      controllers/client/lottery.go
  14. 554
      controllers/client/order_entry.go
  15. 14
      controllers/client/reward.go
  16. 29
      controllers/client/shake_red_envelope.go
  17. 129
      controllers/client/sign.go
  18. 46
      controllers/client/tug_war.go
  19. 12
      controllers/client/upper_wall.go
  20. 36
      controllers/client/vote.go
  21. 18
      controllers/client/wx.go
  22. 3
      controllers/common/im.go
  23. 3
      controllers/common/wechat_oauth.go
  24. 11
      controllers/pc/activity.go
  25. 2
      controllers/pc/area_store.go
  26. 74
      controllers/pc/auction.go
  27. 6
      controllers/pc/barrage.go
  28. 31
      controllers/pc/bully_screen.go
  29. 22
      controllers/pc/calorie.go
  30. 21
      controllers/pc/login.go
  31. 116
      controllers/pc/lottery_draw.go
  32. 511
      controllers/pc/order_draw.go
  33. 50
      controllers/pc/reward.go
  34. 101
      controllers/pc/shake_red_envelope.go
  35. 67
      controllers/pc/sign.go
  36. 84
      controllers/pc/tug_war.go
  37. 70
      controllers/pc/upper_wall.go
  38. 59
      controllers/pc/vote.go
  39. 38
      controllers/pc/ws.go
  40. 23
      go.mod
  41. 66
      go.sum
  42. 11
      hdws/ws/client.go
  43. 4
      hdws/ws/http.go
  44. 12
      hdws/ws/jwt_go.go
  45. 93
      hdws/ws/login.go
  46. 2
      hdws/ws/message.go
  47. 2
      hdws/ws/msg.go
  48. 61
      hdws/ws/node.go
  49. 10
      hdws/ws/timer.go
  50. 12
      libs/jwt/jwt_go.go
  51. 5
      libs/qq/qq.go
  52. 7
      libs/wx/wx.go
  53. 3
      main.go
  54. 50
      models/CalorieUser.go
  55. 18
      models/activity.go
  56. 12
      models/activity_module_service.go
  57. 7
      models/arch.go
  58. 51
      models/area_store.go
  59. 4
      models/auction_activity.go
  60. 4
      models/auction_deal.go
  61. 35
      models/auction_history.go
  62. 18
      models/auction_player.go
  63. 32
      models/auction_result_record.go
  64. 10
      models/auction_rule.go
  65. 6
      models/bahe_activity.go
  66. 6
      models/bahe_history.go
  67. 8
      models/bahe_rule.go
  68. 13
      models/bahe_team.go
  69. 34
      models/bahe_team_member.go
  70. 7
      models/barrage_history.go
  71. 107
      models/base.go
  72. 28
      models/bully_screen_history.go
  73. 11
      models/bully_screen_server.go
  74. 9
      models/bully_screen_wallet.go
  75. 8
      models/bully_screen_wallet_hisotry.go
  76. 17
      models/calorie.go
  77. 44
      models/customer.go
  78. 27
      models/customer_goods.go
  79. 18
      models/customer_operation.go
  80. 100
      models/customer_order.go
  81. 35
      models/customer_order_option.go
  82. 45
      models/customer_order_sub.go
  83. 9
      models/dan_mu_server.go
  84. 6
      models/invitation.go
  85. 24
      models/invitation_letter.go
  86. 9
      models/live_config.go
  87. 9
      models/live_config_area.go
  88. 10
      models/live_red_envelope_rule.go
  89. 20
      models/live_viewer.go
  90. 13
      models/lottery_draw_activity.go
  91. 4
      models/lottery_draw_envelope_wallet.go
  92. 67
      models/lottery_draw_record.go
  93. 17
      models/lottery_draw_rule.go
  94. 11
      models/lottery_draw_rule_ladder.go
  95. 4
      models/lottery_draw_wallet_history.go
  96. 8
      models/lottery_draw_winner.go
  97. 2
      models/module_service.go
  98. 16
      models/module_service_history.go
  99. 4
      models/module_style.go
  100. 6
      models/msg_wall_server.go

104
controllers/author.go

@ -1,8 +1,8 @@
package controllers
import (
jwt2 "github.com/dgrijalva/jwt-go"
"hudongzhuanjia/libs/jwt"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
@ -10,69 +10,67 @@ import (
//执行路由方法前校验登陆态,并且解析page、pageSize
type AuthorCtl struct {
BaseCtl
claims *jwt.Claims
AccountId int
AccountType string
claims *jwt.Claims
}
func (t *AuthorCtl) Prepare() {
t.BaseCtl.Prepare()
skip, _ := t.GetInt64("skip")
if skip != 0 {
t.claims = &jwt.Claims{
AccountType: "customer",
AccountId: skip,
CustomerId: 1,
CustomerPid: 0,
ActivityId: 1,
AreaId: 1,
StandardClaims: jwt2.StandardClaims{},
}
return
//skip, _ := t.GetInt("skip")
//if skip != 0 {
//t.AccountId
//t.claims = &jwt.Claims{
// AccountType: "customer",
// AccountId: skip,
// CustomerId: 1,
// CustomerPid: 0,
// ActivityId: 1,
// AreaId: 1,
// StandardClaims: jwt2.StandardClaims{},
//}
//return
//} else {
token := ""
if t.Request.SESSION[define.TOKEN] != "" {
token = t.Request.SESSION[define.TOKEN]
} else if t.Request.REQUEST[define.TOKEN] != "" {
token = t.Request.REQUEST[define.TOKEN]
} else if t.Request.HEADER[define.TOKEN] != "" {
token = t.Request.HEADER[define.TOKEN]
} else {
token := ""
if tokenStr, ok := t.Request.SESSION[define.TOKEN]; ok {
token = tokenStr
} else if tokenStr, ok = t.Request.REQUEST[define.TOKEN]; ok {
token = tokenStr
} else if tokenStr, ok = t.Request.HEADER[define.TOKEN]; ok {
token = tokenStr
} else {
var param = make(map[string]interface{}, 0)
err := t.RequestToStruct(&param)
t.CheckErr(err)
if tokenStr, ok := param[define.TOKEN]; ok {
token = tokenStr.(string)
}
}
claims, err := jwt.ParseAccessToken(token)
if err != nil {
t.ERROR("token 失效", code.MSG_ERR_Authority)
var param = make(map[string]interface{}, 0)
err := t.RequestToStruct(&param)
t.CheckErr(err)
if param[define.TOKEN] != nil {
token = param[define.TOKEN].(string)
}
t.claims = claims
// 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取
}
}
func (t *AuthorCtl) MustGetUID() int64 {
return t.claims.AccountId
}
if token == "" {
t.ERROR("token失效", code.MSG_ERR_Authority)
}
func (t *AuthorCtl) MustGetCustomerId() int64 {
if t.claims.CustomerId == 0 {
return t.MustGetInt64("customer_id")
_type, id, err := models.ParseToken(token)
if err != nil {
t.ERROR("token失效", code.MSG_ERR_Authority)
return
}
return t.claims.CustomerId
t.AccountType = _type
t.AccountId = id
//claims, err := jwt.ParseAccessToken(token)
//if err != nil {
// t.ERROR("token 失效", code.MSG_ERR_Authority)
//}
//t.claims = claims
// 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取
//}
}
func (t *AuthorCtl) MustGetAreaId() int64 {
areaId, exist := t.GetInt64("area_id")
if !exist {
areaId = t.claims.AreaId
}
if areaId == 0 {
t.ERROR("area_id 不能为空", code.MSG_ERR_Param)
}
return areaId
func (t *AuthorCtl) GetAccountId() int {
return t.AccountId
}
// 对各种角色进行不同的接口权限限定
// role: main sub entry user : 主账号 子账号 录入人员 用户
func (t *AuthorCtl) GetAccountType() string {
return t.AccountType
}

4
controllers/base.go

@ -2,13 +2,14 @@ package controllers
import (
"fmt"
"go.uber.org/zap"
"hudongzhuanjia/logger"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"net/http"
"strconv"
"go.uber.org/zap"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
@ -72,7 +73,6 @@ func (t *BaseCtl) GetInt64(key string) (int64, bool) {
}
value, err := strconv.ParseInt(v, 10, 64)
if err != nil {
logger.Error("get int64 from request error", err)
t.ERROR(fmt.Sprintf("%v的数据类型不为int", key), code.MSG_ERR_Param)
return value, false
}

14
controllers/client/activity.go

@ -19,7 +19,7 @@ type ActivityCtl struct {
}
func (t *ActivityCtl) ModuleStatus() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
moduleName := t.MustGet("module_name")
exist, err := activity_service.ExistModuleByActivityId(activityId, moduleName)
t.CheckErr(err)
@ -30,9 +30,9 @@ func (t *ActivityCtl) ModuleStatus() {
// 某个模块的活动状态
func (t *ActivityCtl) ModuleCurrent() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
moduleName := t.MustGet("module_name")
uid := t.MustGetUID()
uid := t.GetAccountId()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -42,15 +42,15 @@ func (t *ActivityCtl) ModuleCurrent() {
var data map[string]interface{}
switch moduleName {
case define.MODULE_TUGWAR: // 拔河
data, err = bahe_service.GetCurrentTugWar(activityId, uid, activity.RehearsalId)
data, err = bahe_service.GetCurrentTugWar(activity.Id, uid, activity.RehearsalId, activity.ArchId)
case define.MODULE_CALORIE: // 卡路里
data, err = calorie_service.GetCurrentCalorie(activityId, uid, activity.RehearsalId)
data, err = calorie_service.GetCurrentCalorie(activityId, uid, activity.RehearsalId, activity.ArchId)
case define.MODULE_SHAKRB: // 摇红包
// 没有初始状态 // 记下参与人数
data, err = red_envelope_service.GetCurrentRB(activityId, uid, activity.RehearsalId)
data, err = red_envelope_service.GetCurrentRB(activityId, uid, activity.RehearsalId, activity.ArchId)
case define.MODULE_AUCTION:
// 竞拍
data, err = auction_service.GetCurrentAuction(activityId, activity.RehearsalId, t.MustGetUID())
data, err = auction_service.GetCurrentAuction(activityId, activity.RehearsalId, uid, activity.ArchId)
case define.MODULE_VOTE:
data, err = vote_service.GetCurrentVote(activityId, uid, activity.RehearsalId)
case define.MODULE_BULLYS:

37
controllers/client/area.go

@ -0,0 +1,37 @@
package client
import (
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/jwt"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
type AreaCtl struct {
controllers.BaseCtl
}
// 登陆
func (t *AreaCtl) Login() {
activityId := t.MustGetInt("activity_id")
username := t.MustGet("username")
password := t.MustGet("password")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := &models.AreaStore{}
exist, err = area.Login(activityId, username, password)
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR_Authority, "用户信息异常")
token, err := jwt.GenJwtToken(define.TYPE_AREAADMIN, area.Id, area.CustomerId, area.CustomerId, area.Id, area.ActivityId)
t.CheckErr(err)
t.SetSession(define.TOKEN, token)
t.JSON(map[string]interface{}{
"token": token,
"area": area,
})
}

27
controllers/client/auction.go

@ -16,11 +16,12 @@ type AuctionCtl struct {
}
// 竞拍动作
// todo: 进行替换
func (t *AuctionCtl) Auction() {
auctionId := t.MustGetInt64("auction_activity_id")
auctionId := t.MustGetInt("auction_activity_id")
totalMoney := t.MustGetDouble("total_money")
uid := t.MustGetUID()
areaId := t.MustGetInt64("area_id")
uid := t.GetAccountId()
areaId := t.MustGetInt("area_id")
if totalMoney < 0 {
t.ERROR("金额不能为0", code.MSG_ERR)
@ -49,12 +50,13 @@ func (t *AuctionCtl) Auction() {
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
player := new(models.AuctionPlayer)
exist, err = player.GetByAuctionIdAndUid(auction.Id, uid, activity.RehearsalId)
exist, err = player.GetByAuctionIdAndUid(auction.Id, uid, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "竞拍编号不存在")
history := new(models.AuctionHistory)
history.AuctionActivityId = auction.Id
history.ArchId = activity.ArchId
history.AuctionGoodsName = auction.AuctionGoodsName
history.ActivityId = activity.Id
history.RehearsalId = activity.RehearsalId
@ -75,7 +77,7 @@ func (t *AuctionCtl) Auction() {
if auction.AuctionModel == "加价竞拍" {
maxHistory := new(models.AuctionHistory)
exist, err := maxHistory.GetHighestMoney(activity.RehearsalId, auction.Id)
exist, err := maxHistory.GetHighestMoney(activity.RehearsalId, auction.Id, activity.ArchId)
t.CheckErr(err)
if exist && (history.Money < maxHistory.Money || history.UserId != maxHistory.UserId) {
history.IsDelete = true
@ -102,7 +104,7 @@ func (t *AuctionCtl) Auction() {
} else { // 减价竞拍
record := new(models.AuctionResultRecord)
count, err := record.CountHistory(activity.RehearsalId, auction.Id)
count, err := record.CountHistory(activity.RehearsalId, auction.Id, activity.ArchId)
t.CheckErr(err)
if int(count) >= auction.GoodsNum {
t.ERROR("所有商品已经竞拍完毕", code.MSG_ERR)
@ -116,6 +118,7 @@ func (t *AuctionCtl) Auction() {
record.UserName = user.Nickname
record.AreaId = area.Id
record.AreaName = area.Name
record.ArchId = activity.ArchId
record.DealPrice = totalMoney
record.RehearsalId = activity.RehearsalId
record.PlayerCode = player.Code
@ -145,8 +148,8 @@ func (t *AuctionCtl) Auction() {
}
func (t *AuctionCtl) ExistRecord() {
auctionId := t.MustGetInt64("auction_activity_id")
uid := t.MustGetUID()
auctionId := t.MustGetInt("auction_activity_id")
uid := t.GetAccountId()
auction := new(models.NewAuctionActivity)
exist, err := models.Get(auction, auctionId)
@ -159,7 +162,7 @@ func (t *AuctionCtl) ExistRecord() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
record := new(models.AuctionResultRecord)
exist, err = record.GetByUserIdAndAuctionId(uid, auctionId, activity.RehearsalId)
exist, err = record.GetByUserIdAndAuctionId(uid, auctionId, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"show": exist,
@ -168,15 +171,15 @@ func (t *AuctionCtl) ExistRecord() {
// 已经竞拍到了
func (t *AuctionCtl) UserAuctions() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
records, err := auction_service.GetUserAuctions(activityId, activity.RehearsalId, uid)
records, err := auction_service.GetUserAuctions(activityId, activity.RehearsalId, uid, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"list": records,

7
controllers/client/barrage.go

@ -18,9 +18,9 @@ type BarrageCtl struct {
//发送弹幕
func (t *BarrageCtl) Send() {
uid := t.MustGetUID()
customerId := t.MustGetCustomerId()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
customerId := t.MustGetInt("customer_id")
activityId := t.MustGetInt("activity_id")
content := t.MustGet("content")
//检查内容是否包含敏感
@ -45,6 +45,7 @@ func (t *BarrageCtl) Send() {
ActivityId: activityId,
UserId: uid,
Content: content,
ArchId: activity.ArchId,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}

17
controllers/client/bully_screen.go

@ -5,7 +5,7 @@ import (
"hudongzhuanjia/libs/filter"
"hudongzhuanjia/models"
bully_screen_service "hudongzhuanjia/services/bully_reward"
"hudongzhuanjia/services/pay"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils/code"
"time"
)
@ -17,11 +17,12 @@ type BullyScreenCtl struct {
//用户霸屏
func (t *BullyScreenCtl) PaScreen() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
uid := t.GetAccountId()
content := t.MustGet("content")
second := t.MustGetDouble("second")
style := t.MustGetInt("style")
customerId := t.MustGetInt("customer_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -50,7 +51,7 @@ func (t *BullyScreenCtl) PaScreen() {
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), 1, user.Id,
res, err = pay_service.UnifiedOrder("欧轩互动-霸屏支付", user.Openid, int(amount*100), 1, user.Id,
activityId, time.Now().Add(1*time.Hour).Unix())
t.CheckErr(err)
}
@ -58,10 +59,11 @@ func (t *BullyScreenCtl) PaScreen() {
history := models.BullyScreenHistory{
OutTradeNo: res["out_trade_no"].(string),
BullyScreenServerId: bullyScreenServer.Id,
ArchId: activity.ArchId,
ActivityId: activityId,
UserId: user.Id,
Nickname: user.Nickname,
CustomerId: t.MustGetCustomerId(),
CustomerId: customerId,
RehearsalId: activity.RehearsalId,
Second: int(second),
Amount: amount,
@ -75,13 +77,14 @@ func (t *BullyScreenCtl) PaScreen() {
}
_, err = models.Add(&history)
t.CheckErr(err)
res["rehearsal_id"] = activity.RehearsalId
t.JSON(res)
}
// 审核列表 [未审核,未通过,已通过]
func (t *BullyScreenCtl) List() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
bss := new(models.BullyScreenServer)
exist, err := bss.GetByActivityId(activityId)

14
controllers/client/calorie.go

@ -13,9 +13,9 @@ type CalorieCtl struct {
// h5 1/s
func (t *CalorieCtl) Shake() {
calorieId := t.MustGetInt64("calorie_id")
calorieId := t.MustGetInt("calorie_id")
score := t.DefaultInt("score", 0)
uid := t.MustGetUID()
uid := t.GetAccountId()
calorie := new(models.Calorie)
exist, err := models.Get(calorie, calorieId)
@ -29,21 +29,21 @@ func (t *CalorieCtl) Shake() {
t.CheckRunning(activity.Status)
calorieUser := new(models.CalorieUser)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorieId, uid, activity.RehearsalId)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorieId, activity.ArchId, uid, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "您尚未参与卡路里活动")
// 增加score
if calorie.Status == define.StatusRunning && score > 0 {
_, err = calorieUser.IncrScore(score)
_, err = calorieUser.IncrScore(activity.ArchId, calorieUser.Id, score)
t.CheckErr(err)
calorieUser.Score += int64(score) // 增加
calorieUser.Score += int(score) // 增加
}
count, err := calorieUser.CountByCalorieId(calorie.Id, activity.RehearsalId)
count, err := calorieUser.CountByCalorieId(calorie.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
users, err := models.GetCalorieUsersByCalorieIdAndScore(calorie.Id, activity.RehearsalId, calorieUser.Score)
users, err := models.GetCalorieUsersByCalorieIdAndScore(calorie.Id, activity.ArchId, activity.RehearsalId, calorieUser.Score)
t.CheckErr(err)
var rank int

85
controllers/client/good.go

@ -3,7 +3,6 @@ package client
import (
"encoding/json"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
pay_service "hudongzhuanjia/services/pay"
@ -11,6 +10,8 @@ import (
"hudongzhuanjia/utils/define"
"strings"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type GoodCtl struct {
@ -18,7 +19,7 @@ type GoodCtl struct {
}
func (t *GoodCtl) GoodDetail() {
goodsId := t.MustGetInt64("customer_goods_id")
goodsId := t.MustGetInt("customer_goods_id")
good := new(models.CustomerGoods)
exist, err := models.Get(good, goodsId)
t.CheckErr(err)
@ -27,7 +28,7 @@ func (t *GoodCtl) GoodDetail() {
}
func (t *GoodCtl) GoodOption() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
option := new(models.CustomerOrderOption)
exist, err := option.GetByActivityId(activityId)
@ -42,18 +43,28 @@ func (t *GoodCtl) GoodOption() {
// 商品列表
func (t *GoodCtl) ListGood() {
activityId := t.MustGetInt64("activity_id")
areaId := t.MustGetInt64("area_id")
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
area := &models.AreaStore{}
exist, err := models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
if area.IsMainArea != 1 && area.AreaGoodsRuleSwitch != 1 {
exist, err = area.GetMainAreaById(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
}
option := new(models.CustomerOrderOption)
exist, err := option.GetByActivityId(activityId)
exist, err = option.GetByActivityId(activityId)
t.CheckErr(err)
if !exist {
t.JSON([]interface{}{})
return
}
goods, err := models.GetGoodsByActivityId(activityId, areaId)
goods, err := models.GetGoodsByActivityId(activityId, area.Id)
t.CheckErr(err)
for index := range goods {
@ -65,10 +76,10 @@ func (t *GoodCtl) ListGood() {
}
func (t *GoodCtl) ListOrder() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
status := t.MustGet("status")
areaId := t.MustGetInt64("area_id")
uid := t.MustGetUID()
areaId := t.MustGetInt("area_id")
uid := t.GetAccountId()
statusList := strings.Split(status, ",")
@ -86,19 +97,19 @@ func (t *GoodCtl) ListOrder() {
}
orders, err := models.GetCustomerOrdersByActivityId(uid, activity.Id, activity.RehearsalId,
areaId, statusList, t.Page, t.PageSize)
areaId, statusList, t.Page, t.PageSize, activity.ArchId)
t.CheckErr(err)
orderNos := make([]string, 0)
orderIds := make([]int, 0)
for _, order := range orders {
orderNos = append(orderNos, order.OrderNo)
orderIds = append(orderIds, order.Id)
}
subs, err := models.GetCustomerOrderSubsByOrderNos(orderNos...)
subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds)
t.CheckErr(err)
for index, order := range orders {
order.ServicePhone = option.MainServicePhone
for _, sub := range subs {
if order.OrderNo == sub["order_no"] {
if order.Id == sub.OrderId {
orders[index].SubOrders = append(orders[index].SubOrders, sub)
}
}
@ -107,8 +118,8 @@ func (t *GoodCtl) ListOrder() {
}
type OrderParam struct {
ActivityId int64 `json:"activity_id"`
AreaId int64 `json:"area_id"`
ActivityId int `json:"activity_id"`
AreaId int `json:"area_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Address string `json:"address"`
@ -117,13 +128,13 @@ type OrderParam struct {
// 下订单
func (t *GoodCtl) Order() {
userId := t.MustGetUID() //
userId := t.GetAccountId() //
param := OrderParam{}
if t.Request.OriginRequest.Method == "POST" {
t.CheckErr(t.Bind(&param))
} else if t.Request.OriginRequest.Method == "GET" {
param.ActivityId = t.MustGetInt64("activity_id")
param.AreaId = t.MustGetInt64("area_id")
param.ActivityId = t.MustGetInt("activity_id")
param.AreaId = t.MustGetInt("area_id")
param.Name = t.MustGet("name")
param.Phone = t.MustGet("phone")
param.Address = t.MustGet("address")
@ -173,7 +184,7 @@ func (t *GoodCtl) Order() {
// 检测库存
for _, good := range goods {
for _, g := range param.Goods {
if good.Id == int64(g["id"]) {
if good.Id == int(g["id"]) {
if good.Stock-g["num"] < 0 {
session.Rollback()
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
@ -188,7 +199,6 @@ func (t *GoodCtl) Order() {
IsDelete: false,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
OrderNo: "",
GoodsId: good.Id,
GoodsNum: g["num"],
GoodName: good.Name,
@ -201,13 +211,6 @@ func (t *GoodCtl) Order() {
}
var expireAt = time.Now().Add(30 * time.Second).Unix()
res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid, int64(price+int(option.PostFee*100)),
4, userId, activity.Id, expireAt)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
count, err := session.Where("is_delete=0").Count(&models.CustomerOrder{})
if err != nil {
session.Rollback()
@ -217,22 +220,38 @@ func (t *GoodCtl) Order() {
order := models.CustomerOrder{
OrderNo: fmt.Sprint(define.DefaultOrderNo + int(count)),
ActivityId: activity.Id,
ArchId: activity.ArchId,
AreaId: area.Id,
AreaName: area.Name,
RehearsalId: activity.RehearsalId,
OutTradeNo: res["out_trade_no"].(string),
BuyerId: user.Id,
TotalAmount: float64(price)/100 + option.PostFee,
PayAmount: float64(price)/100 + option.PostFee,
Status: 0,
Status: 1,
Type: 1, // 直播订单
Receiver: param.Name,
Address: param.Address,
Phone: param.Phone,
GoodsId: subOrders[0].GoodsId,
GoodsName: subOrders[0].GoodName,
IsDrawCash: 0,
ExpireTime: expireAt,
Postage: option.PostFee,
}
amount := price + int(option.PostFee*100)
res := make(map[string]interface{})
if amount > 0.00 {
res, err = pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid, amount, 4, userId,
activity.Id, expireAt)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
order.OutTradeNo = res["out_trade_no"].(string)
order.Status = 0
}
_, err = session.InsertOne(&order)
if err != nil {
session.Rollback()
@ -242,7 +261,7 @@ func (t *GoodCtl) Order() {
// 批量插入
beans := make([]interface{}, 0)
for _, subOrder := range subOrders {
subOrder.OrderNo = order.OrderNo
subOrder.OrderId = order.Id
beans = append(beans, subOrder)
}
session.Insert(beans...)
@ -261,7 +280,6 @@ func (t *GoodCtl) Order() {
// 为支付的重新支付
func (t *GoodCtl) Reorder() {
outTradeNo := t.MustGet("out_trade_no")
res, err := pay_service.ReOrder(outTradeNo)
t.CheckErr(err)
t.JSON(res)
@ -271,7 +289,6 @@ func (t *GoodCtl) Reorder() {
// 申请退款
func (t *GoodCtl) RefundOrder() {
outTradeNo := t.MustGet("out_trade_no")
order := new(models.CustomerOrder)
exist, err := order.GetByOutTradeNO(outTradeNo)
t.CheckErr(err)

16
controllers/client/invite_envelope.go

@ -12,9 +12,9 @@ type InvitationLetterCtl struct {
}
func (t *InvitationLetterCtl) Invite() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
invitationId := t.MustGetInt64("invitation_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
invitationId := t.MustGetInt("invitation_id")
answer := t.MustGet("answer")
activity := new(models.Activity)
@ -23,7 +23,7 @@ func (t *InvitationLetterCtl) Invite() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
letter := new(models.InvitationLetter)
exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
exist, err = letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
@ -32,18 +32,18 @@ func (t *InvitationLetterCtl) Invite() {
letter.InvitationId = invitationId
letter.RehearsalId = activity.RehearsalId
letter.ExtraData = answer
letter.ArchId = activity.ArchId
letter.IsDelete = false
letter.CreatedAt = time.Now()
letter.UpdatedAt = time.Now()
_, err = models.Add(letter)
t.CheckErr(err)
t.SUCCESS("success")
}
func (t *InvitationLetterCtl) Setting() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
uid := t.GetAccountId()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -51,7 +51,7 @@ func (t *InvitationLetterCtl) Setting() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
letter := new(models.InvitationLetter)
exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")

41
controllers/client/live.go

@ -2,7 +2,6 @@ package client
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/filter"
"hudongzhuanjia/libs/im"
@ -14,6 +13,8 @@ import (
"hudongzhuanjia/utils/define"
"sync"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
// 轮询接口
@ -26,7 +27,7 @@ func QueryOnline() error {
if err != nil {
return err
}
liveIds := make([]int64, 0)
liveIds := make([]int, 0)
for _, live := range lives { // 查询在线人数
liveIds = append(liveIds, live.Id)
}
@ -35,7 +36,7 @@ func QueryOnline() error {
return err
}
var idm = make(map[int64][]string, 0)
var idm = make(map[int][]string, 0)
for _, live := range lives {
for _, viewer := range viewers {
if live.Id == viewer.LiveConfigId {
@ -50,7 +51,7 @@ func QueryOnline() error {
wg.Add(len(idm))
var errs []error
for lid, ids := range idm {
go func(int64, []string) {
go func(int, []string) {
defer func() { recover() }()
defer wg.Done()
res, err := im.QueryState(ids)
@ -79,8 +80,8 @@ type LiveCtl struct {
// 详情
func (t *LiveCtl) Detail() {
activityId := t.MustGetInt64("activity_id")
areaId := t.MustGetInt64("area_id")
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
@ -123,7 +124,7 @@ func (t *LiveCtl) Detail() {
}
func (t *LiveCtl) Like() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
_, err := new(models.LiveConfig).Like(activityId)
t.CheckErr(err)
@ -139,7 +140,7 @@ func (t *LiveCtl) Like() {
}
func (t *LiveCtl) LoopQuery() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
t.CheckErr(err)
@ -153,14 +154,14 @@ func (t *LiveCtl) LoopQuery() {
// 下单发送红包
// 维护一个队列进行循环, 遍历是否付款成功
func (t *LiveCtl) SendLiveRedPack() {
userId := t.MustGetUID() // 用户 uid
activityId := t.MustGetInt64("activity_id") // activity_id
userId := t.GetAccountId() // 用户 uid
activityId := t.MustGetInt("activity_id") // activity_id
num := t.MustGetInt("num") // 红包数量
prompt := t.MustGet("prompt") // 提示
amount := utils.Float64CusDecimal(t.MustGetDouble("amount"), 2) // 金额
areaId := t.MustGetInt64("area_id")
areaId := t.MustGetInt("area_id")
if amount/float64(num) < 1 && amount/float64(num) > 200 { // 平均每个红包不得小于0.3
if amount/float64(num) < 1 || amount/float64(num) > 200 { //
t.ERROR("每个红包的平均金额必须在1.00元到200.00元之间", code.MSG_ERR)
return
}
@ -175,7 +176,7 @@ func (t *LiveCtl) SendLiveRedPack() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int64(amount*100),
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int(amount*100),
3, userId, activityId, time.Now().Add(1*time.Hour).Unix())
t.CheckErr(err)
@ -201,6 +202,7 @@ func (t *LiveCtl) SendLiveRedPack() {
ShakeRedEnvelopeType: 1,
ShakeRedEnvelopeRuleId: rule.Id,
AreaId: areaId,
ArchId: activity.ArchId,
Name: user.Nickname + "发红包",
UserId: user.Id,
Amount: utils.Float64CusDecimal(float64(v)/float64(100), 2),
@ -217,8 +219,8 @@ func (t *LiveCtl) SendLiveRedPack() {
// 领取红包
func (t *LiveCtl) GetLiveRedPack() {
ruleId := t.MustGetInt64("live_red_envelope_rule_id")
userId := t.MustGetUID()
ruleId := t.MustGetInt("live_red_envelope_rule_id")
userId := t.GetAccountId()
rule := new(models.LiveRedEnvelopeRule)
exist, err := models.Get(rule, ruleId)
@ -226,13 +228,18 @@ func (t *LiveCtl) GetLiveRedPack() {
t.Assert(exist, code.MSG_SHAKERB_RULE_NOT_EXIST, "红包规则不存在")
t.Assert(rule.Status == 1, code.MSG_SHAKERB_RULE_NOT_EXIST, "红包规则尚未生效")
activity := &models.Activity{}
exist, err = models.Get(activity, rule.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
user := models.User{}
exist, err = models.Get(&user, userId)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "不存在用户")
record := new(models.ShakeRedEnvelopeRecord)
exist, err = record.GetByRuleId(ruleId, rule.RehearsalId, 1)
exist, err = record.GetByRuleId(ruleId, rule.RehearsalId, 1, activity.ArchId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SHAKERB_RECORD_NOT_HIT, "红包领完了")
@ -251,5 +258,3 @@ func (t *LiveCtl) GetLiveRedPack() {
models.Update(record.Id, record, "mch_billno", "is_draw")
t.JSON(record)
}
// 订单

203
controllers/client/login.go

@ -2,7 +2,6 @@ package client
import (
"fmt"
mpoauth2 "github.com/chanxuehong/wechat/mp/oauth2"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/libs/jwt"
@ -10,9 +9,12 @@ import (
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
mpoauth2 "github.com/chanxuehong/wechat/mp/oauth2"
)
//用户
@ -24,60 +26,68 @@ type UserCtl struct {
func (t *UserCtl) EntryLogin() {
account := t.MustGet("account")
password := t.MustGet("password")
activityId := t.MustGetInt64("activity_id") // 需要获取
activityId := t.MustGetInt("activity_id") // 需要获取
entryPeople := new(models.OrderEntryPerson)
exist, err := entryPeople.Auth(account, password, activityId)
entry := new(models.OrderEntryPerson)
exist, err := entry.Auth(account, password, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
activity := new(models.Activity)
exist, err = activity.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := new(models.AreaStore)
exist, err = models.Get(area, entryPeople.AreaId)
exist, err = area.Get(area, entry.AreaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
t.ERROR("用户密码不存在", code.MSG_ERR_LOGIN_ERR)
}
customer := new(models.Customer)
exist, err = models.Get(customer, entryPeople.Pid)
exist, err = customer.Get(customer, entry.Pid)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
// 怎讲activity
token, err := jwt.GenJwtToken("entry", entryPeople.Id, customer.Id, customer.Pid, entryPeople.AreaId, entryPeople.ActivityId)
//token, err := jwt.GenJwtToken(define.TYPE_ENTRYPEOPLE, entry.Id, customer.Id, customer.Pid, entry.AreaId, entry.ActivityId)
//t.CheckErr(err)
if entry.Token == "" {
entry.Token = utils.GenToken(entry.Name)
}
entry.AreaName = area.Name
entry.ActivityName = activity.Name
entry.IsSpecial = customer.IsSpecial
_, err = entry.Update(entry, entry.Id)
t.CheckErr(err)
t.SetSession(define.TOKEN, token)
entryPeople.Token = token
entryPeople.AreaName = area.Name
entryPeople.ActivityName = activity.Name
entry.Token = fmt.Sprintf("%s:%s", define.TYPE_ENTRYPEOPLE, entry.Token)
t.SetSession(define.TOKEN, entry.Token)
t.JSON(map[string]interface{}{
"people": entryPeople,
"people": entry,
"more_area_mode": activity.MoreAreaMode,
})
}
func (t *UserCtl) WxLogin() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
wxcode := t.MustGet("code")
logger.Error("微信code:", wxcode)
activity, exist, err := activity_service.GetActivityById(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
customerId := t.DefaultInt64("customer_id", activity.CustomerId)
customer := new(models.Customer)
exist, err = models.Get(customer, customerId)
exist, err = models.Get(customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
area := new(models.AreaStore)
if customer.Pid == 0 {
exist, err = area.GetMainAreaById(activityId)
} else {
exist, err = area.GetAreaStoreById(customer.AreaId)
}
exist, err = area.GetByCustomerId(customer.Id, activity.Id)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
@ -92,18 +102,12 @@ func (t *UserCtl) WxLogin() {
user := new(models.User)
exist, err = user.GetUserByOpenid(info.OpenId)
t.CheckErr(err)
user.ActivityId = activityId
user.AreaId = area.Id
user.AreaName = area.Name
if user.Token == "" {
user.Token = utils.GenToken(user.Openid)
}
user.Nickname = info.Nickname
user.Openid = info.OpenId
user.Gender = func() string {
if info.Sex == 1 {
return "男"
}
return "女"
}()
user.Gender = utils.GetGender(info.Sex)
user.Avatar = info.HeadImageURL
user.Unionid = info.UnionId
user.City = info.City
@ -112,33 +116,61 @@ func (t *UserCtl) WxLogin() {
user.CreatedAt = time.Now()
user.UpdatedAt = time.Now()
if !exist {
_, err = models.Add(user)
_, err = user.Add(user)
} else {
_, err = user.SaveUserInfo(user.Id)
_, err = user.Update(user, user.Id)
}
t.CheckErr(err)
// 校验邀请函是否开启
invitation := new(models.Invitation)
exist, err = invitation.GetInvitationByActivityId(activityId)
t.CheckErr(err)
//t.Assert(exist, code.MSG_INVITE_SETTING_NOT_EXIST, "邀请函设置不存在")
if exist { // 存在邀请函
letter := new(models.InvitationLetter)
exist, err = letter.GetByUserIdAndActivityId(user.Id, activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您尚未接受过邀请")
}
sign := new(models.SignUp)
exist, err = sign.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
history := new(models.SignHistory)
signExist, err := history.GetByUserId(activityId, user.Id, activity.RehearsalId, area.Id)
signExist, err := history.GetByUserId(activityId, activity.ArchId, user.Id, activity.RehearsalId, area.Id)
t.CheckErr(err)
var signIn = "未签到"
if signExist && history.Status == 2 { // 存在数据
if customer.IsSpecial == 1 {
if signExist {
history = new(models.SignHistory)
history.UserId = user.Id
history.RehearsalId = activity.RehearsalId
history.ActivityId = activityId
history.SignRuleId = sign.Id
history.AreaId = area.Id
history.ArchId = activity.ArchId
history.Status = 2
_, err = models.Add(history)
t.CheckErr(err)
}
signIn = "已签到"
} else {
if signExist && history.Status == 2 { // 存在数据
signIn = "已签到"
}
}
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, customer.Id, customer.Pid, area.Id, activityId)
t.CheckErr(err)
t.SetSession(define.TOKEN, jwtToken)
//jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId)
//t.CheckErr(err)
user.Token = fmt.Sprintf("%s:%s", define.TYPE_USER, user.Token)
t.SetSession(define.TOKEN, user.Token)
t.JSON(map[string]interface{}{
"user": user,
"token": jwtToken,
"token": user.Token,
"activity": activity,
"sign_in": signIn,
"sign": signExist,
@ -151,37 +183,92 @@ func (t *UserCtl) WxLogin() {
func (t *UserCtl) Login() {
wxcode := t.MustGet("code")
// _type, _ := t.Get("type")
user := new(models.User)
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := &models.AreaStore{}
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "此直播间已被删除")
if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
t.ERROR("多地区功能关闭,链接失效,请打开后再试", code.MSG_AREASTORE_CLOSED)
}
token, err := wechat.GetToken(wxcode)
t.CheckErr(err)
user.Openid = token.OpenId
exist, err := user.GetUserByOpenid(user.Openid)
info, err := wechat.GetUserInfo(token)
t.CheckErr(err)
user := new(models.User)
exist, err = user.GetUserByOpenid(info.OpenId)
t.CheckErr(err)
if user.Token == "" {
user.Token = utils.GenToken(user.Openid)
}
user.Nickname = info.Nickname
user.Openid = info.OpenId
user.Gender = utils.GetGender(info.Sex)
user.Avatar = info.HeadImageURL
user.Unionid = info.UnionId
user.City = info.City
user.Province = info.Province
user.Country = info.Country
user.CreatedAt = time.Now()
user.UpdatedAt = time.Now()
if !exist {
_, err = models.Add(user)
t.CheckErr(err)
_, err = user.Add(user)
} else {
_, err = user.Update(user, user.Id)
}
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0)
t.CheckErr(err)
t.SetSession(define.TOKEN, jwtToken)
admin := 0
if username, ok := t.Get("username"); ok && username != "" {
username := t.MustGet("username")
password := t.MustGet("password")
exist, err := area.Login(activityId, username, password)
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR_LOGIN_ERR, "不存在地区管理员")
if area.UserId != user.Id {
area.UserId = user.Id
_, err = models.Update(area.Id, area, "user_id")
t.CheckErr(err)
}
admin = 1
} else {
exist, err := area.GetByUserId(activityId, user.Id)
t.CheckErr(err)
if exist { // 管理员
admin = 1
}
}
//jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, 0, 0, 0, 0)
//t.CheckErr(err)
user.Token = fmt.Sprintf("%s:%s", define.TYPE_LIVEUSER, user.Token)
t.SetSession(define.TOKEN, user.Token)
sign, err := im.AccountImport(fmt.Sprintf("%d", user.Id), user.Nickname, user.Avatar)
t.CheckErr(err)
user.Sig = sign
t.JSON(map[string]interface{}{
"user": user,
"token": jwtToken,
"token": user.Token,
"area": area,
"admin": admin,
})
}
// 模拟wx login
func (t *UserCtl) DebugLogin() {
uid := t.DefaultInt64("user_id", 1)
customerId := t.DefaultInt64("customer_id", 1)
activityId := t.DefaultInt64("activity_id", 5)
uid := t.DefaultInt("user_id", 1)
customerId := t.DefaultInt("customer_id", 1)
activityId := t.DefaultInt("activity_id", 5)
user := new(models.User)
exist, err := models.Get(user, uid)
@ -202,7 +289,7 @@ func (t *UserCtl) DebugLogin() {
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
jwtToken, err := jwt.GenJwtToken("user", user.Id, customer.Id, customer.Pid, area.Id, activityId)
jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId)
t.CheckErr(err)
t.SetSession(define.TOKEN, jwtToken)
t.JSON(map[string]interface{}{
@ -216,7 +303,7 @@ type UserAuthCtl struct {
}
func (t *UserAuthCtl) SaveUserInfo() {
uid := t.MustGetUID()
uid := t.GetAccountId()
info := mpoauth2.SessionInfo{}
t.RequestToStruct(&info)

53
controllers/client/lottery.go

@ -14,8 +14,8 @@ type LotteryCtl struct {
}
func (t *LotteryCtl) UserLotteries() {
userId := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
userId := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -32,8 +32,8 @@ func (t *LotteryCtl) UserLotteries() {
}
func (t *LotteryCtl) CashLottery() {
uid := t.MustGetUID()
prizeId := t.MustGetInt64("prize_id")
uid := t.GetAccountId()
prizeId := t.MustGetInt("prize_id")
name := t.MustGet("name")
phone := t.MustGet("phone")
wxNo := t.MustGet("wx_no")
@ -49,8 +49,8 @@ func (t *LotteryCtl) CashLottery() {
exist, err := record.GetByUserPrizeId(prizeId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在")
record.Name = name
record.Phone = phone
record.UserName = name
record.UserPhone = phone
record.WxNo = wxNo
record.Address = address
record.Status = 1
@ -60,16 +60,31 @@ func (t *LotteryCtl) CashLottery() {
}
func (t *LotteryCtl) CheckLottery() {
uid := t.MustGetUID()
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
uid := t.GetAccountId()
ladderId := t.MustGetInt("lottery_draw_ladder_id")
ladder := new(models.LotteryDrawRuleLadder)
ladder := &models.LotteryDrawRuleLadder{}
exist, err := models.Get(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
rule := &models.LotteryDrawRule{}
exist, err = models.Get(rule, ladder.LotteryDrawRuleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
lottery := &models.LotteryDrawActivity{}
exist, err = models.Get(lottery, rule.LotteryDrawActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, lottery.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
record := new(models.LotteryDrawRecord)
exist, err = record.GetByUserIdAndLadderId(uid, ladderId, ladder.RollNum)
exist, err = record.GetByUserIdAndLadderId(uid, ladderId, activity.ArchId, ladder.RollNum)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"record": record,
@ -80,8 +95,8 @@ func (t *LotteryCtl) CheckLottery() {
//获取中奖名单
func (t *LotteryCtl) Winners() {
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -93,7 +108,7 @@ func (t *LotteryCtl) Winners() {
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
result, err := lottery_service.GetLotteryUsersResultByRollNum(ladderId, activity.RehearsalId, ladder.RollNum)
result, err := lottery_service.GetLotteryUsersResultByRollNum(ladderId, activity.RehearsalId, activity.ArchId, ladder.RollNum)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
@ -104,9 +119,9 @@ func (t *LotteryCtl) Winners() {
// 抽奖用户
func (t *LotteryCtl) Users() {
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
areaId := t.MustGetInt64("area_id")
activityId := t.MustGetInt("activity_id")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
areaId := t.MustGetInt("area_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -122,14 +137,14 @@ func (t *LotteryCtl) Users() {
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
recordIds := make([]int64, 0)
recordIds := make([]int, 0)
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
// 去重标志
recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId)
recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId, activity.ArchId)
t.CheckErr(err)
}
result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, recordIds)
result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, activity.ArchId, recordIds)
t.CheckErr(err)
t.JSON(map[string]interface{}{

554
controllers/client/order_entry.go

@ -1,15 +1,14 @@
package client
import (
"encoding/json"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/helper"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
invitation_service "hudongzhuanjia/services/invitation"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
"strings"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
@ -18,20 +17,32 @@ type OrderEntryCtl struct {
controllers.AuthorCtl
}
// 商品 == > 用户查看所有商品
// 用户查看所有商品
func (t *OrderEntryCtl) List() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
goods := make([]*models.CustomerGoods, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Asc("created_at").Find(&goods)
t.CheckErr(err)
for index := range goods {
url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+
"user_id=%d&activity_id=%d&good_id=%d", define.HOST, uid, activityId, goods[index].Id)
qrcode, err := utils.Qrcode2Base64(url)
_type := t.GetAccountType()
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
areaId := 0
if _type == define.TYPE_ENTRYPEOPLE {
entryPerson := models.OrderEntryPerson{}
exist, err := models.Get(&entryPerson, uid)
t.CheckErr(err)
goods[index].Qrcode = qrcode
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员信息异常")
areaId = entryPerson.AreaId
} else {
areaId = t.MustGetInt("area_id")
}
goods, err := models.GetGoodsByActivityId(activityId, areaId)
t.CheckErr(err)
if _type == define.TYPE_USER {
for index := range goods {
url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+
"user_id=%d&activity_id=%d&good_id=%d", define.HOST, uid, activityId, goods[index].Id)
qrcode, err := utils.Qrcode2Base64(url)
t.CheckErr(err)
goods[index].Qrcode = qrcode
}
}
t.JSON(map[string]interface{}{
@ -40,168 +51,483 @@ func (t *OrderEntryCtl) List() {
})
}
// 下订单 == > 二维码跳转
// 扫二维码下单
func (t *OrderEntryCtl) Order() {
userId := t.MustGetInt64("user_id")
activityId := t.MustGetInt64("activity_id")
goodId := t.MustGetInt64("good_id")
entryId := t.MustGetUID()
userId := t.MustGetInt("user_id")
goodId := t.MustGetInt("good_id")
entryId := t.GetAccountId()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
entryPerson := models.OrderEntryPerson{}
exist, err := models.Get(&entryPerson, entryId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
activity := models.Activity{}
exist, err = models.Get(&activity, entryPerson.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
entryPerson := new(models.OrderEntryPerson)
exist, err = models.Get(entryPerson, entryId)
area := models.AreaStore{}
exist, err = models.Get(&area, entryPerson.AreaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
area := new(models.AreaStore)
exist, err = area.GetAreaStoreById(entryPerson.AreaId)
letter := &models.InvitationLetter{}
exist, err = letter.GetByUserIdAndActivityId(userId, activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "邀请函不存在")
good := new(models.CustomerGoods)
exist, err = models.Get(good, goodId)
values := make([]map[string]interface{}, 0)
err = json.Unmarshal([]byte(strings.Trim(letter.ExtraData, `"`)), &values)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "商品不存在")
var name, phone, address = "", "", ""
for _, value := range values {
if value["name"] == "姓名" {
name = fmt.Sprint(value["val"])
} else if value["name"] == "手机" {
phone = fmt.Sprint(value["val"])
} else if value["name"] == "地址" {
address = fmt.Sprint(value["val"])
}
}
s := core.GetXormAuto().NewSession()
defer s.Close()
err = s.Begin()
if err != nil {
s.Rollback()
t.CheckErr(err)
}
session := core.GetXormAuto().NewSession()
defer session.Close()
session.Begin()
good := models.CustomerGoods{}
exist, err = s.Where("is_delete=0 and id=?", goodId).Get(&good)
if err != nil || !exist {
s.Rollback()
t.ERROR("商品信息异常", code.MSG_ERR_Param)
return
}
// 找出商品库存
ms := make([]map[string]int, 0)
err = s.Table(&models.CustomerOrderSub{}).Select("goods_id, sum(goods_num) as goods_num").
Where("goods_id=?", good.Id).GroupBy("goods_id").Find(&ms)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
for _, m := range ms {
if m["goods_id"] == int(good.Id) && m["goods_num"] >= good.Stock {
s.Rollback()
t.ERROR(good.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
return
}
}
gift := new(models.OrderGift)
exist, err = session.Where("is_delete=0 and activity_id=?", activityId).Get(gift)
order := models.CustomerOrder{}
// 查询库存
total, err := s.Where("is_delete=0").Count(&order) // 订单总数
if err != nil {
session.Rollback()
s.Rollback()
t.CheckErr(err)
}
prize := new(models.UserPrize)
prize.UserId = userId
prize.ActivityId = activityId
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.PrizeName = gift.GiftName
prize.PrizeImg = gift.GiftPicUrl
prize.PrizeType = 3
prize.IsDelete = false
prize.CreatedAt = time.Now()
prize.UpdatedAt = time.Now()
order.AreaId = entryPerson.AreaId
order.ArchId = activity.ArchId
order.AreaName = area.Name
order.BuyerId = userId
order.Type = 0
order.ActivityId = activity.Id
order.RehearsalId = activity.RehearsalId
order.OrderEntryPersonId = entryPerson.Id
order.OrderEntryPersonName = entryPerson.Name
order.TotalAmount = good.Price
order.Receiver = name
order.Phone = phone
order.Address = address
order.GoodsName = good.Name
order.GoodsId = good.Id
order.GoodsNum = 1
order.OutTradeNo = utils.RandomStr(32)
order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(total))
order.Status = 1
_, err = s.InsertOne(&order)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
sub := models.CustomerOrderSub{}
sub.GoodsId = good.Id
sub.GoodName = good.Name
sub.GoodPrice = good.Price
sub.GoodsNum = 1
sub.OrderId = order.Id
_, err = models.Add(&sub) // 存入子订单
if err != nil {
s.Rollback()
t.CheckErr(err)
}
gift := models.OrderGift{}
exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
if exist {
prize := models.UserPrize{}
prize.UserId = userId
prize.ActivityId = activity.Id
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.PrizeName = gift.GiftName
prize.PrizeImg = gift.GiftPicUrl
prize.ArchId = activity.ArchId
prize.CustomerOrderId = order.Id
prize.PrizeType = 3
if gift.Num == 0 {
_, err = session.InsertOne(prize)
_, err = s.InsertOne(&prize)
if err != nil {
session.Rollback()
s.Rollback()
t.CheckErr(err)
}
} else if gift.Num > 0 {
count, err := core.GetXormAuto().Where("activity_id=? and rehearsal_id=? and is_delete=0",
activityId, activity.RehearsalId).Count(new(models.CustomerOrder))
count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
if err != nil {
session.Rollback()
s.Rollback()
t.CheckErr(err)
}
if gift.Num > int(count) {
_, err = session.InsertOne(prize)
if gift.Num >= int(count) { // 大于等于
_, err = s.InsertOne(&prize)
if err != nil {
session.Rollback()
s.Rollback()
t.CheckErr(err)
}
}
}
if prize.Id > 0 {
order.UserPrizeId = prize.Id
_, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
}
}
order := new(models.CustomerOrder)
order.UserPrizeId = prize.Id
err = s.Commit()
if err != nil {
s.Rollback()
t.CheckErr(err)
}
t.SUCCESS("成功录入订单")
}
// 手动下单
type ManualOrderGood struct {
GoodId int `json:"good_id"`
GoodNum int `json:"good_num"`
}
type ManualOrderParam struct {
Name string `json:"name"`
Phone string `json:"phone"`
Goods []*ManualOrderGood `json:"goods"`
}
func (t *OrderEntryCtl) ManualOrder() {
entryId := t.GetAccountId() // 录入人员id
param := &ManualOrderParam{}
t.Bind(param)
param.Goods = make([]*ManualOrderGood, 0)
err := json.Unmarshal([]byte(t.Request.REQUEST["goods"]), &param.Goods)
t.CheckErr(err)
if len(param.Goods) <= 0 {
t.ERROR("商品不能为空", code.MSG_CUSTOMER_GOOD_NOT_EXIST)
return
}
entryPerson := models.OrderEntryPerson{}
exist, err := models.Get(&entryPerson, entryId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
activity := models.Activity{}
exist, err = models.Get(&activity, entryPerson.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
area := models.AreaStore{}
exist, err = models.Get(&area, entryPerson.AreaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
goodIds := make([]int, 0)
for _, g := range param.Goods {
goodIds = append(goodIds, g.GoodId)
}
s := core.GetXormAuto().NewSession()
defer s.Close()
err = s.Begin()
if err != nil {
s.Rollback()
t.CheckErr(err)
}
user := models.User{}
exist, err = s.Where("is_delete=0 and phone=?", param.Phone).NoAutoCondition().Get(&user)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
if !exist {
user.Phone = param.Phone
user.Nickname = param.Name
user.Password = utils.RandomStr(8)
_, err = s.InsertOne(&user)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
}
// 校验库存
goods := make([]*models.CustomerGoods, 0)
err = s.Where("is_delete=0").In("id", goodIds).Find(&goods)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
if len(goods) != len(param.Goods) {
s.Rollback()
t.ERROR("商品信息异常", code.MSG_ERR_Param)
return
}
subs := make([]*models.CustomerOrderSub, 0)
totalAmount := 0.00
goodNum := 0
for _, g := range param.Goods {
for _, good := range goods {
if g.GoodId == good.Id {
subs = append(subs, &models.CustomerOrderSub{
GoodsId: good.Id,
GoodsNum: g.GoodNum,
GoodName: good.Name,
GoodPrice: good.Price,
})
totalAmount += good.Price * float64(g.GoodNum)
goodNum += g.GoodNum
}
}
}
ms := make([]map[string]int, 0)
err = s.Table(&models.CustomerOrderSub{}).Alias("s").Select("s.goods_id, COALESCE(SUM(s.goods_num), 0) as goods_num").
Join("left", (&models.CustomerOrder{}).Alias("o"), "o.id=s.order_id").
Where("o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", activity.Id, activity.RehearsalId, activity.ArchId).
In("s.goods_id", goodIds).GroupBy("s.goods_id").Find(&ms)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
for _, m := range ms {
for _, g := range goods {
if g.Stock == -1 { // 无上限
break
}
if m["goods_id"] == int(g.Id) && m["goods_num"] >= g.Stock {
s.Rollback()
t.ERROR(g.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
return
}
}
}
order := models.CustomerOrder{}
count, err := s.Where("is_delete=0").Count(&order) // 查看订单所在
if err != nil {
s.Rollback()
t.CheckErr(err)
}
order.AreaId = entryPerson.AreaId
order.AreaName = area.Name
order.BuyerId = userId
order.GoodsId = goodId
order.ArchId = activity.ArchId
order.BuyerId = user.Id
order.Type = 0
order.ActivityId = activityId
order.ActivityId = activity.Id
order.RehearsalId = activity.RehearsalId
order.OrderEntryPersonId = entryPerson.Id
order.GoodsName = good.Name
order.TotalAmount = good.Price
order.OutTradeNo = helper.CreateUUID()
order.IsDelete = false
order.UpdatedAt = time.Now()
order.CreatedAt = time.Now()
_, err = session.InsertOne(order)
order.OrderEntryPersonName = entryPerson.Name
order.TotalAmount = totalAmount
order.Receiver = param.Name
order.Phone = param.Phone
order.GoodsNum = goodNum
order.GoodsId = subs[0].GoodsId
order.GoodsName = subs[0].GoodName
order.OutTradeNo = utils.RandomStr(32)
order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(count))
order.Status = 1
_, err = s.InsertOne(&order)
if err != nil {
session.Rollback()
s.Rollback()
t.CheckErr(err)
}
for _, sub := range subs {
sub.OrderId = order.Id
_, err = models.Add(sub) // 存入子订单
if err != nil {
s.Rollback()
t.CheckErr(err)
}
}
err = session.Commit()
t.CheckErr(err)
t.SUCCESS("success")
gift := models.OrderGift{}
exist, err = s.Where("is_delete=0 and activity_id=?", activity.Id).Get(&gift)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
if exist {
prize := models.UserPrize{}
prize.UserId = user.Id
prize.ActivityId = activity.Id
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.PrizeName = gift.GiftName
prize.PrizeImg = gift.GiftPicUrl
prize.ArchId = activity.ArchId
prize.CustomerOrderId = order.Id
prize.PrizeType = 3
if gift.Num == 0 {
_, err = s.InsertOne(&prize)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
} else if gift.Num > 0 {
count, err := s.Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
activity.Id, activity.RehearsalId, activity.ArchId).NoAutoCondition().Count(&order)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
if gift.Num >= int(count) { // 大于等于
_, err = s.InsertOne(&prize)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
}
}
if prize.Id > 0 {
order.UserPrizeId = prize.Id
_, err = s.ID(order.Id).NoAutoCondition().Cols("user_prize_id").Update(&order)
if err != nil {
s.Rollback()
t.CheckErr(err)
}
}
}
err = s.Commit()
if err != nil {
s.Rollback()
t.CheckErr(err)
}
t.SUCCESS("成功录入订单")
}
func (t *OrderEntryCtl) DeleteOrder() {
orderId := t.MustGetInt64("order_id")
orderId := t.MustGetInt("order_id")
order := new(models.CustomerOrder)
exist, err := core.GetXormAuto().Where("is_delete=0 and id=?", orderId).Get(order)
exist, err := models.Get(order, orderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单不存在")
_, err = new(models.CustomerOrder).SoftDeleteById(orderId)
_, err = models.Del(order, order.Id)
t.CheckErr(err)
if order.UserPrizeId != 0 {
_, err = new(models.UserPrize).SoftDeleteById(order.UserPrizeId)
if order.UserPrizeId > 0 {
_, err = models.Del(&models.UserPrize{}, order.UserPrizeId)
t.CheckErr(err)
}
t.SUCCESS("删除成功")
}
type OrderListResult struct {
OrderId int64 `json:"order_id"`
UserId int64 `json:"user_id"`
EntryName string `json:"entry_name"`
GoodName string `json:"good_name"`
OrderTime string `json:"order_time"`
OrderMoney float64 `json:"order_money"`
Extra []map[string]interface{} `json:"extra"` // 额外信息
ExtraData string `json:"-"`
OrderId int `json:"order_id"`
UserId int `json:"user_id"`
EntryName string `json:"entry_name"`
GoodName string `json:"-"`
OrderTime string `json:"order_time"`
OrderMoney float64 `json:"order_money"`
Receiver string `json:"receiver"`
Phone string `json:"phone"`
Address string `json:"address"`
Extra interface{} `json:"extra"` // 额外信息
ExtraData string `json:"-"`
}
func (t *OrderEntryCtl) EntryOrders() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
entry := new(models.OrderEntryPerson)
exist, err := models.Get(entry, uid)
entry := models.OrderEntryPerson{}
exist, err := models.Get(&entry, uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
activity := models.Activity{}
exist, err = models.Get(&activity, entry.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
list := make([]*OrderListResult, 0)
err = core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
Select("l.extra_data as extra_data, g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, "+
" o.id as order_id, DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").
Join("LEFT", new(models.CustomerGoods).Alias("g"),
"o.goods_id=g.id and o.activity_id=g.activity_id and g.is_delete=0").
Join("LEFT", new(models.InvitationLetter).Alias("l"),
"l.user_id = o.buyer_id and o.activity_id=l.activity_id and l.is_delete=0").
Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and o.is_delete=0",
activityId, uid, activity.RehearsalId).Desc("o.created_at").Find(&list)
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
// 添加邀请函的内容
optionItems, err := invitation_service.GetOptionItem(activityId)
list := make([]*OrderListResult, 0)
//if customer.IsSpecial == 0 {
// // 添加邀请函的内容
// err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").
// Select("o.receiver as receiver, o.phone as phone, o.address as address,l.extra_data as extra_data, "+
// " g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, o.id as order_id, "+
// " DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").Join("LEFT",
// (&models.CustomerGoods{}).Alias("g"), "o.goods_id=g.id and o.activity_id=g.activity_id").
// Join("LEFT", (&models.InvitationLetter{}).Alias("l"), "l.user_id = o.buyer_id and o.activity_id=l.activity_id and o.arch_id=l.arch_id and l.is_delete=0").
// Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and o.arch_id=? "+
// " and o.is_delete=0", activity.Id, uid, activity.RehearsalId, activity.ArchId).
// Desc("o.created_at").Find(&list)
// t.CheckErr(err)
// optionItems, err := invitation_service.GetOptionItem(activity.Id)
// t.CheckErr(err)
// for i := range list {
// data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData)
// t.CheckErr(err)
// list[i].Extra = data
// list[i].EntryName = entry.Name
// }
//} else if customer.IsSpecial == 2 {
err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as order_id, "+
" o.receiver as receiver, o.phone as phone, o.address as address, o.buyer_id as user_id, o.order_entry_person_name as entry_name, "+
" o.total_amount as order_money, DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").
Where("o.activity_id=? and o.rehearsal_id=? and o.order_entry_person_id=? and o.arch_id=?",
activity.Id, activity.RehearsalId, uid, activity.ArchId).Desc("o.created_at").Find(&list)
t.CheckErr(err)
orderIds := make([]int, 0)
for _, v := range list {
orderIds = append(orderIds, v.OrderId)
}
subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds)
t.CheckErr(err)
for i := range list {
data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData)
t.CheckErr(err)
list[i].Extra = data
list[i].EntryName = entry.Name
s := make([]interface{}, 0)
for _, sub := range subs {
if sub.OrderId == list[i].OrderId {
s = append(s, sub)
}
}
list[i].Extra = s
}
//}
t.JSON(map[string]interface{}{
"list": list,
@ -217,8 +543,8 @@ type UserOrdersResult struct {
// 用户查看订单列表
func (t *OrderEntryCtl) UserOrders() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -229,8 +555,8 @@ func (t *OrderEntryCtl) UserOrders() {
s := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
Join("LEFT", new(models.CustomerGoods).Alias("g"),
"o.goods_id=g.id and g.is_delete=0").
Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=?",
uid, activity.Id, activity.RehearsalId)
Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
uid, activity.Id, activity.RehearsalId, activity.ArchId)
if t.PageSize > 0 {
s = s.Limit(t.PageSize, t.Page*t.PageSize)
@ -245,9 +571,9 @@ func (t *OrderEntryCtl) UserOrders() {
// 二维码
func (t *OrderEntryCtl) Qrcode() {
userId := t.MustGetInt64("user_id")
activityId := t.MustGetInt64("activity_id")
goodId := t.MustGetInt64("good_id")
userId := t.MustGetInt("user_id")
activityId := t.MustGetInt("activity_id")
goodId := t.MustGetInt("good_id")
Url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?user_id=%d&activity_id=%d&good_id=%d",
define.HOST, userId, activityId, goodId)
qr, err := utils.Qrcode2Base64(Url)

14
controllers/client/reward.go

@ -17,10 +17,10 @@ type RewardCtl struct {
}
func (t *RewardCtl) Reward() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
content := t.MustGet("content")
amount := t.MustGetDouble("amount")
uid := t.MustGetUID()
uid := t.GetAccountId()
_type := t.DefaultInt("type", 0)
if amount <= 0 {
@ -57,7 +57,7 @@ func (t *RewardCtl) Reward() {
var expireAt = time.Now().Add(24 * time.Hour).Unix()
res["out_trade_no"] = ""
if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2,
res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int(amount*100), 2,
user.Id, activityId, expireAt)
t.CheckErr(err)
}
@ -65,6 +65,7 @@ func (t *RewardCtl) Reward() {
history := models.RewardHistory{
OutTradeNo: res["out_trade_no"].(string),
ActivityId: activityId,
ArchId: activity.ArchId,
RewardServerId: rewardServer.Id,
CustomerId: activity.CustomerId,
UserId: user.Id,
@ -83,14 +84,13 @@ func (t *RewardCtl) Reward() {
_, err = models.Add(&history)
t.CheckErr(err)
res["rehearsal_id"] = activity.RehearsalId
t.JSON(res)
}
func (t *RewardCtl) List() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -102,7 +102,7 @@ func (t *RewardCtl) List() {
t.CheckErr(err)
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id)
list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(list),

29
controllers/client/shake_red_envelope.go

@ -18,7 +18,7 @@ type ShakeRedEnvelopeCtl struct {
}
func (t *ShakeRedEnvelopeCtl) Status() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
rule := new(models.ShakeRedEnvelopeRule)
exist, err := models.Get(rule, ruleId)
t.CheckErr(err)
@ -29,9 +29,9 @@ func (t *ShakeRedEnvelopeCtl) Status() {
}
func (t *ShakeRedEnvelopeCtl) Shake() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
userId := t.MustGetUID()
areaId := t.MustGetAreaId()
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
userId := t.GetAccountId()
areaId := t.MustGetInt("area_id")
// 查询摇红包规则
rule := new(models.ShakeRedEnvelopeRule)
@ -70,10 +70,12 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
// done: 增加概率, 修改概率
r := rand.New(rand.NewSource(time.Now().UnixNano()))
t.Assert(r.Float64()*100 <= rule.Probability, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 必须在红包概率以内才能获取
p := r.Float64() * 100
fmt.Println(p)
t.Assert(p <= rule.Probability, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 必须在红包概率以内才能获取
// 增加session 或者乐观锁
exist, err = record.GetByRuleId(ruleId, activity.RehearsalId, 0)
exist, err = record.GetByRuleId(ruleId, activity.RehearsalId, 0, activity.ArchId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SHAKERB_RECORD_NOT_HIT, "红包已经派发完毕")
@ -86,7 +88,8 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
record.IsDraw = 0
record.UserId = userId
record.AreaId = areaId
row, err := models.Update(record.Id, record, "is_draw", "user_id", "area_id")
record.ArchId = activity.ArchId
row, err := models.Update(record.Id, record, "is_draw", "user_id", "area_id", "arch_id")
t.CheckErr(err)
t.Assert(row == 1, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 那么 row == 1 为已经成功抢到
@ -94,9 +97,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
if activity.RehearsalId == 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)
}
t.CheckErr(err)
record.MchBillno = result.MchBillno
models.Update(record.Id, record, "mch_billno")
}
@ -107,7 +108,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
t.CheckErr(err)
go ws_send_service.SendShakeRedEnvelope(fmt.Sprintf("%d", activity.Id),
define.TYPE_H5USER, userId, map[string]interface{}{
define.TYPE_USER, userId, map[string]interface{}{
"customer_id": area.CustomerId,
"user_id": user.Id,
"type": "shake_rb",
@ -142,14 +143,14 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
// 用户红包
func (t *ShakeRedEnvelopeCtl) UserRedEnvelopes() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "活动不存在")
records, err := models.GetRedEnvelopesByUserId(uid, activityId, activity.RehearsalId)
records, err := models.GetRedEnvelopesByUserId(uid, activityId, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"list": records,

129
controllers/client/sign.go

@ -8,7 +8,6 @@ import (
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
)
//签到
@ -17,13 +16,32 @@ type SignCtl struct {
}
func (t *SignCtl) CheckSign() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
uid := t.GetAccountId()
_type := t.MustGetInt("type")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
area := &models.AreaStore{}
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "此直播间已被删除")
if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
t.ERROR("多地区功能关闭,链接失效,请打开后再试", code.MSG_AREASTORE_CLOSED)
}
if _type == 1 {
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
exist, err := live.GetByActivityId(activity.Id)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
if live.LiveMode == 2 {
@ -60,27 +78,8 @@ func (t *SignCtl) CheckSign() {
}
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
area := new(models.AreaStore)
if customer.AreaId == 0 {
exist, err = area.GetMainAreaById(activityId)
} else {
exist, err = area.GetAreaStoreById(customer.AreaId)
}
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
history := new(models.SignHistory)
signExist, err := history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id)
signExist, err := history.GetByUserId(activityId, activity.ArchId, uid, activity.RehearsalId, area.Id)
t.CheckErr(err)
if !signExist || history.Status != 2 {
t.JSON(false)
@ -90,10 +89,24 @@ func (t *SignCtl) CheckSign() {
}
func (t *SignCtl) Setting() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := &models.AreaStore{}
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "此直播间已被删除")
if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
t.ERROR("多地区功能关闭,链接失效,请打开后再试", code.MSG_AREASTORE_CLOSED)
}
service := new(models.ModuleService)
exist, err := service.GetByName(define.MODULE_SIGNIN)
exist, err = service.GetByName(define.MODULE_SIGNIN)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
historyIds, err := models.GetModuleServiceHistoryIdsByIdAndName(service.Id, service.Name)
@ -118,10 +131,10 @@ func (t *SignCtl) Setting() {
//签到动作
func (t *SignCtl) Sign() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
_type := t.DefaultInt("type", 0) // 默认 0
areaId := t.MustGetAreaId()
areaId := t.MustGetInt("area_id")
//根据activity_id查找主活动的信息
activity := new(models.Activity)
@ -153,23 +166,23 @@ func (t *SignCtl) Sign() {
if signUp.OnlyInvitation == 1 && _type == 0 { // 直播不需要进行邀请函
// 邀请函才能签到
letter := new(models.InvitationLetter)
exist, err := letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
exist, err := letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
}
//检查是否已经签到了
history := new(models.SignHistory)
exist, err = history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id)
exist, err = history.GetByUserId(activity.Id, activity.ArchId, uid, activity.RehearsalId, area.Id)
t.CheckErr(err)
if exist || history.Status == 2 {
t.ERROR("您已经签到过了", code.MSG_SIGN_HISTORY_EXIST)
}
// 签到人数
signTotal, err := history.Count(signUp.Id, activity.RehearsalId, activity.Id)
signTotal, err := history.Count(activity.Id, activity.ArchId, activity.RehearsalId, 2)
t.CheckErr(err)
signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.RehearsalId)
signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
if activity.RehearsalId != 0 && signTotal >= 10 {
@ -177,16 +190,13 @@ func (t *SignCtl) Sign() {
}
history = new(models.SignHistory)
history.Type = _type
history.UserId = uid
history.RehearsalId = activity.RehearsalId
history.ActivityId = activityId
history.SignRuleId = signUp.Id
history.AreaId = areaId
history.ArchId = activity.ArchId
history.Status = 2
history.IsDelete = false
history.UpdatedAt = time.Now()
history.CreatedAt = time.Now()
_, err = models.Add(history)
t.CheckErr(err)
@ -205,9 +215,9 @@ func (t *SignCtl) Sign() {
// 实名签到
func (t *SignCtl) RealSign() {
activityId := t.MustGetInt64("activity_id")
userId := t.MustGetUID()
areaId := t.MustGetInt64("area_id")
activityId := t.MustGetInt("activity_id")
userId := t.GetAccountId()
areaId := t.MustGetInt("area_id")
user := new(models.User)
exist, err := models.Get(user, userId)
@ -226,15 +236,15 @@ func (t *SignCtl) RealSign() {
t.Assert(sign.SignMethod == 2, code.MSG_ERR_Param, "非实名签到")
history := new(models.SignHistory)
isSign, err := history.GetByUserId(activityId, userId, activity.RehearsalId, areaId)
isSign, err := history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
t.CheckErr(err)
if isSign && history.Status == 2 {
t.SUCCESS("已通过实名签到")
return
} else if sign.RealSignJsonTitle != nil && len(sign.RealSignJsonTitle) != 0 {
} else if sign.RealSignJsonForm != nil && len(sign.RealSignJsonForm) != 0 {
var params = make(map[string]string, 0)
var extSql string
for _, v := range sign.RealSignJsonTitle {
for _, v := range sign.RealSignJsonForm {
m, ok := v.(map[string]interface{})
if !ok {
continue
@ -257,9 +267,14 @@ func (t *SignCtl) RealSign() {
realSignList := new(models.RealSignList)
exist, err = realSignList.CheckSignIn(activityId, extSql)
t.CheckErr(err)
if exist && realSignList.Status == 1 {
t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST)
return
if exist {
existRsi, err := models.ExistReviewedSignInfo(activity.Id, activity.ArchId,
activity.RehearsalId, realSignList.Id)
t.CheckErr(err)
if existRsi {
t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST)
return
}
}
var body []byte
@ -270,18 +285,20 @@ func (t *SignCtl) RealSign() {
history.ActivityId = activityId
history.UserId = userId
history.Nickname = user.Nickname
history.ArchId = activity.ArchId
history.RehearsalId = activity.RehearsalId
history.AreaId = areaId
history.Content = string(body)
history.RealSignListId = realSignList.Id
if exist { // 存在 直接通过
history.Status = 2
} else {
history.Status = 0
}
if isSign {
err = history.UpdateById([]interface{}{history.Id})
_, err = models.Update(history.Id, history)
} else {
err = history.Insert()
_, err = models.Add(history)
}
t.CheckErr(err)
if !exist { // 找不到导入的签名信息
@ -297,9 +314,9 @@ func (t *SignCtl) RealSign() {
}
func (t *SignCtl) ApplySign() {
userId := t.MustGetUID()
areaId := t.MustGetAreaId()
activityId := t.MustGetInt64("activity_id")
userId := t.GetAccountId()
areaId := t.MustGetInt("area_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -307,7 +324,7 @@ func (t *SignCtl) ApplySign() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
history := new(models.SignHistory)
exist, err = history.GetByUserId(activityId, userId, activity.RehearsalId, areaId)
exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到不存在")
if history.Status == 2 {
@ -322,9 +339,9 @@ func (t *SignCtl) ApplySign() {
}
func (t *SignCtl) CheckRealSign() {
userId := t.MustGetUID()
areaId := t.MustGetInt64("area_id")
activityId := t.MustGetInt64("activity_id")
userId := t.GetAccountId()
areaId := t.MustGetInt("area_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -332,7 +349,7 @@ func (t *SignCtl) CheckRealSign() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
history := new(models.SignHistory)
exist, err = history.GetByUserId(activityId, userId, activity.RehearsalId, areaId)
exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到信息不存在")
if history.Status == 2 {

46
controllers/client/tug_war.go

@ -15,8 +15,8 @@ type TugOfWarCtl struct {
func (t *TugOfWarCtl) Status() {
// 获取此次活动的状态
baheId := t.MustGetInt64("bahe_activity_id")
uid := t.MustGetUID()
baheId := t.MustGetInt("bahe_activity_id")
uid := t.GetAccountId()
// 找到活动
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheId)
@ -31,7 +31,7 @@ func (t *TugOfWarCtl) Status() {
// 找到用户
member := new(models.BaheTeamMember)
exist, err = member.GetMemberByBaheIdAndUserId(uid, bahe.Id, activity.RehearsalId)
exist, err = member.GetMemberByBaheIdAndUserId(activity.ArchId, uid, bahe.Id, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_TUGWAR_MEMBER_NOT_EXIST, "队员不存在")
@ -62,36 +62,34 @@ func (t *TugOfWarCtl) Status() {
}
func (t *TugOfWarCtl) Shake() {
uid := t.MustGetUID()
baheId := t.MustGetInt64("bahe_activity_id")
score := t.MustGetInt64("score") // 增加的分数
uid := t.GetAccountId()
baheId := t.MustGetInt("bahe_activity_id")
score := t.MustGetInt("score") // 增加的分数
bahe := new(models.TugOfWar)
bahe := &models.TugOfWar{}
exist, err := models.Get(bahe, baheId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "拔河活动不存在")
t.CheckRunning(bahe.Status)
activity := new(models.Activity)
activity := &models.Activity{}
exist, err = models.Get(activity, bahe.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
member := new(models.BaheTeamMember)
exist, err = member.GetMemberByBaheIdAndUserId(uid, baheId, activity.RehearsalId)
member := &models.BaheTeamMember{}
exist, err = member.GetMemberByBaheIdAndUserId(activity.ArchId, uid, baheId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR, "该用户尚未加入队伍")
if score != 0 {
_, err = member.IncrScoreById(member.Id, score)
if bahe.Status == define.StatusRunning && score > 0 { // 增加分数
_, err = member.IncrScoreById(activity.ArchId, member.Id, score)
t.CheckErr(err)
member.Score += score
}
// 根据team_id 获取所有成员的分数
members := make([]*models.BaheTeamMember, 0)
err = models.GetBaheMembersByTeamId(members, member.TeamId, member.RehearsalId)
members, err := models.GetBaheMembersByTeamId(member.TeamId, member.RehearsalId)
t.CheckErr(err)
var rank int
@ -109,16 +107,21 @@ func (t *TugOfWarCtl) Shake() {
}
func (t *TugOfWarCtl) JoinTeam() {
teamId := t.MustGetInt64("bahe_team_id")
baheActivityId := t.MustGetInt64("bahe_activity_id")
uid := t.MustGetUID()
teamId := t.MustGetInt("bahe_team_id")
baheActivityId := t.MustGetInt("bahe_activity_id")
uid := t.GetAccountId()
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_TUGWAR_TEAM_OVER_LIMIT, "拔河不存在")
if bahe.Status == define.StatusNotBegin {
t.ERROR("该拔河活动尚未开始", code.MSG_MODULE_STATUS_NOT_RUNNING)
return
}
if bahe.Status == define.StatusEnding {
t.ERROR("该拔河活动已结束", code.MSG_MODULE_STATUS_END)
return
}
activity := new(models.Activity)
@ -129,7 +132,7 @@ func (t *TugOfWarCtl) JoinTeam() {
// 判斷是否已經存在该用户
member := new(models.BaheTeamMember)
exist, err = member.GetMemberByBaheIdAndUserId(uid, bahe.Id, activity.RehearsalId)
exist, err = member.GetMemberByBaheIdAndUserId(activity.ArchId, uid, bahe.Id, activity.RehearsalId)
t.CheckErr(err)
if exist { // 存在改用户
t.JSON(map[string]interface{}{
@ -140,9 +143,9 @@ func (t *TugOfWarCtl) JoinTeam() {
var team *bahe_service.JoinTeamResult
if teamId == 0 {
team, exist, err = bahe_service.GetJoinTeamByBaheId(bahe.Id, activity.RehearsalId)
team, exist, err = bahe_service.GetJoinTeamByBaheId(bahe.Id, activity.RehearsalId, activity.ArchId)
} else {
team, exist, err = bahe_service.GetJoinTeamByTeamId(teamId, activity.RehearsalId)
team, exist, err = bahe_service.GetJoinTeamByTeamId(teamId, activity.RehearsalId, activity.ArchId)
}
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR, "队伍信息错误, 请重新扫码")
@ -158,6 +161,7 @@ func (t *TugOfWarCtl) JoinTeam() {
member.TeamName = team.TeamName
member.MemberId = uid
member.Avatar = user.Avatar
member.ArchId = activity.ArchId
member.NickName = user.Nickname
member.BaheActivityId = baheActivityId
member.RehearsalId = activity.RehearsalId

12
controllers/client/upper_wall.go

@ -14,10 +14,9 @@ type UpperWallCtl struct {
}
//发送上墙消息
// todo: 支付接口
func (t *UpperWallCtl) Send() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
category := t.MustGetInt("category")
content, _ := t.Get("content")
img, _ := t.Get("img")
@ -46,6 +45,7 @@ func (t *UpperWallCtl) Send() {
uw.RehearsalId = activity.RehearsalId
uw.ActivityId = activityId
uw.Category = fmt.Sprintf("%v", category)
uw.ArchId = activity.ArchId
uw.UserId = user.Id
uw.Content = content
uw.Img = img
@ -58,15 +58,15 @@ func (t *UpperWallCtl) Send() {
}
func (t *UpperWallCtl) List() {
activityId := t.MustGetInt64("activity_id")
userId := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
userId := t.GetAccountId()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
list, err := upper_wall.GetUpperWallResult(userId, activity.Id, activity.RehearsalId)
list, err := upper_wall.GetUpperWallResult(userId, activity.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"list": list,

36
controllers/client/vote.go

@ -2,11 +2,11 @@ package client
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type VoteCtl struct {
@ -15,8 +15,8 @@ type VoteCtl struct {
//投票
func (t *VoteCtl) Vote() {
uid := t.MustGetUID()
ladderId := t.MustGetInt64("vote_activity_ladder_id")
uid := t.GetAccountId()
ladderId := t.MustGetInt("vote_activity_ladder_id")
//检查是否可以投票
ladder := new(models.NewVoteActivityLadder)
@ -37,34 +37,30 @@ func (t *VoteCtl) Vote() {
t.CheckRunning(activity.Status)
history := new(models.NewVoteActivityHistory)
exist, err = history.ExistByLadderId(uid, ladderId, activity.RehearsalId)
exist, err = history.ExistByLadderId(uid, ladderId, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_VOTE_HISTORY_EXIST, "您已经投过票了")
if vote.Model == "单选" {
//检查是否已经投过票了
exist, err = history.ExistByVoteId(uid, vote.Id, activity.RehearsalId)
exist, err = history.ExistByVoteId(uid, vote.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_VOTE_HISTORY_EXIST, "您已经投过票了")
} else {
num, err := history.CountUser(uid, activity.RehearsalId, vote.Id)
num, err := history.CountUser(uid, activity.RehearsalId, vote.Id, activity.ArchId)
t.CheckErr(err)
if num >= vote.ModelNum {
if int(num) >= vote.ModelNum {
t.ERROR(fmt.Sprintf("您投票人数已超过%d人", vote.ModelNum), code.MSG_ERR)
}
}
// done: 增加人数限制
history.UserId = uid
history.RehearsalId = activity.RehearsalId
history.VoteActivityId = vote.Id
history.VoteActivityLadderId = ladderId
history.IsDelete = false
history.CreatedAt = time.Now()
history.UpdatedAt = time.Now()
history.ArchId = activity.ArchId
_, err = models.Add(history)
t.CheckErr(err)
// vote ladder total_number + 1
_, err = ladder.Incr(ladderId, 1)
t.CheckErr(err)
@ -73,7 +69,7 @@ func (t *VoteCtl) Vote() {
// 投票活动列表
func (t *VoteCtl) List() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
// 该活动是否进行中
activity := new(models.Activity)
@ -82,7 +78,7 @@ func (t *VoteCtl) List() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
votes, err := models.GetVoteListByActivityId(activity.Id)
votes, err := models.GetVoteListByActivityId(activity.Id, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -92,9 +88,9 @@ func (t *VoteCtl) List() {
}
func (t *VoteCtl) Detail() {
voteActivityId := t.MustGetInt64("vote_activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
voteActivityId := t.MustGetInt("vote_activity_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -107,8 +103,8 @@ func (t *VoteCtl) Detail() {
t.CheckErr(err)
histories := make([]*models.NewVoteActivityHistory, 0)
err = core.GetXormAuto().Where("is_delete=0 and user_id=? and rehearsal_id=? and vote_activity_id=?",
uid, activity.RehearsalId, voteActivityId).Find(&histories)
err = core.GetXormAuto().Where("is_delete=0 and user_id=? and rehearsal_id=? and vote_activity_id=? "+
" and arch_id=?", uid, activity.RehearsalId, voteActivityId, activity.ArchId).Find(&histories)
t.CheckErr(err)
for i := range ladders {

18
controllers/client/wx.go

@ -60,21 +60,3 @@ func (t *WxCtl) Ticket() {
"appid": define.AppId,
})
}
//type WechatPay struct {
//}
//func (t *WxCtl) Order() {
// userId := t.MustGetUID()
// content := t.MustGet("content")
// amount := t.MustGetInt("amount")
//
// user := new(models.User)
// exist, err := models.GetById(user, userId)
// t.CheckErr(err)
// t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
//
// ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
// res, err := pay_service.Order(content, ip[0], user.Openid, amount, 1, user.Id)
// t.JSON(res)
//}

3
controllers/common/im.go

@ -25,9 +25,10 @@ func (t *ImTestCtl) Refund() {
}
func (t *ImTestCtl) Send() {
err := im_service.SendGroupCustomMessage("admin", t.MustGetInt64("activity_id"),
err := im_service.SendGroupCustomMessage("admin", t.MustGetInt("activity_id"),
im_service.NoticeStatus(t.MustGetInt("type")), map[string]interface{}{
"content": "测试",
"admin": 1,
})
t.CheckErr(err)
t.SUCCESS("成功")

3
controllers/common/wechat_oauth.go

@ -4,7 +4,6 @@ import (
"crypto/sha1"
"encoding/xml"
"fmt"
"go.uber.org/atomic"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/filter"
"hudongzhuanjia/logger"
@ -12,6 +11,8 @@ import (
"hudongzhuanjia/utils/define"
"os"
"time"
"go.uber.org/atomic"
)
var Now = time.Now()

11
controllers/pc/activity.go

@ -16,10 +16,10 @@ type ActivityCtl struct {
}
func (t *ActivityCtl) StartActivity() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
mode := t.MustGetInt("mode") // 标识彩排 mode=0正式 mode=1彩排
uid := t.MustGetUID()
limit := t.DefaultInt64("limit", 10)
uid := t.GetAccountId()
limit := t.DefaultInt("limit", 10)
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -48,6 +48,9 @@ func (t *ActivityCtl) StartActivity() {
t.CheckErr(err)
activity.RehearsalId = rehearsal.Id
} else { //非彩排
if activity.StartTime.After(time.Now()) {
t.ERROR("互动设置开始时间尚未到,无法正式开始", code.MSG_ACTIVITY_NOT_EXIST)
}
arch := &models.Arch{}
count, err := arch.Count(activity.Id)
t.CheckErr(err)
@ -66,7 +69,7 @@ func (t *ActivityCtl) StartActivity() {
}
func (t *ActivityCtl) StopActivity() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)

2
controllers/pc/area_store.go

@ -11,7 +11,7 @@ type AreaStoreCtl struct {
}
func (t *AreaStoreCtl) List() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
list, err := models.GetAreaStoresByActivityId(activityId)
t.CheckErr(err)

74
controllers/pc/auction.go

@ -19,7 +19,7 @@ type AuctionCtl struct {
// 竞拍准备状态
func (t *AuctionCtl) ReadyAuction() {
auctionId := t.MustGetInt64("auction_activity_id")
auctionId := t.MustGetInt("auction_activity_id")
auction := new(models.NewAuctionActivity)
exist, err := models.Get(auction, auctionId)
t.CheckErr(err)
@ -36,7 +36,7 @@ func (t *AuctionCtl) ReadyAuction() {
}
func (t *AuctionCtl) StartAuction() {
auctionId := t.MustGetInt64("auction_activity_id")
auctionId := t.MustGetInt("auction_activity_id")
auction := new(models.NewAuctionActivity)
exist, err := models.Get(auction, auctionId)
@ -57,8 +57,7 @@ func (t *AuctionCtl) StartAuction() {
}
func (t *AuctionCtl) StopAuction() {
auctionId := t.MustGetInt64("auction_activity_id")
auctionId := t.MustGetInt("auction_activity_id")
auction := new(models.NewAuctionActivity)
exist, err := models.Get(auction, auctionId)
t.CheckErr(err)
@ -77,10 +76,9 @@ func (t *AuctionCtl) StopAuction() {
_, err = models.Get(activity, auction.ActivityId)
t.CheckErr(err)
// todo: 记录用户最高价
if auction.AuctionModel == define.INCR_AUCTION {
history := new(models.AuctionHistory)
_, err := history.GetHighestMoney(activity.RehearsalId, auction.Id) // 区分彩排数据
_, err := history.GetHighestMoney(activity.RehearsalId, auction.Id, activity.ArchId) // 区分彩排数据
t.CheckErr(err)
user := new(models.User)
@ -90,6 +88,7 @@ func (t *AuctionCtl) StopAuction() {
if exist {
record.AuctionActivityId = auctionId
record.RehearsalId = history.RehearsalId // 彩排
record.ArchId = activity.ArchId
record.AuctionGoodsName = auction.AuctionGoodsName
record.ActivityId = auction.ActivityId
record.UserId = history.UserId
@ -142,25 +141,29 @@ func (t *AuctionCtl) StopAuction() {
t.SUCCESS("操作成功")
}
// 增加数据
func (t *AuctionCtl) History() {
auctionId := t.MustGetInt64("auction_activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
auctionId := t.MustGetInt("auction_activity_id")
rehearsalId := t.MustGetInt("rehearsal_id")
auction := new(models.NewAuctionActivity)
auction := &models.NewAuctionActivity{}
exist, err := models.Get(auction, auctionId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "竞拍不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, auction.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
orderBy := "money asc"
if auction.AuctionModel == "加价竞拍" {
orderBy = "money desc"
}
histories, err := models.GetAuctionHistoriesByAuctionId(auctionId, rehearsalId, orderBy)
histories, err := models.GetAuctionHistoriesByAuctionId(auctionId, rehearsalId, orderBy, activity.ArchId)
t.CheckErr(err)
userIdMap := make(map[int64]struct{}, 0) // 去重操作
userIdMap := make(map[int]struct{}, 0) // 去重操作
for u := range histories {
if _, ok := userIdMap[histories[u].UserId]; ok {
//去掉重复的
@ -177,24 +180,29 @@ func (t *AuctionCtl) History() {
}
func (t *AuctionCtl) List() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
rehearsalId := t.MustGetInt("rehearsal_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
auctions, err := models.GetAuctionsByActivityId(activityId, "created_at asc")
auctions, err := models.GetAuctionsByActivityId(activityId)
t.CheckErr(err)
// 更具某个数据进行
upIds := make([]int64, 0)
upIds := make([]int, 0)
for _, item := range auctions {
if item.AuctionModel == "加价竞拍" {
upIds = append(upIds, item.Id)
}
}
upH, err := models.GetAuctionHistoriesByAuctionIds(upIds, rehearsalId, "money desc")
upH, err := models.GetAuctionHistoriesByAuctionIds(upIds, rehearsalId, activity.ArchId)
t.CheckErr(err)
for i := range auctions {
if auctions[i].AuctionModel == define.INCR_AUCTION {
userIdMap := make(map[int64]struct{}, 0) // 去重操作
userIdMap := make(map[int]struct{}, 0) // 去重操作
for u := range upH {
if _, ok := userIdMap[upH[u].UserId]; ok {
//去掉重复的
@ -217,10 +225,18 @@ func (t *AuctionCtl) List() {
// 成交记录
func (t *AuctionCtl) Records() {
rehearsalId := t.MustGetInt64("rehearsal_id") // 彩排
auctionId := t.MustGetInt64("auction_activity_id")
auctionId := t.MustGetInt("auction_activity_id")
auction := &models.NewAuctionActivity{}
exist, err := models.Get(auction, auctionId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "竞拍活动不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, auction.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "互动不存在")
records, err := models.GetAuctionRecordsByAuctionId(auctionId, rehearsalId, "created_at desc")
records, err := models.GetAuctionRecordsByAuctionId(auctionId, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"records": records,
@ -231,13 +247,17 @@ func (t *AuctionCtl) Records() {
//获取二维码
func (t *AuctionCtl) Qrcode() {
//将服务器得地址和activity_id,动态生成二维码
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
auctionId := t.MustGetInt64("auction_activity_id")
rehearsalId := t.MustGetInt("rehearsal_id")
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
auctionId := t.MustGetInt("auction_activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "互动不存在")
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(uid, activityId)
exist, err = area.GetByCustomerId(uid, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
@ -246,7 +266,7 @@ func (t *AuctionCtl) Qrcode() {
"area_id": area.Id,
"customer_id": uid,
"auction_id": auctionId,
"rehearsal_id": rehearsalId,
"rehearsal_id": activity.RehearsalId,
})
t.CheckErr(err)
t.JSON(map[string]interface{}{

6
controllers/pc/barrage.go

@ -13,7 +13,7 @@ type BarrageCtl struct {
//获取活动的详情
func (t *BarrageCtl) Details() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
server := new(models.DanMuServer)
exist, err := server.GetByActivityId(activityId)
t.CheckErr(err)
@ -25,14 +25,14 @@ func (t *BarrageCtl) Details() {
}
func (t *BarrageCtl) SaveSetting() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
danmuId := t.MustGetInt64("danmu_server_id")
danmuId := t.MustGetInt("danmu_server_id")
server := new(models.DanMuServer)
server.DanmuFontSize = t.MustGet("font_size")
server.DanmuOpacity = t.MustGetInt("opacity")

31
controllers/pc/bully_screen.go

@ -4,7 +4,7 @@ import (
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
bully_reward_service "hudongzhuanjia/services/bully_reward"
"hudongzhuanjia/services/pay"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"strings"
@ -17,7 +17,7 @@ type BullyScreenCtl struct {
//获取待审核列表
func (t *BullyScreenCtl) WaitReview() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -31,8 +31,8 @@ func (t *BullyScreenCtl) WaitReview() {
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
//根据霸屏服务得id获取待审核得霸屏列表
t.CheckErr(bully_reward_service.CheckBullyScreenStatus(bullyScreenServer.Id))
result, err := bully_reward_service.GetBullyScreenReview(bullyScreenServer.Id, activity.RehearsalId)
go bully_reward_service.CheckBullyScreenStatus(bullyScreenServer.Id)
result, err := bully_reward_service.GetBullyScreenReview(bullyScreenServer.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -43,11 +43,10 @@ func (t *BullyScreenCtl) WaitReview() {
//审核操作
func (t *BullyScreenCtl) Review() {
customerId := t.MustGetUID()
customerId := t.GetAccountId()
status := t.MustGetBool("status")
ids := strings.Split(t.MustGet("ids"), "|")
activityId := t.MustGetInt64("activity_id")
//rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -104,7 +103,7 @@ func (t *BullyScreenCtl) Review() {
//获取黑名单列表
func (t *BullyScreenCtl) Blacklist() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -118,7 +117,7 @@ func (t *BullyScreenCtl) Blacklist() {
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏活动不存在")
//根据霸屏服务得id获取待审核得霸屏列表
result, err := bully_reward_service.GetBullyScreenBlacklist(bullyScreenServer.Id, activity.RehearsalId)
result, err := bully_reward_service.GetBullyScreenBlacklist(bullyScreenServer.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.DisplayByData(map[string]interface{}{
@ -129,7 +128,7 @@ func (t *BullyScreenCtl) Blacklist() {
//获取目前霸屏得总金额
func (t *BullyScreenCtl) Amount() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -142,7 +141,7 @@ func (t *BullyScreenCtl) Amount() {
t.CheckErr(err)
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
totalSecond, err := new(models.BullyScreenHistory).SumSecond(bullyScreenServer.Id, activity.RehearsalId)
totalSecond, err := new(models.BullyScreenHistory).SumSecond(bullyScreenServer.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -152,7 +151,7 @@ func (t *BullyScreenCtl) Amount() {
//获取最新得霸屏记录
func (t *BullyScreenCtl) Latest() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -160,12 +159,12 @@ func (t *BullyScreenCtl) Latest() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//获取霸屏服务得id
bullyScreenServer := new(models.BullyScreenServer)
exist, err = bullyScreenServer.GetByActivityId(activityId)
server := new(models.BullyScreenServer)
exist, err = server.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
result, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId)
result, err := bully_reward_service.GetBullyScreenLatest(server.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
if result == nil || result.Id == 0 {
t.JSON(result)
@ -181,7 +180,7 @@ func (t *BullyScreenCtl) Latest() {
// 霸屏服务器开关
func (t *BullyScreenCtl) Details() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
server := new(models.BullyScreenServer)
exist, err := server.GetByActivityId(activityId)
t.CheckErr(err)

22
controllers/pc/calorie.go

@ -16,7 +16,7 @@ type CalorieCtl struct {
}
func (t *CalorieCtl) Ready() {
calorieId := t.MustGetInt64("calorie_id")
calorieId := t.MustGetInt("calorie_id")
calorie := new(models.Calorie)
exist, err := models.Get(calorie, calorieId)
@ -42,7 +42,7 @@ func (t *CalorieCtl) Ready() {
// 开始, 加一个开始时间
func (t *CalorieCtl) Start() {
calorieId := t.MustGetInt64("calorie_id")
calorieId := t.MustGetInt("calorie_id")
calorie := new(models.Calorie)
exist, err := models.Get(calorie, calorieId)
@ -64,7 +64,7 @@ func (t *CalorieCtl) Start() {
// 彩排活动需要恢复
func (t *CalorieCtl) Stop() {
calorieId := t.MustGetInt64("calorie_id")
calorieId := t.MustGetInt("calorie_id")
calorie := new(models.Calorie)
exist, err := models.Get(calorie, calorieId)
@ -86,7 +86,7 @@ func (t *CalorieCtl) Stop() {
// 列出轮次, 包括倒计时
func (t *CalorieCtl) List() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
calories, err := models.GetCaloriesByActivityId(activityId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -97,9 +97,9 @@ func (t *CalorieCtl) List() {
// 二维码
func (t *CalorieCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
calorieId := t.MustGetInt64("calorie_id")
activityId := t.MustGetInt("activity_id")
uid := t.GetAccountId()
calorieId := t.MustGetInt("calorie_id")
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(uid, activityId)
@ -120,8 +120,8 @@ func (t *CalorieCtl) Qrcode() {
// 统计一些数据, 包括参与人数, 包括当前排名
func (t *CalorieCtl) Count() {
activityId := t.MustGetInt64("activity_id")
calorieId := t.MustGetInt64("calorie_id")
activityId := t.MustGetInt("activity_id")
calorieId := t.MustGetInt("calorie_id")
limit := t.DefaultInt("limit", 10)
activity := new(models.Activity)
@ -136,11 +136,11 @@ func (t *CalorieCtl) Count() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "卡路里不存在")
// 统计人数
count, err := new(models.CalorieUser).Count(calorieId, activity.RehearsalId)
count, err := new(models.CalorieUser).Count(calorieId, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
// 统计排名
result, err := calorie_service.RankCalorieUser(calorieId, activity.RehearsalId, limit)
result, err := calorie_service.RankCalorieUser(calorieId, activity.ArchId, activity.RehearsalId, limit)
t.CheckErr(err)
t.JSON(map[string]interface{}{

21
controllers/pc/login.go

@ -14,7 +14,8 @@ import (
"hudongzhuanjia/libs/qq"
"hudongzhuanjia/libs/wx"
"hudongzhuanjia/models"
"hudongzhuanjia/services/activity"
activity_service "hudongzhuanjia/services/activity"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
@ -38,16 +39,22 @@ func (t *UserCtl) Login() {
t.CheckErr(err)
// 主账号无法确定
token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId)
t.CheckErr(err)
t.SetSession(define.TOKEN, token)
customer.Token = token
//token, err := jwt.GenJwtToken(define.TYPE_CUSTOMER, customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId)
//t.CheckErr(err)
if customer.Token == "" {
customer.Token = utils.GenToken(customer.Username)
}
customer.Activities = activities
pid := customer.Pid
if pid == 0 {
pid = customer.Id
}
customer.Tag = "activity"
_, err = customer.Update(customer, customer.Id)
t.CheckErr(err)
customer.Token = fmt.Sprintf("%s:%s", define.TYPE_CUSTOMER, customer.Token)
t.SetSession(define.TOKEN, customer.Token)
t.JSON(customer)
}
@ -62,13 +69,13 @@ func (t *UserCtl) Checkin() {
// debug
func (t *UserCtl) DebugLogin() {
customerId := t.DefaultInt64("customer_id", 1)
customerId := t.DefaultInt("customer_id", 1)
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId)
token, err := jwt.GenJwtToken(define.TYPE_CUSTOMER, customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId)
t.CheckErr(err)
t.SetSession(define.TOKEN, token)
t.JSON(map[string]interface{}{

116
controllers/pc/lottery_draw.go

@ -17,18 +17,32 @@ type LotteryDrawCtl struct {
controllers.AuthorCtl
}
// [屏蔽]
func (t *LotteryDrawCtl) Block() {
activityId := t.MustGetInt("activity_id")
status := t.MustGet("status")
module, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块不存在")
module.BesideRepeat = status
_, err = models.Update(module.Id, module, "beside_repeat")
t.CheckErr(err)
t.SUCCESS("操作成功")
}
//开始抽奖
func (t *LotteryDrawCtl) Start() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
ladder := new(models.LotteryDrawRuleLadder)
exist, err := models.Get(ladder, ladderId)
ladder := models.LotteryDrawRuleLadder{}
exist, err := models.Get(&ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
activity := models.Activity{}
exist, err = models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
@ -49,6 +63,7 @@ func (t *LotteryDrawCtl) Start() {
if exist && live.HaveModule(define.MODULE_LOTTERY) {
go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStart,
map[string]interface{}{
"admin": 1,
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
"desc": "开始抽奖",
@ -61,9 +76,9 @@ func (t *LotteryDrawCtl) Start() {
// 滚动
func (t *LotteryDrawCtl) StartRoll() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
num := t.MustGetInt64("num")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
num := t.MustGetInt("num")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -90,6 +105,7 @@ func (t *LotteryDrawCtl) StartRoll() {
if exist && live.HaveModule(define.MODULE_LOTTERY) {
go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStart,
map[string]interface{}{
"admin": 1,
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
"roll_num": ladder.RollNum,
@ -102,9 +118,9 @@ func (t *LotteryDrawCtl) StartRoll() {
}
func (t *LotteryDrawCtl) StopRoll() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
num := t.MustGetInt64("num")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
num := t.MustGetInt("num")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -117,9 +133,6 @@ func (t *LotteryDrawCtl) StopRoll() {
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
//if ladder.Status != define.StatusRunning {
// t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR)
//}
// 通知直播开始抽奖
if activity.RehearsalId == 0 {
live := new(models.LiveConfig)
@ -128,6 +141,7 @@ func (t *LotteryDrawCtl) StopRoll() {
if exist && live.HaveModule(define.MODULE_LOTTERY) {
go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStop,
map[string]interface{}{
"admin": 1,
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
"roll_num": ladder.RollNum,
@ -141,8 +155,8 @@ func (t *LotteryDrawCtl) StopRoll() {
//停止抽奖
func (t *LotteryDrawCtl) Stop() {
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -155,10 +169,6 @@ func (t *LotteryDrawCtl) Stop() {
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
//if ladder.Status != define.StatusRunning {
// t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR)
//}
ladder.Status = define.StatusEnding
ladder.UpdatedAt = time.Now()
ladder.RollNum = 0
@ -173,6 +183,7 @@ func (t *LotteryDrawCtl) Stop() {
if exist && live.HaveModule(define.MODULE_LOTTERY) {
go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStop,
map[string]interface{}{
"admin": 1,
"lottery_draw_ladder_id": ladder.Id,
"timestamp": time.Now().Unix(),
"desc": "结束抽奖",
@ -184,8 +195,8 @@ func (t *LotteryDrawCtl) Stop() {
//获取所有抽奖活动列表
func (t *LotteryDrawCtl) List() {
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
customerId := t.GetAccountId()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
@ -197,7 +208,7 @@ func (t *LotteryDrawCtl) List() {
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
result, err := lottery_service.GetLotteryAndLadder(activityId, activity.RehearsalId)
result, err := lottery_service.GetLotteryAndLadder(activityId, activity.RehearsalId, activity.ArchId)
t.JSON(map[string]interface{}{
"total": len(result),
@ -207,7 +218,7 @@ func (t *LotteryDrawCtl) List() {
//抽奖奖品
func (t *LotteryDrawCtl) Prize() {
ruleId := t.MustGetInt64("lottery_draw_rule_id")
ruleId := t.MustGetInt("lottery_draw_rule_id")
list, err := models.GetLotteryDrawLadderByRuleId(ruleId)
t.CheckErr(err)
@ -223,17 +234,12 @@ func (t *LotteryDrawCtl) Prize() {
// 抽奖用户
func (t *LotteryDrawCtl) Users() {
activityId := t.MustGetInt64("activity_id")
ruleId := t.MustGetInt64("lottery_draw_rule_id")
customerId := t.MustGetUID()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
activityId := t.MustGetInt("activity_id")
ruleId := t.MustGetInt("lottery_draw_rule_id")
customerId := t.GetAccountId()
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
@ -245,13 +251,13 @@ func (t *LotteryDrawCtl) Users() {
moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
recordIds := make([]int64, 0)
recordIds := make([]int, 0)
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
// 去重标志
recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ruleId, activity.RehearsalId, area.Id)
recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ruleId, activity.RehearsalId, area.Id, activity.ArchId)
t.CheckErr(err)
}
result, err := lottery_service.GetLotteryUsersResult(area.Id, activity.Id, activity.RehearsalId, recordIds)
result, err := lottery_service.GetLotteryUsersResult(area.Id, activity.Id, activity.RehearsalId, activity.ArchId, recordIds)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -262,11 +268,11 @@ func (t *LotteryDrawCtl) Users() {
//抽奖动作
func (t *LotteryDrawCtl) Lottery() {
activityId := t.MustGetInt64("activity_id")
ruleId := t.MustGetInt64("lottery_draw_rule_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activityId := t.MustGetInt("activity_id")
ruleId := t.MustGetInt("lottery_draw_rule_id")
ladderId := t.MustGetInt("lottery_draw_ladder_id")
number := t.MustGetInt("number") // 奖品数量
customerId := t.MustGetUID()
customerId := t.GetAccountId()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
@ -297,7 +303,7 @@ func (t *LotteryDrawCtl) Lottery() {
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "抽奖等级不存在")
t.CheckRunning(ladder.Status)
count, err := new(models.LotteryDrawRecord).CountRecord(ruleId, ladder.Id, activity.RehearsalId, area.Id)
count, err := new(models.LotteryDrawRecord).CountRecord(ruleId, ladder.Id, activity.RehearsalId, area.Id, activity.ArchId)
t.CheckErr(err)
prizeNum := ladder.PrizeNumber - int(count)
@ -309,7 +315,8 @@ func (t *LotteryDrawCtl) Lottery() {
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
// 取设置
userIds, err := lottery_service.GetLotteryUserIds(module.BesideRepeat, activityId, ruleId, ladder.Id, activity.RehearsalId, area.Id)
userIds, err := lottery_service.GetLotteryUserIds(module.BesideRepeat, activityId, ruleId, ladder.Id,
activity.RehearsalId, area.Id, activity.ArchId)
if len(userIds) < number {
t.ERROR("抽奖人数不足", code.MSG_LOTTERY_PEOPLE_NOT_ENOUGH)
}
@ -333,6 +340,7 @@ func (t *LotteryDrawCtl) Lottery() {
userPrize.UserId = winners[i].UserId
userPrize.PrizeImg = ladder.PrizeImg
userPrize.PrizeName = ladder.PrizeName
userPrize.ArchId = activity.ArchId
userPrize.PrizeType = 1
userPrize.IsDelete = false
userPrize.CreatedAt = time.Now()
@ -345,6 +353,7 @@ func (t *LotteryDrawCtl) Lottery() {
record.ActivityId = activityId
record.RehearsalId = activity.RehearsalId
record.LotteryDrawActivityId = rule.LotteryDrawActivityId
record.ArchId = activity.ArchId
record.LotteryDrawRuleId = rule.Id
record.UserId = winners[i].UserId
record.UserName = winners[i].Username
@ -369,6 +378,7 @@ func (t *LotteryDrawCtl) Lottery() {
if exist && live.HaveModule(define.MODULE_LOTTERY) {
go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawResult,
map[string]interface{}{
"admin": 1,
"lottery_draw_ladder_id": ladder.Id,
"winners": winners,
"roll_num": ladder.RollNum,
@ -383,10 +393,24 @@ func (t *LotteryDrawCtl) Lottery() {
//获取中奖名单
func (t *LotteryDrawCtl) ListOfWinners() {
ruleId := t.MustGetInt64("lottery_draw_rule_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt("lottery_draw_rule_id")
rule := &models.LotteryDrawRule{}
exist, err := models.Get(rule, ruleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
lottery := &models.LotteryDrawActivity{}
exist, err = models.Get(lottery, rule.LotteryDrawActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, lottery.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
result, err := lottery_service.GetWinnersResult(ruleId, rehearsalId)
result, err := lottery_service.GetWinnersResult(ruleId, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),

511
controllers/pc/order_draw.go

@ -2,7 +2,6 @@ package pc
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
@ -11,6 +10,8 @@ import (
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
// 订单
@ -18,17 +19,31 @@ type OrderDrawCtl struct {
controllers.AuthorCtl
}
// 屏蔽
func (t *OrderDrawCtl) Block() {
activityId := t.MustGetInt("activity_id")
status := t.MustGet("status")
module, exist, err := activity_service.GetModuleService(define.MODULE_ORDERLY, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块不存在")
module.BesideRepeat = status
_, err = models.Update(module.Id, module, "beside_repeat")
t.CheckErr(err)
t.SUCCESS("操作成功")
}
// 开启订单活动
func (t *OrderDrawCtl) Switch() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
status := t.MustGetInt("status")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
option := new(models.CustomerOrderOption)
option := &models.CustomerOrderOption{}
exist, err = option.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "订单活动不存在")
@ -38,8 +53,8 @@ func (t *OrderDrawCtl) Switch() {
return
}
_, err = option.Switch(activityId, status)
t.CheckErr(err)
option.Status = status
_, err = models.Update(option.Id, option, "status")
t.CheckErr(err)
t.SUCCESS("操作成功")
}
@ -48,7 +63,7 @@ func (t *OrderDrawCtl) Switch() {
// 开始抽奖
func (t *OrderDrawCtl) Start() {
ladderId := t.MustGetInt64("order_draw_ladder_id")
ladderId := t.MustGetInt("order_draw_ladder_id")
ladder := new(models.OrderDrawRuleLadder)
exist, err := models.Get(ladder, ladderId)
@ -70,7 +85,7 @@ func (t *OrderDrawCtl) Start() {
// 开始抽奖
func (t *OrderDrawCtl) Stop() {
ladderId := t.MustGetInt64("order_draw_ladder_id")
ladderId := t.MustGetInt("order_draw_ladder_id")
ladder := new(models.OrderDrawRuleLadder)
exist, err := models.Get(ladder, ladderId)
@ -91,80 +106,72 @@ func (t *OrderDrawCtl) Stop() {
t.SUCCESS("操作成功")
}
type OrderListResult struct {
OrderDrawActivityId int64 `json:"order_draw_activity_id"`
OrderDrawRuleId int64 `json:"order_draw_rule_id"`
OrderDrawActivityName string `json:"order_draw_activity_name"`
OrderDrawLadders []*OrderLadderResult `json:"order_draw_ladders"`
PrizeNumber int64 `json:"prize_number"`
}
type OrderLadderResult struct {
OrderDrawRuleId int64 `json:"order_draw_rule_id"`
OrderDrawLadderId int64 `json:"order_draw_ladder_id"`
OrderDrawRuleId int `json:"order_draw_rule_id"`
OrderDrawLadderId int `json:"order_draw_ladder_id"`
PrizeName string `json:"prize_name"`
Status string `json:"status"`
PrizeImg string `json:"prize_img"`
PrizeNumber int64 `json:"prize_number"`
PrizeNumber int `json:"prize_number"`
}
type OrderListResult struct {
OrderDrawActivityId int `json:"order_draw_activity_id"`
OrderDrawRuleId int `json:"order_draw_rule_id"`
OrderDrawActivityName string `json:"order_draw_activity_name"`
OrderDrawLadders []*OrderLadderResult `json:"order_draw_ladders"`
PrizeNumber int `json:"prize_number"`
}
//获取所有订单奖品
func (t *OrderDrawCtl) List() {
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetUID()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
activityId := t.MustGetInt("activity_id")
customerId := t.GetAccountId()
//
area := &models.AreaStore{}
exist, err := area.GetByCustomerId(customerId, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区信息异常")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
activity := models.Activity{}
exist, err = models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动信息异常")
// 订单的开启或关闭
order := new(models.CustomerOrderOption)
exist, err = order.GetByActivityId(activityId)
option := &models.CustomerOrderOption{}
exist, err = option.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在")
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单信息异常")
result := make([]*OrderListResult, 0)
core.GetXormAuto().Table(new(models.OrderDrawActivity)).Alias("a").
core.GetXormAuto().Table(&models.OrderDrawActivity{}).Alias("a").
Select("a.id as order_draw_activity_id, r.id as order_draw_rule_id, a.order_draw_activity_name").
Join("LEFT", new(models.OrderDrawRule).Alias("r"),
Join("LEFT", (&models.OrderDrawRule{}).Alias("r"),
"a.id=r.order_draw_activity_id and r.is_delete=0").
Where("a.is_delete=0 and a.activity_id=?", activityId).Find(&result)
// 多地区的一个坑:分配给主会场的area_id不是主账号的area_id
area := new(models.AreaStore)
if customer.Pid == 0 {
exist, err = area.GetMainAreaById(activityId)
} else {
exist, err = area.GetAreaStoreById(t.MustGetAreaId())
}
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
ruleIds := make([]int64, 0)
ruleIds := make([]int, 0)
for _, v := range result {
ruleIds = append(ruleIds, v.OrderDrawRuleId)
}
ladders := make([]*OrderLadderResult, 0)
err = core.GetXormAuto().Table(new(models.OrderDrawRuleLadder)).Alias("l").
err = core.GetXormAuto().Table(&models.OrderDrawRuleLadder{}).Alias("l").
Select("id as order_draw_ladder_id, status, prize_name, prize_img, prize_number, order_draw_rule_id").
Where("is_delete=0").In("order_draw_rule_id", ruleIds).Find(&ladders)
t.CheckErr(err)
ladderIds := make([]int64, 0)
ladderIds := make([]int, 0)
for _, ladder := range ladders {
ladderIds = append(ladderIds, ladder.OrderDrawLadderId)
}
records := make([]map[string]int64, 0)
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Alias("r").
records := make([]map[string]int, 0)
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r").
Select("r.order_draw_rule_ladder_id as ladder_id, count(id) as num").
Where("is_delete=0 and rehearsal_id=?", activity.RehearsalId).
Where("is_delete=0 and rehearsal_id=? and arch_id=? and area_id=?",
activity.RehearsalId, activity.ArchId, area.Id).
In("r.order_draw_rule_ladder_id", ladderIds).GroupBy("ladder_id").Find(&records)
t.CheckErr(err)
@ -188,21 +195,17 @@ func (t *OrderDrawCtl) List() {
t.JSON(map[string]interface{}{
"total": len(result),
"list": result,
"status": order.Status,
"status": option.Status,
})
}
//抽奖奖品
func (t *OrderDrawCtl) Prize() {
ruleId := t.MustGetInt64("order_draw_rule_id")
ruleId := t.MustGetInt("order_draw_rule_id")
list := make([]*models.OrderDrawRuleLadder, 0)
err := core.GetXormAuto().Where("is_delete=0 and order_draw_rule_id=?", ruleId).Find(&list)
list, err := models.GetOrderDrawRuleLaddersByRuleId(ruleId)
t.CheckErr(err)
for index := range list {
list[index].Des = "在该活动的所有订单用户中随机抽奖品数量的用户"
}
t.JSON(map[string]interface{}{
"total": len(list),
"lise": list,
@ -210,40 +213,66 @@ func (t *OrderDrawCtl) Prize() {
}
type OrderUsersResult struct {
UserId int64 `json:"user_id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
UserId int `json:"user_id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Phone string `json:"phone"`
EntryPersonName string `json:"entry_person_name"`
}
//统计人数和订单数量
func (t *OrderDrawCtl) Users() {
activityId := t.MustGetInt64("activity_id")
ruleId := t.MustGetInt64("order_draw_rule_id")
activityId := t.MustGetInt("activity_id")
ruleId := t.MustGetInt("order_draw_rule_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
result := make([]*OrderUsersResult, 0)
session := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
Select("o.buyer_id as user_id, u.nickname as username, u.avatar").Distinct("o.buyer_id").
Join("LEFT", new(models.User).Alias("u"), "o.buyer_id=u.id and u.is_delete=0").
Where("o.activity_id=? and o.is_delete=0 and o.rehearsal_id=?",
activityId, activity.RehearsalId)
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
moduleService, exist, err := activity_service.GetModuleService(define.MODULE_ORDERLY, activity.Id)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块服务不存在")
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
recordIds := make([]int64, 0)
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id").
Where("order_draw_rule_id=? and rehearsal_id=? and is_delete=0",
ruleId, activity.RehearsalId).Find(&recordIds)
t.CheckErr(err)
session = session.NotIn("o.buyer_id", recordIds)
result := make([]*OrderUsersResult, 0)
s := core.GetXormAuto().NewSession()
defer s.Close()
if customer.IsSpecial == 2 {
s = s.Table(&models.CustomerOrder{}).Alias("o").Select("o.buyer_id as user_id, "+
" o.phone, o.order_entry_person_name as entry_person_name, o.receiver as username").
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
activity.Id, activity.RehearsalId, activity.ArchId)
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
recordIds := make([]int, 0)
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("customer_order_id").
Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
activity.Id, activity.RehearsalId, activity.ArchId).Find(&recordIds)
t.CheckErr(err)
s = s.NotIn("o.id", recordIds)
}
} else {
s = s.Table(&models.CustomerOrder{}).Alias("o").Select("o.buyer_id as user_id, "+
" o.phone, o.order_entry_person_name as entry_person_name, u.nickname as username, u.avatar").
Distinct("o.buyer_id").Join("LEFT", (&models.User{}).Alias("u"),
"o.buyer_id=u.id and u.is_delete=0").Where("o.activity_id=? and o.is_delete=0 "+
" and o.rehearsal_id=? and o.arch_id=?", activityId, activity.RehearsalId, activity.ArchId)
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
recordIds := make([]int, 0)
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("user_id").
Where("order_draw_rule_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
ruleId, activity.RehearsalId, activity.ArchId).Find(&recordIds)
t.CheckErr(err)
s = s.NotIn("o.buyer_id", recordIds)
}
}
err = session.Find(&result)
err = s.Find(&result)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -254,42 +283,40 @@ func (t *OrderDrawCtl) Users() {
// 订单抽奖动作
func (t *OrderDrawCtl) Draw() {
activityId := t.MustGetInt64("activity_id")
ruleId := t.MustGetInt64("order_draw_rule_id")
ladderId := t.MustGetInt64("order_draw_rule_ladder_id")
activityId := t.MustGetInt("activity_id")
ladderId := t.MustGetInt("order_draw_rule_ladder_id")
number := t.MustGetInt("number")
customerId := t.MustGetUID()
customerId := t.GetAccountId()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
customer := models.Customer{}
exist, err := models.Get(&customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
activity := models.Activity{}
exist, err = models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
area := new(models.AreaStore)
area := &models.AreaStore{}
exist, err = area.GetByCustomerId(customerId, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在")
rule := new(models.OrderDrawRule)
exist, err = models.Get(rule, ruleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在")
// 查询奖品
ladder := new(models.OrderDrawRuleLadder)
exist, err = models.Get(ladder, ladderId)
ladder := models.OrderDrawRuleLadder{}
exist, err = models.Get(&ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ORDER_LADDER_NOT_EXIST, "订单抽奖等级不存在")
t.CheckRunning(ladder.Status)
count, err := core.GetXormAuto().Where("order_draw_rule_id=? and order_draw_rule_ladder_id=? "+
"and rehearsal_id=? and is_delete=0", ruleId, ladderId, activity.RehearsalId).Count(new(models.OrderDrawRecord))
rule := models.OrderDrawRule{}
exist, err = models.Get(&rule, ladder.OrderDrawRuleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在")
count, err := (&models.OrderDrawRecord{}).Count(ladder.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
prizeNum := ladder.PrizeNumber - int(count)
if prizeNum <= 0 || prizeNum < number {
@ -299,57 +326,117 @@ func (t *OrderDrawCtl) Draw() {
module, exist, err := activity_service.GetModuleService(define.MODULE_ORDERLY, activity.Id)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块服务不存在")
userIds, err := lottery_service.GetOrderLotteryUserIds(module.BesideRepeat, activity.Id, rule.Id, ladder.Id, activity.RehearsalId, area.Id)
if len(userIds) < number {
t.ERROR("订单抽奖人数不足", code.MSG_LOTTERY_PEOPLE_NOT_ENOUGH)
}
if customer.IsSpecial == 2 {
orders, err := lottery_service.GetSpecialOrderLottery(module.BesideRepeat, activity.Id, rule.Id, ladder.Id, activity.RehearsalId, area.Id, activity.ArchId)
if len(orders) < number {
t.ERROR("抽奖订单数量不足", code.MSG_LOTTERY_PEOPLE_NOT_ENOUGH)
}
lottery_service.RandSpecialOrderLottery(orders)
winnerOrders := orders[:number]
userIds := make([]int, 0)
for _, v := range winnerOrders {
userIds = append(userIds, v.BuyerId)
}
users, err := models.GetUsersByIds(userIds)
t.CheckErr(err)
lottery_service.RandLotteryUserIds(userIds)
winnerIds := userIds[:number]
winners, err := lottery_service.GetLotteryUsers(winnerIds)
t.CheckErr(err)
for i := range winners {
winners[i].LadderId = ladder.Id
winners[i].PrizeImg = ladder.PrizeImg
winners[i].PrizeName = ladder.PrizeName
// 订单抽奖 ==> 存入我的奖品
userPrize := new(models.UserPrize)
userPrize.ActivityId = activityId
userPrize.RehearsalId = activity.RehearsalId
userPrize.ActivityName = activity.Name
userPrize.UserId = winners[i].UserId
userPrize.PrizeImg = ladder.PrizeImg
userPrize.PrizeName = ladder.PrizeName
userPrize.PrizeType = 2
userPrize.IsDelete = false
userPrize.CreatedAt = time.Now()
userPrize.UpdatedAt = time.Now()
_, err = core.GetXormAuto().Insert(userPrize)
winners := make([]*lottery_service.SpecialOrderLotteryUser, 0)
t.CheckErr(err)
for _, o := range winnerOrders {
for _, u := range users {
if u.Id == o.BuyerId {
winners = append(winners, &lottery_service.SpecialOrderLotteryUser{
UserId: u.Id,
Username: o.Receiver,
UserPhone: o.Phone,
Avatar: u.Avatar,
PrizeName: ladder.PrizeName,
LadderId: ladder.Id,
PrizeImg: ladder.PrizeImg,
EntryPersonName: o.OrderEntryPersonName,
})
}
}
prize := models.UserPrize{}
prize.ActivityId = activityId
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.UserId = o.BuyerId
prize.CustomerOrderId = o.Id
prize.PrizeImg = ladder.PrizeImg
prize.PrizeName = ladder.PrizeName
prize.ArchId = activity.ArchId
prize.PrizeType = 2
_, err = models.Add(&prize)
t.CheckErr(err)
record := models.OrderDrawRecord{}
record.UserPrizeId = prize.Id
record.ActivityId = activityId
record.RehearsalId = activity.RehearsalId
record.ArchId = activity.ArchId
record.OrderDrawActivityId = rule.OrderDrawActivityId
record.OrderDrawRuleId = rule.Id
record.UserId = o.BuyerId
record.CustomerOrderId = o.Id
record.OrderDrawRuleLadderId = ladder.Id
record.PrizeName = ladder.PrizeName
record.OrderEntryPersonName = o.OrderEntryPersonName
record.AreaId = area.Id
record.AreaName = area.Name
_, err = models.Add(&record)
t.CheckErr(err)
}
t.JSON(winners)
} else {
userIds, err := lottery_service.GetOrderLotteryUserIds(module.BesideRepeat, activity.Id, rule.Id, ladder.Id, activity.RehearsalId, area.Id, activity.ArchId)
if len(userIds) < number {
t.ERROR("订单抽奖人数不足", code.MSG_LOTTERY_PEOPLE_NOT_ENOUGH)
}
record := new(models.OrderDrawRecord)
record.UserPrizeId = userPrize.Id
record.ActivityId = activityId
record.RehearsalId = activity.RehearsalId
record.OrderDrawActivityId = rule.OrderDrawActivityId
record.OrderDrawRuleId = rule.Id
record.UserId = winners[i].UserId
record.OrderDrawRuleLadderId = ladder.Id
record.PrizeName = ladder.PrizeName
record.AreaId = area.Id
record.AreaName = area.Name
record.IsDelete = false
record.CreatedAt = time.Now()
record.UpdatedAt = time.Now()
_, err = core.GetXormAuto().InsertOne(record)
lottery_service.RandLotteryUserIds(userIds)
winnerIds := userIds[:number]
winners, err := lottery_service.GetLotteryUsers(winnerIds)
t.CheckErr(err)
for i := range winners {
winners[i].LadderId = ladder.Id
winners[i].PrizeImg = ladder.PrizeImg
winners[i].PrizeName = ladder.PrizeName
prize := models.UserPrize{}
prize.ActivityId = activityId
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.UserId = winners[i].UserId
prize.PrizeImg = ladder.PrizeImg
prize.PrizeName = ladder.PrizeName
prize.ArchId = activity.ArchId
prize.PrizeType = 2
_, err = models.Add(&prize)
t.CheckErr(err)
record := models.OrderDrawRecord{}
record.UserPrizeId = prize.Id
record.ActivityId = activityId
record.RehearsalId = activity.RehearsalId
record.ArchId = activity.ArchId
record.OrderDrawActivityId = rule.OrderDrawActivityId
record.OrderDrawRuleId = rule.Id
record.UserId = winners[i].UserId
record.OrderDrawRuleLadderId = ladder.Id
record.PrizeName = ladder.PrizeName
record.AreaId = area.Id
record.AreaName = area.Name
_, err = models.Add(&record)
t.CheckErr(err)
}
t.JSON(winners)
}
t.JSON(winners)
}
type WinnerResult struct {
UserId int64 `json:"user_id"`
UserId int `json:"user_id"`
Username string `json:"user_name"`
UserPhone string `json:"user_phone"`
Avatar string `json:"avatar"`
@ -357,10 +444,34 @@ type WinnerResult struct {
}
func (t *OrderDrawCtl) ListOfWinners() {
orderDrawRuleId := t.MustGetInt64("order_draw_rule_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt("order_draw_rule_id")
rule := &models.OrderDrawRule{}
exist, err := models.Get(rule, ruleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在")
lottery := &models.OrderDrawActivity{}
exist, err = models.Get(lottery, rule.OrderDrawActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, lottery.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
result, err := lottery_service.GetOrderWinnersResult(orderDrawRuleId, rehearsalId)
var result []*lottery_service.OrderWinnersResult
if customer.IsSpecial == 2 {
result, err = lottery_service.GetSpecialOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId)
} else {
result, err = lottery_service.GetOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId)
}
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
@ -371,7 +482,7 @@ func (t *OrderDrawCtl) ListOfWinners() {
// 获取所有订单
type OrdersResult struct {
UserId int64 `json:"user_id"`
UserId int `json:"user_id"`
AreaName string `json:"area_name"`
GoodsName string `json:"goods_name"`
Nickname string `json:"nickname"`
@ -379,36 +490,112 @@ type OrdersResult struct {
Extra []map[string]interface{} `json:"extra"`
}
// 获取所有订单
type SpecialOrdersResult struct {
Id int `json:"id"`
UserId int `json:"user_id"`
AreaName string `json:"area_name"`
EntryPersonName string `json:"entry_person_name"`
Username string `json:"username"`
Phone string `json:"phone"`
Address string `json:"address"`
Goods []*models.SubOrderResult `json:"goods"`
}
func (t *OrderDrawCtl) Orders() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
orders := make([]*OrdersResult, 0)
err := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o").
Select("o.area_name, o.goods_name, o.buyer_id as user_id, u.nickname, l.extra_data as extra_data, o.created_at").
Distinct("o.id").Join("LEFT", new(models.InvitationLetter).Alias("l"),
"o.buyer_id=l.user_id and o.activity_id=l.activity_id and l.is_delete=0").
Join("LEFT", new(models.User).Alias("u"), "u.id=o.buyer_id and u.is_delete=0").
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=?", activityId, rehearsalId).
Asc("o.created_at").Find(&orders)
customer := models.Customer{}
exist, err = models.Get(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
items, err := invitation_service.GetOptionItem(activityId)
t.CheckErr(err)
for i := range orders {
data, err := invitation_service.GetOptionValue(items, orders[i].ExtraData)
if customer.IsSpecial == 2 {
count, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, 0)
orders := make([]*SpecialOrdersResult, 0)
err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as id, "+
" o.area_name as area_name, o.order_entry_person_name as entry_person_name, o.buyer_id as user_id, "+
" o.receiver as username, o.phone as phone, o.address as address, o.created_at").
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
activityId, activity.RehearsalId, activity.ArchId).Asc("o.created_at").Find(&orders)
t.CheckErr(err)
orderIds := make([]int, 0)
for _, o := range orders {
orderIds = append(orderIds, o.Id)
}
subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds)
t.CheckErr(err)
for i := range orders {
for j := range subs {
if orders[i].Id == subs[j].OrderId {
orders[i].Goods = append(orders[i].Goods, subs[j])
}
}
}
t.JSON(map[string]interface{}{
"orders": orders,
"total": len(orders),
"buyer_count": count,
})
return
} else {
count, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, 1)
orders := make([]*OrdersResult, 0)
err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as id, "+
" o.area_name, o.order_entry_person_name as entry_person_name, o.buyer_id as user_id, o.goods_name, "+
" o.receiver as nickname, o.phone as phone, o.address as address, o.created_at, l.extra_data").
Distinct("o.id").Join("LEFT", (&models.InvitationLetter{}).Alias("l"),
"o.buyer_id=l.user_id and l.rehearsal_id=? and l.arch_id=?", activity.RehearsalId, activity.ArchId).
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?",
activityId, activity.RehearsalId, activity.ArchId).
Asc("o.created_at").Find(&orders)
t.CheckErr(err)
items, err := invitation_service.GetOptionItem(activityId)
t.CheckErr(err)
orders[i].Extra = data
for i := range orders {
data, err := invitation_service.GetOptionValue(items, orders[i].ExtraData)
t.CheckErr(err)
orders[i].Extra = data
}
t.JSON(map[string]interface{}{
"orders": orders,
"total": len(orders),
"buyer_count": count,
})
return
}
}
// 下订单人数
buyerCount, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=?",
activityId, rehearsalId).Distinct("buyer_id").Count(new(models.CustomerOrder))
// 录入人员排行榜
func (t *OrderDrawCtl) OrderRank() {
activityId := t.MustGetInt("activity_id")
limit := t.MustGetInt("limit")
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
order := &models.CustomerOrder{}
res, err := order.SumCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, limit)
t.CheckErr(err)
var total int64 = 0
if len(res) == 1 && res[0]["num"] == "0" {
res = nil
} else {
total, err = order.TotalCustomerOrderGoodsNum(activity.Id, activity.RehearsalId, activity.ArchId)
}
t.CheckErr(err)
t.JSON(map[string]interface{}{
"orders": orders,
"total": len(orders),
"buyer_count": buyerCount,
"list": res,
"total": total,
})
}

50
controllers/pc/reward.go

@ -6,7 +6,7 @@ import (
"hudongzhuanjia/models"
bully_reward_service "hudongzhuanjia/services/bully_reward"
im_service "hudongzhuanjia/services/im"
"hudongzhuanjia/services/pay"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"strings"
@ -19,16 +19,20 @@ type RewardCtl struct {
//获取最新的打赏记录
func (t *RewardCtl) Latest() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//获取打赏服务得id
server := new(models.RewardServer)
exist, err := server.GetByActivityId(activityId)
exist, err = server.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
result, err := bully_reward_service.GetRewardLatest(server.Id, rehearsalId)
result, err := bully_reward_service.GetRewardLatest(server.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
if result == nil || result.Id == 0 {
t.JSON(result)
@ -48,19 +52,23 @@ func (t *RewardCtl) Latest() {
//获取待审核列表
func (t *RewardCtl) WaitReview() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//获取打赏服务得id
server := new(models.RewardServer)
exist, err := server.GetByActivityId(activityId)
exist, err = server.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
//// todo: 检查订单
//t.CheckErr(bully_reward_service.CheckRewardStatus(server.Id))
go bully_reward_service.CheckRewardStatus(server.Id, activity.ArchId)
result, err := bully_reward_service.GetRewardReview(server.Id, rehearsalId)
result, err := bully_reward_service.GetRewardReview(server.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
//根据打赏服务得id获取待审核得打赏列表
@ -74,7 +82,7 @@ func (t *RewardCtl) WaitReview() {
func (t *RewardCtl) Review() {
status := t.MustGetBool("status")
ids := strings.Split(t.MustGet("ids"), "|")
uid := t.MustGetUID()
uid := t.GetAccountId()
result, err := models.GetRewardHistoryByIds(ids)
t.CheckErr(err)
@ -105,6 +113,7 @@ func (t *RewardCtl) Review() {
go im_service.SendGroupCustomMessage(v.UserId, v.ActivityId, im_service.NoticeReward,
map[string]interface{}{
"admin": 1,
"amount": v.Amount,
"content": v.Content,
})
@ -132,19 +141,20 @@ func (t *RewardCtl) Review() {
//获取打赏得总金额
func (t *RewardCtl) Amount() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//获取打赏服务得id
server := new(models.RewardServer)
exist, err = server.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId)
totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.DisplayByData(map[string]interface{}{
@ -154,18 +164,22 @@ func (t *RewardCtl) Amount() {
// 黑名单
func (t *RewardCtl) Blacklist() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
// 获取打赏的服务id
server := new(models.RewardServer)
exist, err := server.GetByActivityId(activityId)
exist, err = server.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
// 根据打赏服务id获取待审核的名单
// status=true 代表审核不通过还是通过
// 目前表示不通过,bully_screen也一样
result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
result, err := bully_reward_service.GetRewardBlacklist(server.Id, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -176,7 +190,7 @@ func (t *RewardCtl) Blacklist() {
// 开启打赏
func (t *RewardCtl) Details() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
server := new(models.RewardServer)
exist, err := server.GetByActivityId(activityId)
t.CheckErr(err)

101
controllers/pc/shake_red_envelope.go

@ -2,7 +2,6 @@ package pc
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
im_service "hudongzhuanjia/services/im"
@ -11,6 +10,8 @@ import (
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type ShakeRedEnvelopeCtl struct {
@ -18,7 +19,7 @@ type ShakeRedEnvelopeCtl struct {
}
func (t *ShakeRedEnvelopeCtl) Ready() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
rule := new(models.ShakeRedEnvelopeRule)
exist, err := models.Get(rule, ruleId)
@ -38,9 +39,7 @@ func (t *ShakeRedEnvelopeCtl) Ready() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
// done: 把其他的准备中的状态改为未开始
// 又一个坑, 红包的 轮次根据 activity_id
sids := make([]int64, 0)
sids := make([]int, 0)
err = core.GetXormAuto().Table(new(models.ShakeRedEnvelopeActivity)).Select("id").
Where("is_delete=0 and activity_id=?", activity.Id).Find(&sids)
t.CheckErr(err)
@ -55,8 +54,8 @@ func (t *ShakeRedEnvelopeCtl) Ready() {
//开始摇红包
func (t *ShakeRedEnvelopeCtl) Start() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
uid := t.MustGetUID()
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
uid := t.GetAccountId()
//根据摇红包规则id查找该条记录并且更给状态
rule := new(models.ShakeRedEnvelopeRule)
@ -83,7 +82,7 @@ func (t *ShakeRedEnvelopeCtl) Start() {
_, err = rule.UpdateStatus(ruleId, define.StatusRunning)
t.CheckErr(err)
err = red_envelope_service.GenRedEnvelope(activity.Id, activity.Name, activity.RehearsalId, rule)
err = red_envelope_service.GenRedEnvelope(activity.Id, activity.Name, activity.RehearsalId, rule, activity.ArchId)
t.CheckErr(err)
// 彩排不用发送到直播间
@ -94,6 +93,7 @@ func (t *ShakeRedEnvelopeCtl) Start() {
if exist && live.HaveModule(define.MODULE_SHAKRB) {
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackStart,
map[string]interface{}{
"admin": 1,
"customer_id": uid,
"shake_red_envelope_rule_id": rule.Id,
"timestamp": time.Now().Unix(),
@ -106,8 +106,8 @@ func (t *ShakeRedEnvelopeCtl) Start() {
//停止摇红包
func (t *ShakeRedEnvelopeCtl) Stop() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
uid := t.MustGetUID()
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
uid := t.GetAccountId()
rule := new(models.ShakeRedEnvelopeRule)
exist, err := models.Get(rule, ruleId)
@ -136,6 +136,7 @@ func (t *ShakeRedEnvelopeCtl) Stop() {
if exist && live.HaveModule(define.MODULE_SHAKRB) {
go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackEnd,
map[string]interface{}{
"admin": 1,
"customer_id": uid,
"shake_red_envelope_rule_id": rule.Id,
"timestamp": time.Now().Unix(),
@ -147,13 +148,13 @@ func (t *ShakeRedEnvelopeCtl) Stop() {
}
func (t *ShakeRedEnvelopeCtl) List() {
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
customerId := t.GetAccountId()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(customerId, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, activityId)
@ -164,23 +165,15 @@ func (t *ShakeRedEnvelopeCtl) List() {
list := make([]*models.ShakeRedEnvelopeActivity, 0)
total, err := core.GetXormAuto().Where("is_delete=0 and is_pay=1 and activity_id=?", activityId).FindAndCount(&list)
t.CheckErr(err)
aIds := make([]int64, 0)
aIds := make([]int, 0)
for _, v := range list {
aIds = append(aIds, v.Id)
}
area := new(models.AreaStore)
if customer.Pid == 0 {
exist, err = area.GetMainAreaById(activityId)
} else {
exist, err = area.GetAreaStoreById(t.MustGetAreaId())
}
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在")
rules := make([]*models.ShakeRedEnvelopeRule, 0)
err = core.GetXormAuto().Where("is_delete=0 and area_id=?", area.Id).In("shake_red_envelope_activity_id", aIds).Find(&rules)
t.CheckErr(err)
rIds := make([]int64, 0)
rIds := make([]int, 0)
for _, v := range rules {
rIds = append(rIds, v.Id)
}
@ -190,6 +183,7 @@ func (t *ShakeRedEnvelopeCtl) List() {
for i := range ladders {
if rules[index].Id == ladders[i].ShakeRedEnvelopeRuleId {
rules[index].ShakeRedEnvelopeRuleLadders = append(rules[index].ShakeRedEnvelopeRuleLadders, ladders[i])
rules[index].RedEnvelopeNum += ladders[i].RedEnvelopeNum
}
}
}
@ -214,10 +208,10 @@ func (t *ShakeRedEnvelopeCtl) List() {
//二维码
func (t *ShakeRedEnvelopeCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetUID()
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
activityId := t.MustGetInt("activity_id")
customerId := t.GetAccountId()
rehearsalId := t.MustGetInt("rehearsal_id")
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(customerId, activityId)
@ -245,13 +239,28 @@ type ShakeRedEnvelopeRecordAndUser struct {
// 参数优化
func (t *ShakeRedEnvelopeCtl) Winners() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
rule := &models.ShakeRedEnvelopeRule{}
exist, err := models.Get(rule, ruleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SHAKERB_RULE_NOT_EXIST, "红包规则不存在")
redEnvelope := &models.ShakeRedEnvelopeActivity{}
exist, err = models.Get(redEnvelope, rule.ShakeRedEnvelopeActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SHAKERB_RULE_NOT_EXIST, "红包活动不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, redEnvelope.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
records := make([]*ShakeRedEnvelopeRecordAndUser, 0)
err := core.GetXormAuto().Table(new(models.ShakeRedEnvelopeRecord)).Alias("r").
Join("LEFT", models.AliasTableName(new(models.User), "u"), "r.user_id=u.id and u.is_delete=0").
Where("r.shake_red_envelope_rule_id=? and is_draw<>-1 and r.is_delete=0 and r.rehearsal_id=?",
ruleId, rehearsalId).OrderBy("r.created_at desc").Find(&records)
err = core.GetXormAuto().Table(new(models.ShakeRedEnvelopeRecord)).Alias("r").
Join("LEFT", models.Alias(new(models.User), "u"), "r.user_id=u.id and u.is_delete=0").
Where("r.shake_red_envelope_rule_id=? and is_draw<>-1 and r.is_delete=0 and r.rehearsal_id=? and r.arch_id=?",
ruleId, activity.RehearsalId, activity.ArchId).OrderBy("r.created_at desc").Find(&records)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(records),
@ -261,20 +270,30 @@ func (t *ShakeRedEnvelopeCtl) Winners() {
// 统计摇红包参与人数和剩余红包数量
func (t *ShakeRedEnvelopeCtl) Count() {
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt("shake_red_envelope_rule_id")
rule := new(models.ShakeRedEnvelopeRule)
exist, err := models.Get(rule, ruleId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "摇红包轮次不存在")
numU, err := core.GetXormAuto().Where("is_delete=0 and shake_red_envelope_rule_id=? and rehearsal_id=?",
ruleId, rehearsalId).Count(new(models.ShakeRedEnvelopeUser))
redEnvelope := &models.ShakeRedEnvelopeActivity{}
exist, err = models.Get(redEnvelope, rule.ShakeRedEnvelopeActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SHAKERB_RULE_NOT_EXIST, "红包活动不存在")
activity := &models.Activity{}
exist, err = models.Get(activity, redEnvelope.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
numU, err := core.GetXormAuto().Where("is_delete=0 and shake_red_envelope_rule_id=? and rehearsal_id=? and arch_id=?",
ruleId, activity.RehearsalId, activity.ArchId).Count(new(models.ShakeRedEnvelopeUser))
t.CheckErr(err)
numR, err := core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and shake_red_envelope_rule_id=? and rehearsal_id=?",
ruleId, rehearsalId).Count(new(models.ShakeRedEnvelopeRecord))
numR, err := core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and shake_red_envelope_rule_id=? "+
" and rehearsal_id=? and arch_id=?", ruleId, activity.RehearsalId, activity.ArchId).
Count(new(models.ShakeRedEnvelopeRecord))
t.CheckErr(err)
t.JSON(map[string]interface{}{

67
controllers/pc/sign.go

@ -7,8 +7,6 @@ import (
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"strings"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
//签到
@ -18,9 +16,9 @@ type SignCtl struct {
//获取二维码
func (t *SignCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
signUpId := t.MustGetInt64("sign_rule_id")
activityId := t.MustGetInt("activity_id")
uid := t.GetAccountId()
signUpId := t.MustGetInt("sign_rule_id")
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(uid, activityId)
@ -44,7 +42,7 @@ func (t *SignCtl) Qrcode() {
//获取签到模式
func (t *SignCtl) Mode() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
//通过activity_id查询ox_sign_rule的id
signUp := new(models.SignUp)
@ -56,14 +54,12 @@ func (t *SignCtl) Mode() {
}
func (t *SignCtl) List() {
activityId := t.MustGetInt64("activity_id")
signUps := make([]*models.SignUp, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Asc("created_at").Find(&signUps)
activityId := t.MustGetInt("activity_id")
sus, err := models.ListSignUp(activityId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(signUps),
"list": signUps,
"total": len(sus),
"list": sus,
})
}
@ -74,19 +70,14 @@ type SignResult struct {
//处理签到信息
func (t *SignCtl) SignInfo() {
aid := t.MustGetInt64("activity_id")
//activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
result := make([]*SignResult, 0)
session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h").
Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
Where("h.is_delete=0 and h.activity_id=? and rehearsal_id=?", aid, rehearsalId)
if t.PageSize > 0 { // 增加分页
session.Limit(t.PageSize, t.Page*t.PageSize)
}
count, err := session.FindAndCount(&result)
activityId := t.MustGetInt("activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
count, result, err := models.GetSignHistories(activity.Id, activity.RehearsalId, activity.ArchId, t.Page, t.PageSize)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -97,21 +88,37 @@ func (t *SignCtl) SignInfo() {
// 实名签到信息
func (t *SignCtl) RealSignInfo() {
aid := t.MustGetInt64("activity_id")
rid := t.MustGetInt64("rehearsal_id")
results, err := models.GetApplyRealSigns(aid, rid)
aid := t.MustGetInt("activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, aid)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
results, err := models.GetApplyRealSigns(activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
total, err := new(models.RealSignList).Count(activity.Id)
t.CheckErr(err)
signTotal, err := new(models.SignHistory).Count(activity.Id, activity.ArchId, activity.RehearsalId, 2)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"result": results,
"count": len(results),
"result": results,
"count": len(results),
"total": total,
"sign_total": signTotal,
"no_sign_total": total - signTotal,
})
}
// 审核实名签到
func (t *SignCtl) RealSignVerify() {
ids := strings.Split(t.MustGet("real_sign_history_ids"), ",")
history := new(models.SignHistory)
history.Status = 2
err := history.UpdateById(ids, "status")
err := history.UpdateByIds(ids, "status")
t.CheckErr(err)
t.SUCCESS("审核成功")
}

84
controllers/pc/tug_war.go

@ -17,7 +17,7 @@ type TugOfWarCtl struct {
}
func (t *TugOfWarCtl) Ready() { // 准备中
baheId := t.MustGetInt64("bahe_activity_id")
baheId := t.MustGetInt("bahe_activity_id")
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheId)
@ -67,7 +67,7 @@ func (t *TugOfWarCtl) Ready() { // 准备中
}
func (t *TugOfWarCtl) Start() {
baheId := t.MustGetInt64("bahe_activity_id")
baheId := t.MustGetInt("bahe_activity_id")
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheId)
@ -83,7 +83,7 @@ func (t *TugOfWarCtl) Start() {
}
func (t *TugOfWarCtl) Stop() {
baheId := t.MustGetInt64("bahe_activity_id")
baheId := t.MustGetInt("bahe_activity_id")
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheId)
@ -101,13 +101,22 @@ func (t *TugOfWarCtl) Stop() {
}
func (t *TugOfWarCtl) Team() {
baheId := t.MustGetInt64("bahe_activity_id")
customerId := t.MustGetUID()
baheId := t.MustGetInt("bahe_activity_id")
customerId := t.GetAccountId()
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
bahe := new(models.TugOfWar)
exist, err := models.Get(bahe, baheId)
exist, err = models.Get(bahe, baheId)
t.CheckErr(err)
t.Assert(exist, code.MSG_TUGWAR_NOT_EXIST, "拔河不存在")
if bahe.Status == define.StatusNotBegin {
t.ERROR("拔河尚未开始", code.MSG_TUGWAR_NOT_EXIST)
return
}
activity := new(models.Activity)
exist, err = models.Get(activity, bahe.ActivityId)
@ -127,10 +136,14 @@ func (t *TugOfWarCtl) Team() {
// 队伍颜色
qrcode := ""
// 二维码
link := define.H5TugOfWar
if customer.IsSpecial == 1 {
link = define.H5TugOfWar2020
}
if bahe.Model != "随机分配模式" {
// 非随机模式,自选队伍
for index := range teams {
qrcode, err = utils.GenH5Qrcode(define.H5TugOfWar, map[string]interface{}{
qrcode, err = utils.GenH5Qrcode(link, map[string]interface{}{
"area_id": area.Id,
"activity_id": bahe.ActivityId,
"customer_id": customerId,
@ -142,7 +155,7 @@ func (t *TugOfWarCtl) Team() {
teams[index].Qrcode = qrcode
}
} else {
qrcode, err = utils.GenH5Qrcode(define.H5TugOfWar, map[string]interface{}{
qrcode, err = utils.GenH5Qrcode(link, map[string]interface{}{
"area_id": area.Id,
"activity_id": bahe.ActivityId,
"customer_id": customerId,
@ -162,18 +175,28 @@ func (t *TugOfWarCtl) Team() {
}
func (t *TugOfWarCtl) Member() {
baheId := t.MustGetInt64("bahe_activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
baheId := t.MustGetInt("bahe_activity_id")
bahe := &models.TugOfWar{}
exist, err := models.Get(bahe, baheId)
t.CheckErr(err)
t.Assert(exist, code.MSG_TUGWAR_NOT_EXIST, "拔河不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, bahe.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
teams := make([]*models.BaheTeam, 0)
err := core.GetXormAuto().Where("is_delete=0 and bahe_activity_id=?", baheId).Find(&teams)
err = core.GetXormAuto().Where("is_delete=0 and bahe_activity_id=?", baheId).Find(&teams)
t.CheckErr(err)
var total int64 = 0
for index := range teams {
members := make([]*models.BaheTeamMember, 0)
num, err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
teams[index].Id, rehearsalId).Desc("score").Asc("sort_time").FindAndCount(&members)
num, err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=? and arch_id=?",
teams[index].Id, activity.RehearsalId, activity.ArchId).Desc("score").
Asc("sort_time").FindAndCount(&members)
t.CheckErr(err)
total += num
teams[index].Members = members
@ -186,31 +209,41 @@ func (t *TugOfWarCtl) Member() {
}
type BaheScoreResult struct {
TotalScore int64 `json:"total_score" description:"总分数"`
Id int64 `json:"id" description:"id"`
ActivityId int64 `json:"activity_id" description:"活动id"`
BaheActivityId int64 `json:"bahe_activity_id" description:"拔河活动id"`
TotalScore int `json:"total_score" description:"总分数"`
Id int `json:"id" description:"id"`
ActivityId int `json:"activity_id" description:"活动id"`
BaheActivityId int `json:"bahe_activity_id" description:"拔河活动id"`
BaheTeamName string `json:"bahe_team_name" description:"拔河队伍得名称"`
Members []*models.BaheTeamMember `json:"members"`
}
func (t *TugOfWarCtl) Score() {
baheActivityId := t.MustGetInt64("bahe_activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
baheId := t.MustGetInt("bahe_activity_id")
bahe := &models.TugOfWar{}
exist, err := models.Get(bahe, baheId)
t.CheckErr(err)
t.Assert(exist, code.MSG_TUGWAR_NOT_EXIST, "拔河不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, bahe.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
teams := make([]*BaheScoreResult, 0)
err := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t").
err = core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t").
Select("sum(m.score) as total_score, t.id, t.activity_id, t.bahe_activity_id, t.bahe_team_name").
Join("LEFT", new(models.BaheTeamMember).Alias("m"),
"t.id=m.team_id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
Where("t.is_delete=0 and t.bahe_activity_id=?", baheActivityId).
"t.id=m.team_id and m.is_delete=0 and m.rehearsal_id=? and m.arch_id=?",
activity.RehearsalId, activity.ArchId).Where("t.is_delete=0 and t.bahe_activity_id=?", baheId).
GroupBy("t.id").Find(&teams)
t.CheckErr(err)
for index := range teams {
members := make([]*models.BaheTeamMember, 0)
err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?", teams[index].Id, rehearsalId).
Desc("score").Asc("sort_time").Find(&members)
err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=? and arch_id=?",
teams[index].Id, activity.RehearsalId, activity.ArchId).Desc("score").
Asc("sort_time").Find(&members)
t.CheckErr(err)
teams[index].Members = members
}
@ -221,7 +254,8 @@ func (t *TugOfWarCtl) Score() {
}
func (t *TugOfWarCtl) List() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
bahes := make([]*models.TugOfWar, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Asc("created_at").Find(&bahes)

70
controllers/pc/upper_wall.go

@ -24,13 +24,18 @@ type UpperWallResult struct {
//获取所有已审核的上墙消息
func (t *UpperWallCtl) List() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
result := make([]*UpperWallResult, 0)
err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
err = core.GetXormAuto().Table("ox_upper_wall").Alias("w").
Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
Where("w.is_delete=0 and w.status=3 and w.activity_id=? and w.rehearsal_id=?", activityId, rehearsalId).
Where("w.is_delete=0 and w.status=3 and w.activity_id=? and w.rehearsal_id=? and arch_id=?",
activityId, activity.RehearsalId, activity.ArchId).
OrderBy("w.review_time desc").Find(&result)
t.CheckErr(err)
@ -42,14 +47,19 @@ func (t *UpperWallCtl) List() {
//获取待审核列表
func (t *UpperWallCtl) WaitReview() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//根据霸屏服务得id获取待审核得霸屏列表
result := make([]*UpperWallResult, 0)
err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
err = core.GetXormAuto().Table("ox_upper_wall").Alias("w").
Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
Where("w.is_delete=0 and w.status=0 and w.activity_id=? and w.rehearsal_id=?", activityId, rehearsalId).
Where("w.is_delete=0 and w.status=0 and w.activity_id=? and w.rehearsal_id=? and arch_id=?",
activityId, activity.RehearsalId, activity.ArchId).
OrderBy("w.review_time desc").Find(&result)
t.CheckErr(err)
@ -63,8 +73,7 @@ func (t *UpperWallCtl) WaitReview() {
func (t *UpperWallCtl) Review() {
idList := t.MustGet("ids")
status := t.MustGetBool("status")
uid := t.MustGetUID()
uid := t.GetAccountId()
ids := strings.Split(idList, "|")
customer := new(models.Customer)
@ -87,10 +96,9 @@ func (t *UpperWallCtl) Review() {
// false 通过
if !status {
result := make([]*UpperWallResult, 0)
err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
Where("w.is_delete=0").In("w.id", ids).
OrderBy("w.created_at asc").Find(&result)
err := core.GetXormAuto().Table(&models.UpperWall{}).Alias("w").
Join("LEFT", (&models.User{}).Alias("u"), "w.user_id=u.id and u.is_delete=0").
Where("w.is_delete=0").In("w.id", ids).Asc("w.created_at").Find(&result)
t.CheckErr(err)
if len(result) == 0 {
t.ERROR("不存在上墙消息", code.MSG_DATA_NOT_EXIST)
@ -117,15 +125,18 @@ func (t *UpperWallCtl) Review() {
//获取黑名单列表
func (t *UpperWallCtl) Blacklist() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
result := make([]*UpperWallResult, 0)
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
result := make([]*UpperWallResult, 0)
err = core.GetXormAuto().Table("ox_upper_wall").Alias("w").
Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
Where("w.is_delete=0 and w.status=1 and w.status=1 and w.rehearsal_id=? and w.activity_id=?",
rehearsalId, activityId).OrderBy("review_time desc").Find(&result)
Where("w.is_delete=0 and w.status=1 and w.rehearsal_id=? and w.activity_id=? and w.arch_id=?",
activity.RehearsalId, activity.Id, activity.ArchId).Desc("w.review_time").Find(&result)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -136,11 +147,15 @@ func (t *UpperWallCtl) Blacklist() {
//获取目前上墙得总条数
func (t *UpperWallCtl) Total() {
activityId := t.MustGetInt64("activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
total, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=3",
activityId, rehearsalId).Count(new(models.UpperWall))
total, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=? and status=3",
activityId, activity.RehearsalId, activity.ArchId).Count(new(models.UpperWall))
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -151,8 +166,8 @@ func (t *UpperWallCtl) Total() {
//二维码
// 跳到主页
func (t *UpperWallCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
uid := t.GetAccountId()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
@ -178,12 +193,13 @@ func (t *UpperWallCtl) Qrcode() {
}
func (t *UpperWallCtl) Details() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
msgWall := new(models.MsgWallServer)
exist, err := msgWall.GetByActivityId(activityId)
t.CheckErr(err)
if !exist {
t.ERROR("上墙服务模块不存在", code.MSG_ERR)
return
}
t.JSON(map[string]interface{}{
"msg_wall": msgWall,

59
controllers/pc/vote.go

@ -2,7 +2,6 @@ package pc
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
@ -10,6 +9,8 @@ import (
"hudongzhuanjia/utils/define"
"strconv"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type VoteCtl struct {
@ -18,9 +19,9 @@ type VoteCtl struct {
//二维码
func (t *VoteCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
voteActivityId := t.MustGetInt64("vote_activity_id")
uid := t.MustGetUID()
activityId := t.MustGetInt("activity_id")
voteActivityId := t.MustGetInt("vote_activity_id")
uid := t.GetAccountId()
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(uid, activityId)
@ -43,7 +44,7 @@ func (t *VoteCtl) Qrcode() {
// 装备数据
func (t *VoteCtl) ReadyVote() {
voteId := t.MustGetInt64("vote_activity_id")
voteId := t.MustGetInt("vote_activity_id")
vote := new(models.NewVoteActivity)
exist, err := models.Get(vote, voteId)
t.CheckErr(err)
@ -66,14 +67,15 @@ func (t *VoteCtl) ReadyVote() {
t.CheckErr(err)
}
_, err = vote.UpdateStatusById(vote.Id, define.StatusReady)
vote.VoteStatus = define.StatusReady
_, err = models.Update(voteId, vote, "vote_status")
t.CheckErr(err)
t.SUCCESS("success")
}
//开始投票
func (t *VoteCtl) StartVote() {
voteId := t.MustGetInt64("vote_activity_id")
voteId := t.MustGetInt("vote_activity_id")
vote := new(models.NewVoteActivity)
exist, err := models.Get(vote, voteId)
t.CheckErr(err)
@ -82,6 +84,7 @@ func (t *VoteCtl) StartVote() {
if vote.VoteStatus != define.StatusReady {
t.ERROR(fmt.Sprintf("该活动%s", vote.VoteStatus), code.MSG_ERR)
}
// 将所有被投票人置0
vote.VoteStatus = define.StatusRunning
vote.UpdatedAt = time.Now()
if vote.VoteLastTime == "" {
@ -89,15 +92,14 @@ func (t *VoteCtl) StartVote() {
}
duration, _ := strconv.ParseInt(vote.VoteLastTime, 10, 64)
vote.VoteEndTime = time.Now().Unix() + duration
_, err = core.GetXormAuto().Where("is_delete=0 and id=?", voteId).
Cols("vote_status", "vote_end_time", "updated_at").Update(vote)
_, err = models.Update(voteId, vote, "vote_status", "vote_end_time")
t.CheckErr(err)
t.SUCCESS("操作成功")
}
//停止投票
func (t *VoteCtl) StopVote() {
voteId := t.MustGetInt64("vote_activity_id")
voteId := t.MustGetInt("vote_activity_id")
vote := new(models.NewVoteActivity)
exist, err := models.Get(vote, voteId)
@ -111,8 +113,7 @@ func (t *VoteCtl) StopVote() {
vote.VoteStatus = define.StatusEnding
vote.UpdatedAt = time.Now()
vote.VoteEndTime = 0
_, err = core.GetXormAuto().Where("is_delete=0 and id=?", voteId).
Cols("vote_status", "updated_at", "vote_end_time").Update(vote)
_, err = models.Update(voteId, vote, "vote_status", "vote_end_time")
t.CheckErr(err)
t.SUCCESS("操作成功")
@ -120,22 +121,38 @@ func (t *VoteCtl) StopVote() {
//获取参与人数
func (t *VoteCtl) JoinTotal() {
voteActivityId := t.MustGetInt64("vote_activity_id")
rehearsalId := t.MustGetInt64("rehearsal_id")
total, err := core.GetXormAuto().Distinct("user_id").Where("vote_activity_id=? and rehearsal_id=? and is_delete=0",
voteActivityId, rehearsalId).Count(new(models.NewVoteActivityHistory))
voteActivityId := t.MustGetInt("vote_activity_id")
vote := models.NewVoteActivity{}
exist, err := models.Get(vote, voteActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_VOTE_ACTIVITY_NOT_EXIST, "投票活动不存在")
activity := new(models.Activity)
exist, err = models.Get(activity, vote.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
total, err := core.GetXormAuto().Distinct("user_id").Where("vote_activity_id=? and rehearsal_id=? "+
" arch_id=? and is_delete=0", voteActivityId, activity.RehearsalId, activity.ArchId).
Count(new(models.NewVoteActivityHistory))
t.CheckErr(err)
t.JSON(total)
}
//获取所有的投票活动
func (t *VoteCtl) List() {
activityId := t.MustGetInt64("activity_id")
activityId := t.MustGetInt("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
votes, err := models.GetVoteListByActivityId(activityId)
votes, err := models.GetVoteListByActivityId(activityId, activity.ArchId)
t.CheckErr(err)
ids := make([]int64, 0)
ids := make([]int, 0)
for _, v := range votes {
ids = append(ids, v.Id)
}
@ -159,10 +176,10 @@ func (t *VoteCtl) List() {
//获取投票的前几(头像、姓名、票数)
func (t *VoteCtl) History() {
voteActivityId := t.MustGetInt64("vote_activity_id")
voteId := t.MustGetInt("vote_activity_id")
total := t.MustGetInt("total")
ladders, err := models.GetNewVoteTopByVoteActivityId(voteActivityId, total)
ladders, err := models.GetNewVoteTopByVoteActivityId(voteId, total)
t.CheckErr(err)
t.JSON(ladders)
}

38
controllers/pc/ws.go

@ -6,6 +6,8 @@ import (
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"strings"
"time"
)
@ -15,8 +17,8 @@ type WsCtl struct {
// ws doc
func (t *WsCtl) Ops() {
customerId := t.MustGetUID()
activityId, _ := t.GetInt64("activity_id")
customerId := t.GetAccountId()
activityId, _ := t.GetInt("activity_id")
customer := new(models.Customer)
exist, err := models.Get(customer, customerId)
t.CheckErr(err)
@ -47,7 +49,7 @@ func (t *WsCtl) Ops() {
// ws doc
func (t *WsCtl) SaveOp() {
customerId := t.MustGetInt64("customer_id")
customerId := t.MustGetInt("customer_id")
extraData := t.Default("extra_data", "")
op := &models.CustomerOperation{
CustomerId: customerId,
@ -61,3 +63,33 @@ func (t *WsCtl) SaveOp() {
}
t.SUCCESS("success")
}
func (t *WsCtl) CheckToken() {
token := t.MustGet("token")
tokens := strings.SplitN(token, ":", 2)
if tokens[0] == define.TYPE_USER { // h5用户
user := &models.User{}
err := user.GetByToken(tokens[1])
t.CheckErr(err)
t.AccountId = user.Id
t.AccountType = tokens[0]
} else if tokens[0] == define.TYPE_CUSTOMER { // 客户
customer := &models.Customer{}
err := customer.GetByToken(tokens[1])
t.CheckErr(err)
t.AccountId = customer.Id
t.AccountType = tokens[0]
} else if tokens[0] == define.TYPE_ENTRYPEOPLE { // 录入人员
entry := &models.OrderEntryPerson{}
err := entry.GetByToken(tokens[1])
t.CheckErr(err)
t.AccountId = entry.Id
t.AccountType = tokens[0]
} else {
t.ERROR("token失效", code.MSG_ERR_Authority)
}
t.JSON(map[string]interface{}{
"account_id": t.AccountId,
"account_type": t.AccountType,
})
}

23
go.mod

@ -5,7 +5,7 @@ go 1.12
require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.1
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/aws/aws-sdk-go v1.33.1 // indirect
github.com/aws/aws-sdk-go v1.34.31 // indirect
github.com/chanxuehong/wechat v0.0.0-20200409104612-0a1fd76d7a3a
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
@ -13,35 +13,40 @@ require (
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-errors/errors v1.1.1 // indirect
github.com/go-redis/redis v6.15.8+incompatible // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/go-stack/stack v1.8.0
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/gorilla/websocket v1.4.2
github.com/iGoogle-ink/gopay/v2 v2.0.5
github.com/importcjj/sensitive v0.0.0-20200106142752-42d1c505be7b
github.com/jinzhu/gorm v1.9.14 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/kirinlabs/HttpRequest v1.0.5
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/ouxuanserver/osmanthuswine v0.0.0-20190916032555-480efadf4941
github.com/panjf2000/ants v4.0.2+incompatible
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.19.0
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/smartystreets/goconvey v1.6.4
github.com/stretchr/testify v1.5.1 // indirect
github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e // indirect
github.com/swaggo/swag v1.6.3 // indirect
github.com/syndtr/goleveldb v1.0.0
github.com/tealeg/xlsx v1.0.5 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.7
github.com/tencentyun/cos-go-sdk-v5 v0.7.9
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0
github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31 // indirect
github.com/xormplus/xorm v0.0.0-20200529061552-7d0d26c6f81c
go.uber.org/atomic v1.6.0
go.uber.org/zap v1.15.0
github.com/xormplus/xorm v0.0.0-20200912034818-5d90dcd4e3d6
go.uber.org/atomic v1.7.0
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376
gopkg.in/yaml.v2 v2.3.0 // indirect
xorm.io/core v0.7.3 // indirect
xorm.io/xorm v1.0.1 // indirect

66
go.sum

@ -59,6 +59,28 @@ github.com/aws/aws-sdk-go v1.33.0 h1:Bq5Y6VTLbfnJp1IV8EL/qUU5qO1DYHda/zis/sqevkY
github.com/aws/aws-sdk-go v1.33.0/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.1 h1:yz9XmNzPshz/lhfAZvLfMnIS9HPo8+boGRcWqDVX+T0=
github.com/aws/aws-sdk-go v1.33.1/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.6 h1:YLoUeMSx05kHwhS+HLDSpdYYpPzJMyp6hn1cWsJ6a+U=
github.com/aws/aws-sdk-go v1.33.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.8 h1:2/sOfb9oPHTRZ0lxinoaTPDcYwNa1H/SpKP4nVRBwmg=
github.com/aws/aws-sdk-go v1.33.8/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.9 h1:nkC8YxL1nxwshIoO3UM2486Ph+zs7IZWjhRHjmXeCPw=
github.com/aws/aws-sdk-go v1.33.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.18 h1:Ccy1SV2SsgJU3rfrD+SOhQ0jvuzfrFuja/oKI86ruPw=
github.com/aws/aws-sdk-go v1.33.18/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.19 h1:SMna0QLInNqm+nNL9tb7OVWTqSfNYSxrCa2adnyVth4=
github.com/aws/aws-sdk-go v1.33.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.20 h1:mtXKHmMQO6o0i2GTjyiVNZGlXqJDCUbiik0OQeMds/o=
github.com/aws/aws-sdk-go v1.33.20/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.3 h1:pkbLkV9Q/KY86rbV/WG+yzjNektJbjNRdsTNGtNDZcY=
github.com/aws/aws-sdk-go v1.34.3/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.4 h1:Yx49/+ZMCD9YqIVsO3CsiMs4hnUnokd9otKvWYFjnYw=
github.com/aws/aws-sdk-go v1.34.4/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.10 h1:VU78gcf/3wA4HNEDCHidK738l7K0Bals4SJnfnvXOtY=
github.com/aws/aws-sdk-go v1.34.10/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.12 h1:7UbBEYDUa4uW0YmRnOd806MS1yoJMcaodBWDzvBShAI=
github.com/aws/aws-sdk-go v1.34.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.31 h1:408wh5EHKzxyby8JpYfnn1w3fsF26AIU0o1kbJoRy7E=
github.com/aws/aws-sdk-go v1.34.31/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c=
github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
@ -77,6 +99,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -141,6 +164,8 @@ github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis v6.15.8+incompatible h1:BKZuG6mCnRj5AOaWJXoCgf6rqTYnYJLe4en2hxT7r9o=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
@ -166,6 +191,8 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pO
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@ -215,6 +242,10 @@ github.com/jinzhu/gorm v1.9.13 h1:fcdacwmUcoyon8XHkQrdPJZ7pnHAYclHZ6iLYER5nX4=
github.com/jinzhu/gorm v1.9.13/go.mod h1:C0zfmO9z9J61PGrs46nfRkfsq0/8ErGTKBxyudR2KvI=
github.com/jinzhu/gorm v1.9.14 h1:Kg3ShyTPcM6nzVo148fRrcMO6MNKuqtOUwnzqMgVniM=
github.com/jinzhu/gorm v1.9.14/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/gorm v1.9.15 h1:OdR1qFvtXktlxk73XFYMiYn9ywzTwytqe4QkuMRqc38=
github.com/jinzhu/gorm v1.9.15/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a h1:eeaG9XMUvRBYXJi4pg1ZKM7nxc5AfXfojeLLW7O5J3k=
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
@ -227,6 +258,9 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
@ -304,6 +338,9 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.19.0 h1:hYz4ZVdUgjXTBUmrkrw55j1nHx68LfOKIQk5IYtyScg=
github.com/rs/zerolog v1.19.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
github.com/satori/go.uuid v0.0.0-20190313024323-b2ce2384e17b h1:PB8A682UQ6pwoFhkszETBsYw3B9Ze9FEA4cf9H9O3f8=
github.com/satori/go.uuid v0.0.0-20190313024323-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
@ -347,6 +384,8 @@ github.com/tencentyun/cos-go-sdk-v5 v0.7.4 h1:Hsand7ideMevJKmogyFRTOGy0DxM+oSXHw
github.com/tencentyun/cos-go-sdk-v5 v0.7.4/go.mod h1:wQBO5HdAkLjj2q6XQiIfDSP8DXDNrppDRw2Kp/1BODA=
github.com/tencentyun/cos-go-sdk-v5 v0.7.7 h1:7YI5nNwLEhseUoWzzz1CDAwQMeJyJfD3Tj0XnQRzqO8=
github.com/tencentyun/cos-go-sdk-v5 v0.7.7/go.mod h1:wQBO5HdAkLjj2q6XQiIfDSP8DXDNrppDRw2Kp/1BODA=
github.com/tencentyun/cos-go-sdk-v5 v0.7.9 h1:kQ7PMMzSR0lEGKSIR+1FGy/fpNfpfuYdpwky1bMYl7E=
github.com/tencentyun/cos-go-sdk-v5 v0.7.9/go.mod h1:wQBO5HdAkLjj2q6XQiIfDSP8DXDNrppDRw2Kp/1BODA=
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0 h1:NavMw9XO2iCLv8hTKaJW2kTaGR2SdNljMABbe39yu6Q=
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0/go.mod h1:u7WiArmCTXTaQAHJwAOaLgpJ5e2xdY5/cgMEy3ubL60=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
@ -374,6 +413,10 @@ github.com/xormplus/xorm v0.0.0-20200410045938-f6b4c1cd3b8b h1:LkpWvTXxj8r18jZAh
github.com/xormplus/xorm v0.0.0-20200410045938-f6b4c1cd3b8b/go.mod h1:+v6b10b4x5IcQmp1/Cbo9IqaknxVeuhQng+fhya6bdI=
github.com/xormplus/xorm v0.0.0-20200529061552-7d0d26c6f81c h1:NaRjnzmJVo7x3L+W6mgwNBbxTdAK1BbCYto3tKKT1GU=
github.com/xormplus/xorm v0.0.0-20200529061552-7d0d26c6f81c/go.mod h1:+v6b10b4x5IcQmp1/Cbo9IqaknxVeuhQng+fhya6bdI=
github.com/xormplus/xorm v0.0.0-20200731130200-6811f3bde592 h1:uZkSqOig4izJR611DIoCHbDamdTo+sNtEldZGlrfwGk=
github.com/xormplus/xorm v0.0.0-20200731130200-6811f3bde592/go.mod h1:+v6b10b4x5IcQmp1/Cbo9IqaknxVeuhQng+fhya6bdI=
github.com/xormplus/xorm v0.0.0-20200912034818-5d90dcd4e3d6 h1:8wMAe6KZ0YOG1RvjxyK5VhB29grvQbhb6MZTDIdpSd4=
github.com/xormplus/xorm v0.0.0-20200912034818-5d90dcd4e3d6/go.mod h1:+v6b10b4x5IcQmp1/Cbo9IqaknxVeuhQng+fhya6bdI=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
@ -385,10 +428,14 @@ go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.2.0 h1:6I+W7f5VwC5SV9dNrZ3qXrDB9mD0dyGOi/ZJmYw03T4=
go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
@ -397,6 +444,8 @@ go.uber.org/zap v1.14.1 h1:nYDKopTbvAPq/NrUVZwT15y2lpROBiLLyoRTbXOYWOo=
go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190314133821-5284462c4bec/go.mod h1:atTaCNAy0f16Ah5aV1gMSwgiKVHwu/JncqDpuRr7lS4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@ -491,6 +540,22 @@ golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 h1:5/PjkGUjvEU5Gl6BxmvKRPpqo
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 h1:gVCS+QOncANNPlmlO1AhlU3oxs4V9z+gTtPwIk3p2N8=
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 h1:B6caxRw+hozq68X2MY7jEpZh/cr4/aHLv9xU8Kkadrw=
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200805065543-0cf7623e9dbd h1:wefLe/3g5tC0FcXw3NneLA5tHgbyouyZlfcSjNfOdgk=
golang.org/x/sys v0.0.0-20200805065543-0cf7623e9dbd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200806060901-a37d78b92225 h1:a5kp7Ohh+lqGCGHUBQdPwGHTJXKNhVVWp34F+ncDC9M=
golang.org/x/sys v0.0.0-20200806060901-a37d78b92225/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d h1:QQrM/CCYEzTs91GZylDCQjGHudbPTxF/1fvXdVh5lMo=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4=
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
@ -509,6 +574,7 @@ golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b h1:/mJ+GKieZA6hFDQGdWZrjj4AXPl5ylY+5HusG80roy0=
golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191025023517-2077df36852e h1:ejUPpxsbZzyShOEURCSvFIT0ltnmBW92Vsc3i8QRcw8=
golang.org/x/tools v0.0.0-20191025023517-2077df36852e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

11
hdws/ws/client.go

@ -2,17 +2,18 @@ package ws
import (
"encoding/json"
"gopkg.in/olahol/melody.v1"
)
type Client struct {
Id string // account_typ:account_id
AccountId int64
AccountId int
AccountType string
Pid int64
Online bool
RoomId string
node *Node
//Pid int
Online bool
RoomId string
node *Node
*melody.Session
}

4
hdws/ws/http.go

@ -10,11 +10,9 @@ type MessageCtl struct {
core.Controller
}
var now = time.Now()
func (t *MessageCtl) Checkin() {
t.DisplayByData(map[string]interface{}{
"version": now,
"version": "1.0.0",
"status": "success",
})
}

12
hdws/ws/jwt_go.go

@ -11,15 +11,15 @@ import (
type Claims struct {
AccountType string
AccountId int64
CustomerId int64
CustomerPid int64
ActivityId int64
AreaId int64
AccountId int
CustomerId int
CustomerPid int
ActivityId int
AreaId int
jwt.StandardClaims
}
func GenJwtToken(accountType string, accountId, customerId, customerPid, areaId, activityId int64) (string, error) {
func GenJwtToken(accountType string, accountId, customerId, customerPid, areaId, activityId int) (string, error) {
claims := Claims{
accountType,
accountId,

93
hdws/ws/login.go

@ -2,33 +2,50 @@ package ws
import (
"fmt"
"hudongzhuanjia/models"
)
func init() {
N.RegisterLogic(LogicLogin, loginFunc)
N.SetMiddleware(LogicLogin, LoginMid)
}
func loginFunc(c *Client, msg *Message) {
if _, ok := msg.Data["token"]; !ok {
func LoginMid(c *Client, msg *Message) {
var token string
var ok bool
if token, ok = msg.Data["token"].(string); !ok || token == "" {
_ = c.WriteJson(map[string]interface{}{
"msg": "token不能为空",
"code": 506,
})
return
}
claims, err := ParseAccessToken(msg.Data["token"].(string))
_type, id, err := models.ParseToken(token)
if err != nil {
_ = c.WriteJson(map[string]interface{}{
"msg": "token解析出错, " + err.Error(),
c.WriteJson(map[string]interface{}{
"msg": "token失效",
"code": 507,
})
return
}
c.Online = true
c.Id = fmt.Sprintf("%s:%d", claims.AccountType, claims.AccountId)
c.AccountId = claims.AccountId
c.AccountType = claims.AccountType
c.Pid = claims.CustomerPid
c.AccountId = id
c.AccountType = _type
c.Id = fmt.Sprintf("%s:%d", c.AccountType, c.AccountId)
//claims, err := ParseAccessToken(msg.Data["token"].(string))
//if err != nil {
// _ = c.WriteJson(map[string]interface{}{
// "msg": "token解析出错, " + err.Error(),
// "code": 507,
// })
// return
//}
//c.Online = true
//c.Id = fmt.Sprintf("%s:%d", claims.AccountType, claims.AccountId)
//c.AccountId = claims.AccountId
//c.AccountType = claims.AccountType
//c.Pid = claims.CustomerPid
if err = c.Register(); err != nil {
_ = c.WriteJson(map[string]interface{}{
"msg": err.Error(),
@ -36,34 +53,34 @@ func loginFunc(c *Client, msg *Message) {
})
return
}
if claims.AccountType == IDCustomer {
if c.Pid == 0 { // 主账号发给子账号
m := &Message{
Type: TypeNotice,
Dest: 0,
Tag: IDCustomer,
RoomId: c.RoomId,
From: c.Id,
Data: map[string]interface{}{
"content": "主账号上线",
},
}
c.Send(m)
} else { // 子账号发给主账号
m := &Message{
Type: TypeNotice,
Dest: claims.CustomerPid,
Tag: IDCustomer,
RoomId: c.RoomId,
From: c.Id,
Data: map[string]interface{}{
"content": "子账号上线",
},
}
c.Send(m)
}
}
//
//if claims.AccountType == IDCustomer {
// if c.Pid == 0 { // 主账号发给子账号
// m := &Message{
// Type: TypeNotice,
// Dest: 0,
// Tag: IDCustomer,
// RoomId: c.RoomId,
// From: c.Id,
// Data: map[string]interface{}{
// "content": "主账号上线",
// },
// }
// c.Send(m)
// } else { // 子账号发给主账号
// m := &Message{
// Type: TypeNotice,
// Dest: claims.CustomerPid,
// Tag: IDCustomer,
// RoomId: c.RoomId,
// From: c.Id,
// Data: map[string]interface{}{
// "content": "子账号上线",
// },
// }
// c.Send(m)
// }
//}
_ = c.WriteJson(map[string]interface{}{
"msg": "登录成功",
"code": 200,

2
hdws/ws/message.go

@ -5,7 +5,7 @@ import "encoding/json"
type Message struct {
Type string `json:"type"` // 对应处理函数 / sync 同步函数,存入数据库 / msg 发送消息,不存入数据库 / login 登录校验某个客户是否存在
From string `json:"-"` // 发送方 ==> 自行处理, 无需发送
Dest int64 `json:"dest"` // 目标id / 0 代表所有 非0代表某一个
Dest int `json:"dest"` // 目标id / 0 代表所有 非0代表某一个
Tag string `json:"tag"` // 目标类型 customer代表客户 user代表用户 entry代表录入人员
RoomId string `json:"room_id"` // 房间id // activity_id
Data map[string]interface{} `json:"data"`

2
hdws/ws/msg.go

@ -1,7 +1,7 @@
package ws
func init() {
N.RegisterLogic("msg", msgFunc)
N.SetMiddleware("msg", msgFunc)
}
// 简单明了

61
hdws/ws/node.go

@ -5,7 +5,6 @@ import (
"fmt"
"github.com/rs/zerolog/log"
"gopkg.in/olahol/melody.v1"
"strings"
"sync"
)
@ -68,35 +67,35 @@ func (t *Node) handleMelodyMessage(client *Client, msg *Message) {
// 删掉注册的
func (t *Node) handleMelodyDisconnect(client *Client) {
if client.Online && strings.HasPrefix(client.Id, IDCustomer) {
if client.Pid == 0 { // 主账号下线 通知子账号
msg := &Message{
Type: TypeNotice,
Dest: 0,
Tag: IDCustomer,
RoomId: client.RoomId,
From: client.Id,
Data: map[string]interface{}{
"id": client.AccountId,
"content": "主账号下线",
},
}
t.Send(msg)
} else { // 子账号下线 通知主账号
msg := &Message{
Type: TypeNotice,
Dest: client.Pid,
Tag: IDCustomer,
RoomId: client.RoomId,
From: client.Id,
Data: map[string]interface{}{
"id": client.AccountId,
"content": "子账号下线",
},
}
t.Send(msg)
}
}
//if client.Online && strings.HasPrefix(client.Id, IDCustomer) {
// if client.Pid == 0 { // 主账号下线 通知子账号
// msg := &Message{
// Type: TypeNotice,
// Dest: 0,
// Tag: IDCustomer,
// RoomId: client.RoomId,
// From: client.Id,
// Data: map[string]interface{}{
// "id": client.AccountId,
// "content": "主账号下线",
// },
// }
// t.Send(msg)
// } else { // 子账号下线 通知主账号
// msg := &Message{
// Type: TypeNotice,
// Dest: client.Pid,
// Tag: IDCustomer,
// RoomId: client.RoomId,
// From: client.Id,
// Data: map[string]interface{}{
// "id": client.AccountId,
// "content": "子账号下线",
// },
// }
// t.Send(msg)
// }
//}
// 释放内存
if room, ok := t.rooms[client.RoomId]; ok {
room.DeleteClient(client.Id)
@ -107,7 +106,7 @@ func (t *Node) handleMelodyDisconnect(client *Client) {
log.Printf("[websocket] [disconnect] [room:%s] [client:%s] online=>%v\n", client.RoomId, client.Id, client.Online)
}
func (t *Node) RegisterLogic(name string, fn logic) {
func (t *Node) SetMiddleware(name string, fn logic) {
t.handles[name] = fn
}

10
hdws/ws/timer.go

@ -7,11 +7,11 @@ import (
)
func init() {
N.RegisterLogic(LogicSync, syncFunc)
N.SetMiddleware(LogicSync, syncFunc)
}
func syncFunc(c *Client, msg *Message) {
if c.AccountType != IDCustomer && c.Pid != 0 {
if c.AccountType != IDCustomer {
c.Write([]byte("此账号无此权限"))
return
}
@ -50,10 +50,10 @@ func syncFunc(c *Client, msg *Message) {
op := &models.CustomerOperation{
CustomerId: c.AccountId,
Operation: operation.(string),
AreaId: int64(areaId.(float64)),
ModuleActivityId: int64(moduleActivityId.(float64)),
AreaId: int(areaId.(float64)),
ModuleActivityId: int(moduleActivityId.(float64)),
ModuleActivityType: moduleActivityType.(string),
ActivityId: int64(activityId.(float64)),
ActivityId: int(activityId.(float64)),
ExtraData: string(extraData),
UpdatedAt: time.Now(),
CreatedAt: time.Now(),

12
libs/jwt/jwt_go.go

@ -11,15 +11,15 @@ import (
type Claims struct {
AccountType string
AccountId int64
CustomerId int64
CustomerPid int64
ActivityId int64
AreaId int64
AccountId int
CustomerId int
CustomerPid int
ActivityId int
AreaId int
jwt.StandardClaims
}
func GenJwtToken(accountType string, accountId, customerId, customerPid, areaId, activityId int64) (string, error) {
func GenJwtToken(accountType string, accountId, customerId, customerPid, areaId, activityId int) (string, error) {
claims := Claims{
accountType,
accountId,

5
libs/qq/qq.go

@ -3,10 +3,11 @@ package qq
import (
"encoding/json"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/helper"
"io/ioutil"
"net/http"
"net/url"
"github.com/ouxuanserver/osmanthuswine/src/helper"
)
var (
@ -49,7 +50,7 @@ func GetUserInfoUrl(accessToken, openid string) string {
type Token struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
}

7
libs/wx/wx.go

@ -2,10 +2,11 @@ package wx
import (
"fmt"
"github.com/kirinlabs/HttpRequest"
"github.com/ouxuanserver/osmanthuswine/src/helper"
"hudongzhuanjia/utils/define"
"net/url"
"github.com/kirinlabs/HttpRequest"
"github.com/ouxuanserver/osmanthuswine/src/helper"
)
func GetCodeUrl() string {
@ -41,7 +42,7 @@ func GetTicketTokenUrl() string {
type Token struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Openid string `json:"openid"`
Scope string `json:"scope"`

3
main.go

@ -6,10 +6,12 @@ import (
"hudongzhuanjia/controllers/client"
"hudongzhuanjia/controllers/common"
"hudongzhuanjia/controllers/pc"
"hudongzhuanjia/utils/define"
//_ "net/http/pprof"
)
func main() {
define.SetDebug(true)
// pc
core.GetInstanceRouterManage().Registered(new(pc.WsCtl)) // 用户
@ -49,6 +51,7 @@ func main() {
core.GetInstanceRouterManage().Registered(new(client.CalorieCtl)) // 卡路里
core.GetInstanceRouterManage().Registered(new(client.LiveCtl)) // 直播
core.GetInstanceRouterManage().Registered(new(client.GoodCtl)) // 商品
core.GetInstanceRouterManage().Registered(new(client.AreaCtl)) //
// common
core.GetInstanceRouterManage().Registered(new(common.AnnexCtl))

50
models/CalorieUser.go

@ -1,53 +1,59 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CalorieUserTableName = TableNamePrefix + "calorie_user"
type CalorieUser struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
Avatar string `json:"avatar" xorm:"-"`
Nickname string `json:"nickname" xorm:"-"`
UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
CalorieId int64 `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
CalorieId int `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
Score int `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
JoinTime int64 `json:"join_time" xorm:"not null default('0') comment('加入时间纳秒') VARCHAR(128)"`
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"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default(CURRENT_TIMESTAMP) updated comment('创建时间') TIMESTAMP"`
// 无关变量
Avatar string `json:"avatar" xorm:"-"`
Nickname string `json:"nickname" xorm:"-"`
}
func (t *CalorieUser) TableName() string {
return CalorieUserTableName
}
func (t *CalorieUser) GetByCalorieIdAndUserId(cid, uid, rid int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and user_id=? and rehearsal_id=?", cid, uid, rid).Get(t)
func (t *CalorieUser) GetByCalorieIdAndUserId(calorieId, archId, userId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and user_id=? and rehearsal_id=?",
calorieId, archId, userId, rehearsalId).Get(t)
}
func (t *CalorieUser) IncrScore(score int) (int64, error) {
func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) {
t.JoinTime = time.Now().UnixNano()
return core.GetXormAuto().Where("is_delete=0 and id=?", t.Id).Cols("score", "join_time").Incr("score", score).Update(t)
return core.GetXormAuto().Where("is_delete=0 and arch_id=? and id=?", archId, id).
Cols("score", "join_time").Incr("score", score).Update(t)
}
func (t *CalorieUser) CountByCalorieId(calorieId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?",
calorieId, rehearsalId).Count(&CalorieUser{})
func (t *CalorieUser) CountByCalorieId(calorieId, archId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
calorieId, archId, rehearsalId).Count(&CalorieUser{})
}
func GetCalorieUsersByCalorieIdAndScore(calorieId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
func GetCalorieUsersByCalorieIdAndScore(calorieId, archId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
users := make([]*CalorieUser, 0)
err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=? and score<=?",
calorieId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users)
err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=? and score<=?",
calorieId, archId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users)
return users, err
}
func (t *CalorieUser) Count(calorieId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?",
calorieId, rehearsalId).Count(t)
func (t *CalorieUser) Count(calorieId, archId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
calorieId, archId, rehearsalId).Count(t)
}

18
models/activity.go

@ -8,9 +8,14 @@ const ActivityTableName = TableNamePrefix + "activity"
//互动活动
type Activity struct {
Id int64 `json:"id" xorm:"pk autoincr INT(11)"`
CustomerId int64 `json:"customer_id" xorm:"not null default(0) comment('customer_id, 创建客户id') INT(11)"`
ArchId int64 `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
Model `xorm:"extends"`
//Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
//IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)" description:"删除"`
//CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME" description:"创建时间"`
//UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME" description:"更新时间"`
CustomerId int `json:"customer_id" xorm:"not null default(0) comment('customer_id, 创建客户id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
Services []*ActivityModuleService `json:"services,omitempty" xorm:"-" description:"主活动下的服务"`
AreaStores []*AreaStore `json:"area_stores,omitempty" xorm:"-" description:"地区"`
BarrageStatus string `json:"barrage_status,omitempty" xorm:"-" description:"弹幕服务状态"`
@ -20,7 +25,7 @@ type Activity struct {
Name string `json:"name" xorm:"not null comment('主活动名字') VARCHAR(255)"`
Classification string `json:"classification" xorm:"not null comment('互动分类') VARCHAR(255)"`
Status string `json:"status" xorm:"not null default('未开始') comment('状态[未开始,进行中,已结束]') VARCHAR(128)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('0正式、1彩排中的id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('0正式、1彩排中的id') INT(11)"`
Province string `json:"province" xorm:"not null default('') comment('省') VARCHAR(128)" description:"省"`
City string `json:"city" xorm:"not null default('') comment('省') VARCHAR(128)" description:"市"`
StartTime time.Time `json:"start_time" xorm:"not null default('1970-01-01 08:00:00') comment('互动开始时间') DATETIME"`
@ -34,9 +39,6 @@ type Activity struct {
PhoneBgSwitch string `json:"phone_bg_switch" xorm:"not null default('关闭') comment('手机通用背景开关') VARCHAR(255)"`
MaxBgUrl string `json:"max_bg_url" xorm:"not null default('') comment('大屏通用背景') VARCHAR(255)" description:"大屏通用背景"`
MaxBgSwitch string `json:"max_bg_switch" xorm:"not null default('关闭') comment('大屏通用背景开关')" description:"大屏通用背景开关"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)" description:"删除"`
CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME" description:"创建时间"`
UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME" description:"更新时间"`
}
func (t *Activity) TableName() string {
@ -44,5 +46,5 @@ func (t *Activity) TableName() string {
}
func (t *Activity) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}

12
models/activity_module_service.go

@ -10,16 +10,16 @@ const ActivityModuleServiceTableName = TableNamePrefix + "activity_module_servic
//活动模块服务
type ActivityModuleService struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id') INT(11)"`
ServiceModuleHistoryId int64 `json:"service_module_history_id" xorm:"not null comment('service_module_history表id') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') INT(11)"`
ServiceModuleHistoryId int `json:"service_module_history_id" xorm:"not null comment('service_module_history表id') INT(11)"`
ServiceModuleName string `json:"service_module_name" xorm:"-" description:"模块服务名字"`
ServiceModuleStatus string `json:"service_module_status" xorm:"not null default('关闭') comment('服务模块 免费开启。付费默认关闭。') VARCHAR(128)"`
PhoneBgUrl string `json:"phone_bg_url" xorm:"not null default('') comment('服务模块的自定义手机屏的图片') VARCHAR(255)"`
PhoneBgSwitch string `json:"phone_bg_switch" xorm:"not null default('关闭') comment('模块手机的开关 开启|关闭') VARCHAR(11)"`
MaxBgUrl string `json:"max_bg_url" xorm:"not null default('') comment('服务模块的自定义大屏的图片') VARCHAR(255)"`
MaxBgSwitch string `json:"max_bg_switch" xorm:"not null default('关闭') comment('模块大屏的开关 开启|关闭') VARCHAR(11)"`
ModuleStyleId int64 `json:"module_style_id" xorm:"not null default(0) comment('每个模块对应的一个样式id 如果有的话') INT(11)"`
ModuleStyleId int `json:"module_style_id" xorm:"not null default(0) comment('每个模块对应的一个样式id 如果有的话') INT(11)"`
BesideRepeat string `json:"beside_repeat" xorm:"not null default('不去除') comment('是否去除重复') VARCHAR(11)"`
ServiceModuleStartTime time.Time `json:"service_module_start_time" xorm:"not null default('1970-01-01 08:00:00') comment('服务开始时间') DATETIME"`
ServiceModuleEndTime time.Time `json:"service_module_end_time" xorm:"not null default('1970-01-01 08:00:00') comment('服务结束时间') DATETIME"`
@ -42,11 +42,11 @@ func (t *ActivityModuleService) TableName() string {
}
func (t *ActivityModuleService) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
//
//func (t *ActivityModuleService) GetByActivityIdAndHistoryId(aid, hid int64) (bool, error) {
//func (t *ActivityModuleService) GetByActivityIdAndHistoryId(aid, hid int) (bool, error) {
// return core.GetXormAuto().Where("is_delete=0 and activity_id=? and service_module_history_id=?", aid, hid).Get(t)
//}

7
models/arch.go

@ -1,14 +1,15 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const ArchTableName = TableNamePrefix + "arch"
type Arch struct {
Id int `json:"id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CustomerId int `json:"customer_id"`
ActivityId int `json:"activity_id"`
Date string `json:"date"`
@ -23,5 +24,5 @@ func (t *Arch) TableName() string {
}
func (t *Arch) Count(activityId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).Get(t)
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).Count(t)
}

51
models/area_store.go

@ -1,43 +1,58 @@
package models
import (
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/ouxuanserver/osmanthuswine/src/helper"
)
const AreaStoreTableName = TableNamePrefix + "area_store"
//店铺地区
type AreaStore struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Name string `json:"name" xorm:"not null default('') comment('名字') VARCHAR(255)"`
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"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
Model `xorm:"extends"`
//Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
//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"`
//UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
//
Name string `json:"name" xorm:"not null default('') comment('名字') VARCHAR(255)"`
Type string `json:"type" xorm:"not null default('') comment('地区类型') VARCHAR(255)"`
Address string `json:"address" xorm:"not null default('') comment('地址') VARCHAR(255)"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') BIGINT(20)"`
CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"`
IsMainArea int `json:"is_main_area" xorm:"not null default(0) comment('是否主地区1是') TINYINT(1)"`
AreaServicePhone string `json:"area_service_phone" xorm:"not null default '' comment('地区客服电话') VARCHAR(128)"`
AdminName string `json:"admin_name" xorm:"not null default '' comment('地区管理员名称') VARCHAR(128)"`
Phone string `json:"phone" xorm:"not null default '' comment('地区管理员账号即手机号') VARCHAR(128)"`
Password string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(255)"`
RawPassword string `json:"raw_password" xorm:"not null default '' comment('密码') VARCHAR(255)"`
IsImport int `json:"is_import" xorm:"not null default 0 comment('是否导入的数据') TINYINT(1)"`
AreaGoodsRuleSwitch int `json:"area_goods_rule_switch" xorm:"not null default 0 comment('地区专属商品规则1开启(用自己地区的商品)0关闭(共用主会场的商品)') TINYINT(1)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
}
func (t *AreaStore) TableName() string {
return AreaStoreTableName
}
func (t *AreaStore) Login(activityId int, username, password string) (bool, error) {
password = helper.Md5("hdzj==" + password)
return core.GetXormAuto().NoAutoCondition().Where("activity_id=? and phone=? and password=?", activityId, username, password).Get(t)
}
func (t *AreaStore) GetByUserId(activityId, userId int) (bool, error) {
return core.GetXormAuto().Where("user_id=? and activity_id=?", userId, activityId).Get(t)
}
func (t *AreaStore) GetByCustomerId(customerId, activityId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and customer_id=? and activity_id=?", customerId, activityId).Get(t)
}
func (t *AreaStore) GetAreaStoreById(id int64) (bool, error) {
func (t *AreaStore) GetAreaStoreById(id int) (bool, error) {
return core.GetXormAuto().Where("id=? and is_delete=0", id).Get(t)
}
func (t *AreaStore) GetMainAreaById(aid int64) (bool, error) {
return core.GetXormAuto().Where("activity_id=? and is_main_area=1 and is_delete=0", aid).Get(t)
func (t *AreaStore) GetMainAreaById(aid int) (bool, error) {
return core.GetXormAuto().NoAutoCondition().Where("activity_id=? and is_main_area=1 and is_delete=0", aid).Get(t)
}
func GetAreaStoresByActivityId(aid int64) ([]*AreaStore, error) {
func GetAreaStoresByActivityId(aid int) ([]*AreaStore, error) {
list := make([]*AreaStore, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Find(&list)
return list, err

4
models/auction_activity.go

@ -2,8 +2,8 @@ package models
//竞拍活动
//type AuctionActivity struct {
// Id int64 `json:"id"`
// ActivityId int64 `json:"activity_id" description:"活动的id"`
// Id int `json:"id"`
// ActivityId int `json:"activity_id" description:"活动的id"`
// AuctionActivityName string `json:"auction_activity_name" description:"竞拍名称"`
// LatestMoney float64 `json:"latest_price" xorm:"-" description:"最新的竞拍叫价,通过查询AuctionHistory获得"`
// MaxMoney float64 `json:"max_price" xorm:"-" description:"目前最高叫价,通过查询AuctionHistory获得"`

4
models/auction_deal.go

@ -2,8 +2,8 @@ package models
//竞拍成交
//type AuctionDeal struct {
// Id int64 `json:"id"`
// RuleId int64 `json:"rule_id" description:"规则id"`
// Id int `json:"id"`
// RuleId int `json:"rule_id" description:"规则id"`
// PlayerCode int `json:"player_code" description:"竞拍参与者号码"`
// DealMoney float64 `json:"deal_money" description:"成交的金额"`
// IsPay bool `json:"is_pay" description:"是否支付"`

35
models/auction_history.go

@ -10,17 +10,18 @@ const AuctionHistoryTableName = TableNamePrefix + "auction_history"
//竞拍历史
type AuctionHistory struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id, 0是正式') INT(11)"`
PlayerId int64 `json:"player_id" xorm:"not null comment('竞拍者id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null comment('地区id') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null comment('彩排id, 0是正式') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
PlayerId int `json:"player_id" xorm:"not null comment('竞拍者id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null comment('地区id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null comment('地区名字') VARCHAR(128)"`
UserName string `json:"user_name" xorm:"not null comment('用户名') VARCHAR(128)"`
UserPhone string `json:"user_phone" xorm:"not null comment('用户手机') VARCHAR(128)"`
AuctionGoodsName string `json:"auction_goods_name" xorm:"not null comment('竞拍商品名字') VARCHAR(255)"`
AuctionActivityId int64 `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
AuctionActivityId int `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
PlayerCode int64 `json:"player_code" xorm:"not null comment('竞拍参与者号码') INT(11)"`
Unit int `json:"unit" xorm:"not null default(1) comment('单位') TINYINT(1)"`
Money float64 `json:"money" xorm:"not null comment('计算总价格') DECIMAL(20)"`
@ -34,25 +35,25 @@ func (t *AuctionHistory) TableName() string {
return AuctionHistoryTableName
}
func (t *AuctionHistory) GetHighestMoney(rid, aid int64) (bool, error) {
return core.GetXormAuto().Where("auction_activity_id = ? and rehearsal_id=? and is_delete=0", aid, rid).
Desc("money").Asc("updated_at").Get(t)
func (t *AuctionHistory) GetHighestMoney(rid, aid int, archId interface{}) (bool, error) {
return core.GetXormAuto().Where("auction_activity_id = ? and arch_id=? and rehearsal_id=? and is_delete=0",
aid, archId, rid).Desc("money").Asc("updated_at").Get(t)
}
func (t *AuctionHistory) CountHistory(rid, aid int64) (int64, error) {
func (t *AuctionHistory) CountHistory(rid, aid int) (int64, error) {
return core.GetXormAuto().Where("auction_activity_id = ? and rehearsal_id=? and is_delete=0", aid, rid).Count(t)
}
func GetAuctionHistoriesByAuctionId(aid, rid int64, orderBy string) ([]*AuctionHistory, error) {
func GetAuctionHistoriesByAuctionId(aid, rid int, orderBy string, archId interface{}) ([]*AuctionHistory, error) {
histories := make([]*AuctionHistory, 0)
err := core.GetXormAuto().Where("is_delete=0 and auction_activity_id=? and rehearsal_id=?", aid, rid).
OrderBy(orderBy).Find(&histories)
err := core.GetXormAuto().Where("is_delete=0 and auction_activity_id=? and rehearsal_id=? and arch_id=?",
aid, rid, archId).OrderBy(orderBy).Find(&histories)
return histories, err
}
func GetAuctionHistoriesByAuctionIds(ids []int64, rid int64, orderBy string) ([]*AuctionHistory, error) {
func GetAuctionHistoriesByAuctionIds(ids []int, rid int, archId interface{}) ([]*AuctionHistory, error) {
histories := make([]*AuctionHistory, 0)
err := core.GetXormAuto().Where("is_delete=0 and rehearsal_id=?", rid).
In("auction_activity_id", ids).OrderBy(orderBy).Find(&histories)
err := core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and arch_id=?", rid, archId).
In("auction_activity_id", ids).Desc("money").Find(&histories)
return histories, err
}

18
models/auction_player.go

@ -1,18 +1,20 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const AuctionPlayerTableName = TableNamePrefix + "auction_player"
//竞拍者
type AuctionPlayer struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
AuctionActivityId int64 `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
UserId int64 `json:"user_id" xorm:"not null comment('客户的id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id, 0正式数据') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
AuctionActivityId int `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('客户的id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id, 0正式数据') INT(11)"`
Code int64 `json:"code" xorm:"not null comment('竞拍参与人的代号') INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(0)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
@ -23,7 +25,7 @@ func (t *AuctionPlayer) TableName() string {
return AuctionPlayerTableName
}
func (t *AuctionPlayer) GetByAuctionIdAndUid(aid, uid, rid int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and auction_activity_id=? and user_id=? and rehearsal_id=?",
aid, uid, rid).Get(t)
func (t *AuctionPlayer) GetByAuctionIdAndUid(aid, uid, rid int, archId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and auction_activity_id=? and arch_id=? and user_id=? and rehearsal_id=?",
aid, archId, uid, rid).Get(t)
}

32
models/auction_result_record.go

@ -1,20 +1,22 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const AuctionResultRecordTableName = TableNamePrefix + "auction_result_record"
type AuctionResultRecord struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('0正式/!0彩排id') INT(11)"` // 增加彩排功能
AuctionActivityId int64 `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default('0') comment('地区id') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('0正式/!0彩排id') INT(11)"` // 增加彩排功能
AuctionActivityId int `json:"auction_activity_id" xorm:"not null comment('竞拍活动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default('0') comment('地区id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null default('') comment('地区名字') VARCHAR(255)"`
UserId int64 `json:"user_id" xorm:"not null comment('用户id') INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('用户id') INT(11)"`
UserName string `json:"user_name" xorm:"not null comment('用户名字') VARCHAR(255)"`
UserPhone string `json:"user_phone" xorm:"not null comment('用户手机号码') VARCHAR(128)"`
PlayerCode int64 `json:"player_code" xorm:"not null default(0) comment('竞拍编号') INT(11)"`
@ -30,17 +32,19 @@ func (t *AuctionResultRecord) TableName() string {
return AuctionResultRecordTableName
}
func (t *AuctionResultRecord) CountHistory(rid, aid int64) (int64, error) {
return core.GetXormAuto().Where("auction_activity_id=? and rehearsal_id=? and is_delete=0", aid, rid).Count(t)
func (t *AuctionResultRecord) CountHistory(rid, aid int, archId interface{}) (int64, error) {
return core.GetXormAuto().Where("auction_activity_id=? and arch_id=? and rehearsal_id=? and is_delete=0",
aid, archId, rid).Count(t)
}
func GetAuctionRecordsByAuctionId(id, rid int64, orderBy string) ([]*AuctionResultRecord, error) {
func GetAuctionRecordsByAuctionId(id, rid int, archId interface{}) ([]*AuctionResultRecord, error) {
records := make([]*AuctionResultRecord, 0)
err := core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and auction_activity_id=?", rid, id).
OrderBy(orderBy).Find(&records)
err := core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and auction_activity_id=? and arch_id=?", rid, id, archId).
Desc("created_at").Find(&records)
return records, err
}
func (t *AuctionResultRecord) GetByUserIdAndAuctionId(userId, auctionId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and user_id=? and auction_activity_id=? and rehearsal_id=?", userId, auctionId, rehearsalId).Get(t)
func (t *AuctionResultRecord) GetByUserIdAndAuctionId(userId, auctionId, archId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and user_id=? and auction_activity_id=? and arch_id=? and rehearsal_id=?",
userId, auctionId, archId, rehearsalId).Get(t)
}

10
models/auction_rule.go

@ -4,11 +4,11 @@ package models
//
////竞拍规则
//type AuctionRule struct {
// Id int64 `json:"id"`
// AuctionActivityId int64 `json:"auction_activity_id" description:"竞拍轮次的id, 对应auction_activity表的主键id"`
// AuctionTime int64 `json:"auction_time" description:"竞拍持续时间 秒为单位"`
// Id int `json:"id"`
// AuctionActivityId int `json:"auction_activity_id" description:"竞拍轮次的id, 对应auction_activity表的主键id"`
// AuctionTime int `json:"auction_time" description:"竞拍持续时间 秒为单位"`
// AuctionStatus string `json:"auction_status" description:"竞拍活动状态 [可竞拍,不可竞拍]"`
// AreaId int64 `json:"area_id" description:"地区id"`
// AreaId int `json:"area_id" description:"地区id"`
// AreaStatus string `json:"area_status" description:"多地区模式[开启,关闭]"`
// AuctionGoodsName string `json:"auction_goods_name" description:"竞拍物品名称"`
// AuctionGoodsDesc string `json:"auction_goods_desc" description:"竞拍物品描述"`
@ -17,7 +17,7 @@ package models
// Pic string `json:"pic" description:"竞拍图片"`
// BaseInterval float64 `json:"base_interval" description:"基础区间"`
// Threshold float64 `json:"threshold" description:"活动结束阀值"`
// UseTimes int64 `json:"use_times" description:"使用次数"`
// UseTimes int `json:"use_times" description:"使用次数"`
// IsDelete bool `json:"is_delete" xorm:"is_delete" description:"是否删除"`
// CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`
// UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`

6
models/bahe_activity.go

@ -2,8 +2,8 @@ package models
//拔河比赛活动
//type BaheActivity struct {
// Id int64 `json:"id"`
// ActivityId int64 `json:"activity_id" description:"活动的id"`
// Id int `json:"id"`
// ActivityId int `json:"activity_id" description:"活动的id"`
// BaheActivityName string `json:"bahe_activity_name" description:"拔河名称"`
// RandomTeam string `json:"random_team" description:"[开启,关闭]随机组队模式"`
// MaxMoreCode string `json:"max_more_code" description:"[开启,关闭]大屏多二维码模式"`
@ -14,6 +14,6 @@ package models
// UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`
//}
//func (b *BaheActivity) GetBaheActivityById(id int64) (bool, error) {
//func (b *BaheActivity) GetBaheActivityById(id int) (bool, error) {
// return core.GetXormAuto().Where("id=? and is_delete=?", id, false).Get(b)
//}

6
models/bahe_history.go

@ -4,9 +4,9 @@ package models
//
////拔河的比赛结果的记录
//type BaheHistory struct {
// Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
// ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动的id') INT(11)"`
// WinnerId int64 `json:"winner_id" xorm:"not null comment('胜利队伍id') INT(11)"`
// Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
// ActivityId int `json:"activity_id" xorm:"not null comment('主活动的id') INT(11)"`
// WinnerId int `json:"winner_id" xorm:"not null comment('胜利队伍id') INT(11)"`
// MatchRes string `json:"match_res" xorm:"not null comment('比赛结果信息,[team_id=>人数,...]') INT(11)"`
// IsDelete bool `json:"is_delete" xorm:"default(0)"`
// CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`

8
models/bahe_rule.go

@ -2,14 +2,14 @@ package models
//拔河规则
//type BaheRule struct {
// Id int64 `json:"id"`
// BaheActivityId int64 `json:"bahe_activity_id" description:"拔河轮次的id, 对应bahe_activity的主键id"`
// AreaId int64 `json:"area_id" description:"地区id"`
// Id int `json:"id"`
// BaheActivityId int `json:"bahe_activity_id" description:"拔河轮次的id, 对应bahe_activity的主键id"`
// AreaId int `json:"area_id" description:"地区id"`
// RandomTeam string `json:"random_team" description:"[开启,关闭]随机组队模式"`
// MaxMoreCode string `json:"max_more_code" description:"[开启,关闭]大屏多二维码模式"`
// H5Choose string `json:"h_5_choose" description:"[开启,关闭]h5挑选队伍"`
// BaheStatus string `json:"bahe_status" description:"拔河活动状态[未开始,进行中,结束]"`
// UseTimes int64 `json:"use_times" description:"使用次数"`
// UseTimes int `json:"use_times" description:"使用次数"`
// IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
// CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`
// UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`

13
models/bahe_team.go

@ -1,19 +1,20 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const BaheTeamTable = TableNamePrefix + "bahe_team"
//拔河队伍
type BaheTeam struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('活动id') INT(11)"`
BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null comment('拔河活动id') INT(11) "`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('活动id') INT(11)"`
BaheActivityId int `json:"bahe_activity_id" xorm:"not null comment('拔河活动id') INT(11) "`
BaheTeamName string `json:"bahe_team_name" xorm:"not null comment('拔河队伍得名称') VARCHAR(255)"`
TotalScore int64 `json:"total_score" xorm:"-" description:"总分数"`
TotalScore int `json:"total_score" xorm:"-" description:"总分数"`
Rank int `json:"rank" xorm:"-" description:"排名"`
Members []*BaheTeamMember `json:"members" xorm:"-" description:"队伍人数"`
Qrcode string `json:"qrcode" xorm:"-" description:"二维码"`
@ -26,7 +27,7 @@ func (t *BaheTeam) TableName() string {
return BaheTeamTable
}
func (t *BaheTeam) GetOtherTeam(id, bid int64) (bool, error) {
func (t *BaheTeam) GetOtherTeam(id, bid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and id=? and bahe_activity_id=?", id, bid).Get(t)
}

34
models/bahe_team_member.go

@ -10,13 +10,14 @@ const BaheTeamMemberTableName = TableNamePrefix + "bahe_team_member"
//拔河队伍人员
type BaheTeamMember struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
TeamId int64 `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
BaheActivityId int `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
TeamId int `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
TeamName string `json:"team_name" xorm:"not null default('') comment('队伍名字') VARCHAR(255)"`
MemberId int64 `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
MemberId int `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
Score int `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
Avatar string `json:"avatar" xorm:"not null comment('头像') VARCHAR(255)"`
NickName string `json:"nick_name" xorm:"not null comment('昵称') VARCHAR(255)"`
SortTime int64 `json:"sort_time" xorm:"not null default '0' comment('排序时间') VARCHAR(20)"`
@ -30,19 +31,24 @@ func (t *BaheTeamMember) TableName() string {
}
func (t *BaheTeamMember) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(uid, bid, rid int64) (bool, error) {
return core.GetXormAuto().Where("member_id=? and bahe_activity_id=? and rehearsal_id=? and is_delete=0", uid, bid, rid).Get(t)
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(archId, userId, baheId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("arch_id=? and member_id=? and bahe_activity_id=? "+
" and rehearsal_id=? and is_delete=0", archId, userId, baheId, rehearsalId).Get(t)
}
func (t *BaheTeamMember) IncrScoreById(id, score int64) (int64, error) {
func (t *BaheTeamMember) IncrScoreById(archId, id, score interface{}) (int64, error) {
t.SortTime = time.Now().UnixNano()
return core.GetXormAuto().ID(id).Incr("score", score).Cols("score, sort_time").Update(t)
return core.GetXormAuto().Where("arch_id=? and id=?", archId, id).
Incr("score", score).Cols("score, sort_time").Update(t)
}
func GetBaheMembersByTeamId(obj, teamId, rehearsalId interface{}) error {
return core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&obj)
func GetBaheMembersByTeamId(teamId, rehearsalId interface{}) ([]*BaheTeamMember, error) {
members := make([]*BaheTeamMember, 0)
err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&members)
return members, err
}

7
models/barrage_history.go

@ -8,9 +8,10 @@ const BarrageHistoryTableName = TableNamePrefix + "barrage_history"
//弹幕历史记录
type BarrageHistory struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动得id') INT(11)"`
UserId int64 `json:"user_id" xorm:"not null comment('用户得id') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动得id') INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('用户得id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
Content string `json:"content" xorm:"not null comment('内容') TEXT"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null created comment('创建时间') DATETIME"`

107
models/base.go

@ -1,15 +1,103 @@
package models
import (
"errors"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/xormplus/xorm"
"hudongzhuanjia/utils/define"
"net/url"
"reflect"
"strings"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/xormplus/xorm"
)
const TableNamePrefix = "ox_"
type Model struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
}
func ParseToken(token string) (_type string, id int, err error) {
token, _ = url.PathUnescape(token)
tokens := strings.SplitN(token, ":", 2)
if len(tokens) < 2 {
err = errors.New("token失效")
return
}
_type = tokens[0]
if tokens[0] == define.TYPE_USER || tokens[0] == define.TYPE_LIVEUSER { // h5用户
user := &User{}
err = user.GetByToken(tokens[1])
if err != nil {
return
}
id = user.Id
} else if tokens[0] == define.TYPE_CUSTOMER { // 客户
customer := &Customer{}
err = customer.GetByToken(tokens[1])
if err != nil {
return
}
id = customer.Id
} else if tokens[0] == define.TYPE_ENTRYPEOPLE { // 录入人员
entry := &OrderEntryPerson{}
err = entry.GetByToken(tokens[1])
if err != nil {
return
}
id = entry.Id
} else {
err = errors.New("token失效")
}
return
}
func (m *Model) TableName(bean interface{}) string {
return core.GetXormAuto().TableName(bean)
}
func (m *Model) Alias(bean interface{}, alias string) string {
tn := m.TableName(bean)
return fmt.Sprintf("%s as %s", tn, alias)
}
func (m *Model) Add(bean interface{}) (int64, error) {
return core.GetXormAuto().InsertOne(bean)
}
func (m *Model) Get(bean interface{}, id interface{}) (bool, error) {
return core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and id=?", id).Get(bean)
}
func (m *Model) Del(bean interface{}, id interface{}) (int64, error) {
return core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and id=?", id).Delete(bean)
}
func (m *Model) Update(bean, id interface{}, field ...string) (int64, error) {
s := core.GetXormAuto().NoAutoCondition().ID(id)
defer s.Close()
if len(field) > 0 {
if field[0] == "*" {
s = s.AllCols()
} else if field[0] == "#" {
s = s.MustCols(field[1:]...)
} else {
s = s.Cols(field...)
}
}
return s.Update(bean)
}
func (m *Model) Exist(bean, id interface{}) (bool, error) {
return core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and id=?", id).Exist(bean)
}
func init() {
err := core.GetXormAuto().Sync2(
new(Activity),
@ -17,6 +105,7 @@ func init() {
new(AreaStore),
new(AuctionHistory),
new(AuctionResultRecord),
new(AuctionPlayer),
new(BaheTeam),
new(BaheTeamMember),
new(BarrageHistory),
@ -134,13 +223,17 @@ func GetTableName(bean interface{}) string {
return core.GetXormAuto().TableName(bean)
}
func AliasTableName(bean interface{}, alias string) string {
func Alias(bean interface{}, alias string) string {
tn := GetTableName(bean)
return fmt.Sprintf("%s as %s", tn, alias)
}
func Get(bean interface{}, id int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(bean)
func Get(bean interface{}, id interface{}) (bool, error) {
return core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and id=?", id).Get(bean)
}
func Del(bean interface{}, id interface{}) (int64, error) {
return core.GetXormAuto().NoAutoCondition().ID(id).Delete(bean)
}
func Add(bean interface{}) (int64, error) {
@ -149,9 +242,9 @@ func Add(bean interface{}) (int64, error) {
func Update(id, bean interface{}, field ...string) (int64, error) {
if len(field) > 0 {
return core.GetXormAuto().ID(id).Cols(field...).Update(bean)
return core.GetXormAuto().ID(id).NoAutoCondition().Cols(field...).Update(bean)
} else {
return core.GetXormAuto().ID(id).Update(bean)
return core.GetXormAuto().ID(id).NoAutoCondition().Update(bean)
}
}

28
models/bully_screen_history.go

@ -1,33 +1,35 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const BullyScreenHistoryTableName = TableNamePrefix + "bully_screen_history"
//霸屏历史表
type BullyScreenHistory struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
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"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
BullyScreenServerId int64 `json:"bully_screen_server_id" xorm:"not null default 0 comment('霸屏服务得id') INT(11)"`
BullyScreenServerId int `json:"bully_screen_server_id" xorm:"not null default 0 comment('霸屏服务得id') INT(11)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单号') VARCHAR(128)"`
CustomerId int64 `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户得id') INT(11)"`
CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户得id') INT(11)"`
Nickname string `json:"nickname" xorm:"not null default '' comment('发送者昵称') VARCHAR(128)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0是正式') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0是正式') INT(11)"`
Style int `json:"style" xorm:"not null default 0 comment('服务样式') INT(11)"`
Second int `json:"second" xorm:"not null default 0 comment('霸屏时间(秒)') INT(11)"`
Content string `json:"content" xorm:"not null comment('内容') TEXT"`
Status int `json:"status" xorm:"not null default(0) comment('[-1未支付,0未审核,1未通过,2已通过,3已推送,4已作废]') INT(11)"`
Amount float64 `json:"amount" xorm:"not null default 0.00 comment('霸屏金额') DECIMAL(18)"`
ReviewTime int64 `json:"review_time" xorm:"not null default 0 comment('审核的时间') INT(11)"`
Version int64 `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
ReviewTime int `json:"review_time" xorm:"not null default 0 comment('审核的时间') INT(11)"`
Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
}
func (t *BullyScreenHistory) TableName() string {
@ -38,7 +40,7 @@ func (t *BullyScreenHistory) GetByOutTradeNo(outTradeNo string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
}
func (t *BullyScreenHistory) UpdateStatus(id int64, status int) (int64, error) {
func (t *BullyScreenHistory) UpdateStatus(id int, status int) (int64, error) {
t.Status = status
return core.GetXormAuto().ID(id).Cols("status").Update(t)
}
@ -50,7 +52,7 @@ func (t *BullyScreenHistory) UpdateStatusByOutTradeNo(outTradeNo string, status
Cols("status").Update(t)
}
func (t *BullyScreenHistory) UpdateStatusByIds(ids []int64, status int) error {
func (t *BullyScreenHistory) UpdateStatusByIds(ids []int, status int) error {
if len(ids) > 0 {
t.Status = status
_, err := core.GetXormAuto().In("id", ids).Cols("status").
@ -66,9 +68,9 @@ func GetBullyScreenHistoryByIds(ids interface{}) ([]*BullyScreenHistory, error)
return result, err
}
func (t *BullyScreenHistory) SumSecond(serverId, rehearsalId interface{}) (float64, error) {
func (t *BullyScreenHistory) SumSecond(serverId, rehearsalId, archId interface{}) (float64, error) {
totalSecond, err := core.GetXormAuto().Where("bully_screen_server_id=? and status=3 and "+
" is_delete=false and rehearsal_id=?", serverId, rehearsalId).
" is_delete=false and rehearsal_id=? and arch_id=?", serverId, rehearsalId, archId).
Sum(new(BullyScreenHistory), "second")
return totalSecond, err
}

11
models/bully_screen_server.go

@ -1,16 +1,17 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const BullyScreenServerTableName = TableNamePrefix + "bully_screen_server"
//霸屏服务
type BullyScreenServer struct {
Id int64 `json:"id"`
ActivityId int64 `json:"activity_id" description:"主活动的id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" description:"主活动的id"`
ServerStartTime time.Time `json:"server_start_time" description:"服务开始时间"`
ServerEndTime time.Time `json:"server_end_time" description:"服务结束时间"`
Start string `json:"start" description:"霸屏是否开启 [开启|关闭]"`
@ -26,9 +27,9 @@ func (t *BullyScreenServer) TableName() string {
}
func (t *BullyScreenServer) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func (t *BullyScreenServer) GetByActivityId(aid int64) (bool, error) {
func (t *BullyScreenServer) GetByActivityId(aid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t)
}

9
models/bully_screen_wallet.go

@ -1,15 +1,16 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const BSWalletTableName = TableNamePrefix + "bully_screen_wallet"
type BullyScreenWallet struct {
Id int64 `json:"id"`
CustomerId int64 `json:"customer_id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CustomerId int `json:"customer_id"`
Balance float64 `json:"balance"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@ -19,7 +20,7 @@ func (t *BullyScreenWallet) TableName() string {
return BSWalletTableName
}
func (t *BullyScreenWallet) IncrBalance(cid int64, money float64) (int64, error) {
func (t *BullyScreenWallet) IncrBalance(cid int, money float64) (int64, error) {
return core.GetXormAuto().Where("customer_id=?", cid).
Incr("balance", money).Cols("balance").Update(t)
}

8
models/bully_screen_wallet_hisotry.go

@ -5,15 +5,15 @@ import "time"
const BSWalletHistoryTableName = TableNamePrefix + "bully_screen_wallet_history"
type BullyScreenWalletHistory struct {
Id int64 `json:"id" xorm:"not null autoincr pk INT(11)"`
CustomerId int64 `json:"customer_id" xorm:"not null default 0 comment('客户表id') INT(11)"`
UserId int64 `json:"customer_id" xorm:"not null default 0 comment('客户表id') INT(11)"`
Id int `json:"id" xorm:"not null autoincr pk INT(11)"`
CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户表id') INT(11)"`
UserId int `json:"customer_id" xorm:"not null default 0 comment('客户表id') INT(11)"`
Money float64 `json:"money" xorm:"not null default 0.00 comment('金额[分正负]') DECIMAL(10)"`
HisBalance string `json:"his_balance" xorm:"not null default '0' comment('历史霸屏余额') VARCHAR(128)"`
Type string `json:"type" xorm:"not null default '' comment('记录类型 霸屏/提现') VARCHAR(128)"`
BullyScreenUsername string `json:"bully_screen_username" xorm:"not null default '' comment('发起霸屏的那个用户的用户名') VARCHAR(128)"`
BullyScreenAccount string `json:"bully_screen_account" xorm:"not null default '' comment('支付霸屏的账户 只支持支付宝或微信') VARCHAR(128)"`
CashDrawId int64 `json:"cash_draw_id" xorm:"not null default 0 comment('cash_draw提现表id') INT(11)"`
CashDrawId int `json:"cash_draw_id" xorm:"not null default 0 comment('cash_draw提现表id') INT(11)"`
Status string `json:"status" xorm:"not null default '交易成功' comment('交易状态') VARCHAR(128)"`
Mark string `json:"mark" xorm:"not null comment('备注') TEXT"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`

17
models/calorie.go

@ -1,17 +1,18 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/utils/define"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CalorieTableName = TableNamePrefix + "calorie"
type Calorie struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
GameDuration int64 `json:"game_duration" xorm:"not null default(60) comment('游戏时长秒') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
GameDuration int `json:"game_duration" xorm:"not null default(60) comment('游戏时长秒') INT(11)"`
StartTime int64 `json:"start_time" xorm:"not null default(0) comment('游戏开始时间') INT(11)"`
Status string `json:"status" xorm:"not null default('未开始') comment('状态[未开始,准备中,进行中,已结束]') VARCHAR(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)"`
@ -23,25 +24,25 @@ func (t *Calorie) TableName() string {
return CalorieTableName
}
func (t *Calorie) UpdateToStatusByActivityId(aid int64, before, after string) (int64, error) {
func (t *Calorie) UpdateToStatusByActivityId(aid int, before, after string) (int64, error) {
t.Status = after
t.UpdatedAt = time.Now()
return core.GetXormAuto().Where("is_delete=0 and status=? and activity_id=?", before, aid).
Cols("status", "updated_at").Update(t)
}
func (t *Calorie) UpdateStatusById(id int64, status string) (int64, error) {
func (t *Calorie) UpdateStatusById(id int, status string) (int64, error) {
t.Status = status
t.UpdatedAt = time.Now()
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Cols("status", "start_time", "updated_at").Update(t)
}
func (t *Calorie) GetCurrent(aid int64) (bool, error) {
func (t *Calorie) GetCurrent(aid interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t)
}
func UpdateCalorieStatusByActivityId(aid int64) (int64, error) {
func UpdateCalorieStatusByActivityId(aid int) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
Update(&Calorie{Status: define.StatusNotBegin})
}

44
models/customer.go

@ -2,20 +2,21 @@ package models
import (
"fmt"
"github.com/pkg/errors"
"go.uber.org/zap"
"hudongzhuanjia/logger"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/ouxuanserver/osmanthuswine/src/helper"
"github.com/pkg/errors"
)
const CustomerTN = TableNamePrefix + "customer"
//客户表
type Customer struct {
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
Model `xorm:"extends"`
//Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
//IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
//CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
//UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
Activities []*Activity `json:"activities" xorm:"-" description:"用户创建的主活动"`
Nickname string `json:"nickname" xorm:"not null default('') comment('昵称') VARCHAR(255)"`
Username string `json:"username" xorm:"not null default('') comment('用户名') VARCHAR(255)"`
@ -24,19 +25,17 @@ type Customer struct {
Token string `json:"token" xorm:"not null default('') comment('登陆凭证token') VARCHAR(255)"`
Balance float64 `json:"balance" xorm:"not null default(0.00) comment('余额') DECIMAL(18)"`
SmsCode string `json:"sms_code" xorm:"not null default('') comment('短信验证码') VARCHAR(128)"`
AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` // 子账号的地区
ActivityId int64 `json:"activity_id" xrom:"not null default(0) comment('主活动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` // 子账号的地区
ActivityId int `json:"activity_id" xrom:"not null default(0) comment('主活动id') INT(11)"`
HeadImg string `json:"head_img" xorm:"not null default('') comment('头像') VARCHAR(255)"`
Email string `json:"email" xorm:"not null default('') comment('邮箱') VARCHAR(128)"`
Phone string `json:"phone" xorm:"not null default('') comment('电话号码') VARCHAR(128)"`
QqOpenid string `json:"qq_openid" xorm:"not null default('') comment('qq openid') VARCHAR(255)"`
Tag string `json:"tag" xorm:"-" description:"tag ws过滤信息"`
Pid int64 `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h
RoleId int64 `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"`
TopId int64 `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"`
IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
Pid int `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h
IsSpecial int `json:"is_special" xorm:"not null default 0 comment('是否是特殊用户') TINYINT(1)"`
RoleId int `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"`
TopId int `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"`
}
func (t *Customer) TableName() string {
@ -48,11 +47,7 @@ func (t *Customer) Author(name, pwd string) error {
exist, err := core.GetXormAuto().Where("(phone=? or email=?) and role_id=? and is_delete=0",
name, name, 6).Get(t)
if err != nil {
logger.Error("验证用户失败",
zap.Error(err),
zap.String("name", name),
zap.String("pwd", pwd))
return errors.WithStack(err)
return err
}
if !exist {
return errors.New("用户名错误,请重新输入")
@ -78,3 +73,14 @@ func (t *Customer) GetByQQOpenid(openid string) (bool, error) {
func (t *Customer) GetByActivityIdAndAreaId(activityId, areaId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId).Get(t)
}
func (t *Customer) GetByToken(token string) error {
exist, err := core.GetXormAuto().Where("is_delete=0 and token=?", token).Get(t)
if err != nil {
return err
}
if !exist {
return errors.New("customer信息异常")
}
return nil
}

27
models/customer_goods.go

@ -1,27 +1,28 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CustomerGoodsTableName = TableNamePrefix + "customer_goods"
type CustomerGoods struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default '' comment('商品图片') VARCHAR(255)"`
IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"`
FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"`
Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"`
Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"`
Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价')"`
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
GoodsPicUrl []interface{} `json:"goods_pic_url" xorm:"json comment('商品图片')"`
IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"`
FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"`
Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"`
Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"`
Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"`
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
//// 无关变量
GoodType int `json:"good_type" xorm:"-"`
@ -34,10 +35,10 @@ func (t *CustomerGoods) TableName() string {
}
func (t *CustomerGoods) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func GetGoodsByActivityId(activityId, areaId int64) ([]*CustomerGoods, error) {
func GetGoodsByActivityId(activityId, areaId interface{}) ([]*CustomerGoods, error) {
goods := make([]*CustomerGoods, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId).
Asc("created_at").Find(&goods)

18
models/customer_operation.go

@ -10,11 +10,11 @@ import (
// 用户操作, 主从账号同步信息
// 拔河/摇红包/摇奖券/订单/上墙/霸屏/抽奖/投票/竞拍/打赏/会务
type CustomerOperation struct {
Id int64 `json:"id"`
CustomerId int64 `json:"customer_id" description:"客户id"`
ActivityId int64 `json:"activity_id" description:"主活动id"`
AreaId int64 `json:"area_id" description:"地区id"`
ModuleActivityId int64 `json:"module_activity_id" description:"具体活动id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CustomerId int `json:"customer_id" description:"客户id"`
ActivityId int `json:"activity_id" description:"主活动id"`
AreaId int `json:"area_id" description:"地区id"`
ModuleActivityId int `json:"module_activity_id" description:"具体活动id"`
ModuleActivityType string `json:"module_activity_type" description:"具体活动类型"`
Operation string `json:"operation" description:"操作内容"`
OtherData interface{} `json:"other_data" xorm:"-" description:"额外的字段"`
@ -33,7 +33,7 @@ func (op *CustomerOperation) SaveCustomerOperation() int64 {
return row
}
func (op *CustomerOperation) GetOpsByCustomerId(customerId int64, areaId int64) []*CustomerOperation {
func (op *CustomerOperation) GetOpsByCustomerId(customerId int, areaId int) []*CustomerOperation {
ops := make([]*CustomerOperation, 0)
var err error
if areaId == 0 {
@ -48,13 +48,13 @@ func (op *CustomerOperation) GetOpsByCustomerId(customerId int64, areaId int64)
return ops
}
func (op *CustomerOperation) GetOpByCustomerId(customerId int64) (bool, error) {
func (op *CustomerOperation) GetOpByCustomerId(customerId int) (bool, error) {
return core.GetXormAuto().Where("customer_id=? and is_delete=0", customerId).OrderBy("created_at desc").Get(op)
}
func (op *CustomerOperation) GetOpByActivityId(activityId int64) (bool, error) {
func (op *CustomerOperation) GetOpByActivityId(activityId int) (bool, error) {
return core.GetXormAuto().Where("activity_id=? and is_delete=0", activityId).OrderBy("created_at desc").Get(op)
}
func (op *CustomerOperation) GetOpByCustomerIdAndActivityId(pid, activityId int64) (bool, error) {
func (op *CustomerOperation) GetOpByCustomerIdAndActivityId(pid, activityId int) (bool, error) {
return core.GetXormAuto().Where("customer_id=? and activity_id=?", pid, activityId).OrderBy("created_at desc").Get(op)
}

100
models/customer_order.go

@ -9,29 +9,28 @@ import (
const CustomerOrderTableName = TableNamePrefix + "customer_order"
type CustomerOrder struct {
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
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"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
UserPrizeId int64 `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(255)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') BIGINT(20)"`
OrderNo string `json:"order_no" xorm:"not null default 0 comment('本机订单号') VARCHAR(255)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单流水号') VARCHAR(255)"`
OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
GoodsId int64 `json:"goods_id,omitempty" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
GoodsName string `json:"goods_name,omitempty" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
GoodsNum int `json:"goods_num,omitempty" xorm:"not null default 0 comment('商品数量') INT(11)"`
TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额')"`
PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额')"`
Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]')"`
Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付即待发货3已发货4确认收货5申请退款6已退款7申请退货8已退货9已取消]')"`
ExpireTime int64 `json:"expire_time" xorm:"not null default 0 comment('订单过时') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('订单类型、0录入订单1直播订单')"`
UserPrizeId int `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(255)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') BIGINT(20)"`
OrderNo string `json:"order_no" xorm:"not null default 0 comment('本机订单号') VARCHAR(255)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单流水号') VARCHAR(255)"`
OrderEntryPersonId int `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') INT(11)"`
OrderEntryPersonName string `json:"order_entry_person_name" xorm:"not null default '' comment('订单录入人员名字') INT(11)"`
BuyerId int `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额')"`
PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额')"`
Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]')"`
Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付即待发货3已发货4确认收货5申请退款6已退款7申请退货8已退货9已取消]')"`
ExpireTime int64 `json:"expire_time" xorm:"not null default 0 comment('订单过时') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('订单类型、0录入订单1直播订单')"`
// 快递信息
Receiver string `json:"receiver" xorm:"not null default '' comment('收件人') VARCHAR(128)"`
@ -44,40 +43,35 @@ type CustomerOrder struct {
CancelTime time.Time `json:"cancel_time" xorm:"comment('取消时间') DATETIME"`
AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"`
GoodsId int `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
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)"`
// 无关变量
OrderTime string `json:"order_time,omitempty" xorm:"-"`
Good *CustomerGoods `json:"good,omitempty" xorm:"-"`
User *User `json:"user,omitempty" xorm:"-"`
OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"`
ServicePhone string `json:"service_phone" xorm:"-"`
//SubOrders []*CustomerOrderSub `json:"sub_orders" xorm:"-"`
SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"`
OrderTime string `json:"order_time,omitempty" xorm:"-"`
Good *CustomerGoods `json:"good,omitempty" xorm:"-"`
User *User `json:"user,omitempty" xorm:"-"`
ServicePhone string `json:"service_phone" xorm:"-"`
SubOrders []*SubOrderResult `json:"sub_orders,omitempty" xorm:"-"`
}
func (t *CustomerOrder) TableName() string {
return CustomerOrderTableName
}
func (t *CustomerOrder) SoftDeleteById(id int64) (int64, error) {
t.IsDelete = true
return core.GetXormAuto().Where("id=?", id).Cols("is_delete").Update(t)
func (t *CustomerOrder) Alias(name string) string {
return Alias(t, name)
}
func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
}
func (t *CustomerOrder) Count(activityId, rehearsalId int64, limitTime time.Time) (int64, error) {
return core.GetXormAuto().Where("user_prize_id=0 and created_at >= ? and "+
"activity_id=? and rehearsal_id=? and is_delete=0",
limitTime, activityId, rehearsalId).Count(t)
}
func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int64, status []string, page, pageSize int) ([]*CustomerOrder, error) {
func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int, status []string, page, pageSize int, archId interface{}) ([]*CustomerOrder, error) {
orders := make([]*CustomerOrder, 0)
err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+
"rehearsal_id=? and area_id=?", userId, activityId, rehearsalId, areaId).In("status", status).
Desc("created_at").Limit(pageSize, page*pageSize).Find(&orders)
"rehearsal_id=? and area_id=? and arch_id=?", userId, activityId, rehearsalId, areaId, archId).
In("status", status).Desc("created_at").Limit(pageSize, page*pageSize).Find(&orders)
return orders, err
}
@ -89,9 +83,37 @@ func (t *CustomerOrder) UpdateStatusBy(outTradeNo string, originStatus, status i
func GetExpiredAtLiveCustomerOrder() ([]*CustomerOrder, error) {
orders := make([]*CustomerOrder, 0)
err := core.GetXormAuto().Where("type=1 and is_delete=0 and status=0 and expire_time <= ?", time.Now().Unix()).Find(&orders)
err := core.GetXormAuto().Where("type=1 and is_delete=0 and "+
"status=0 and expire_time <= ? and out_trade_no<>''", time.Now().Unix()).Find(&orders)
if err != nil {
return nil, err
}
return orders, nil
}
func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId interface{}, _type int) (int64, error) {
s := core.GetXormAuto().NoAutoCondition().
Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
activityId, rehearsalId, archId)
defer s.Close()
if _type == 1 {
s.Distinct("buyer_id")
}
count, err := s.Count(t)
return count, err
}
func (t *CustomerOrder) SumCustomerOrder(activityId, rehearsalId, archId interface{}, limit int) ([]map[string]string, error) {
res := make([]map[string]string, 0)
err := core.GetXormAuto().Table(t).Select("order_entry_person_id, order_entry_person_name, COALESCE(SUM(goods_num), 0) as num").
NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
activityId, rehearsalId, archId).GroupBy("order_entry_person_id,order_entry_person_name").Limit(limit).
Desc("num").Find(&res)
return res, err
}
func (t *CustomerOrder) TotalCustomerOrderGoodsNum(activityId, rehearsalId, archId interface{}) (int64, error) {
sum, err := core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
activityId, rehearsalId, archId).SumInt(t, "goods_num")
return sum, err
}

35
models/customer_order_option.go

@ -2,24 +2,26 @@ package models
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CustomerOrderOptionTableName = TableNamePrefix + "customer_order_option"
type CustomerOrderOption struct {
Id int64 `json:"id" xorm:"not null pk INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"`
SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"`
Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"`
PostFeeType int `json:"post_fee_type" xorm:"not null default 0 comment('直播订单运费设置0包邮1货到付款2收费') TINYINT(1)"`
PostFee float64 `json:"post_fee" xorm:"not null default 0.00 comment('直播订单运费') DECIMAL(18)"`
MainServicePhone string `json:"main_service_phone" xorm:"not null default '' comment('客服电话') VARCHAR(128)"`
IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"`
CreatedAt time.Time `json:"-" xorm:"created"`
UpdatedAt time.Time `json:"-" xorm:"updated"`
Id int `json:"id" xorm:"not null pk INT(11)"`
IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"`
CreatedAt time.Time `json:"-" xorm:"created"`
UpdatedAt time.Time `json:"-" xorm:"updated"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"`
SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"`
Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"`
PostFeeType int `json:"post_fee_type" xorm:"not null default 0 comment('直播订单运费设置0包邮1货到付款2收费') TINYINT(1)"`
PostFee float64 `json:"post_fee" xorm:"not null default 0.00 comment('直播订单运费') DECIMAL(18)"`
MainServicePhone string `json:"main_service_phone" xorm:"not null default '' comment('客服电话') VARCHAR(128)"`
}
func (t *CustomerOrderOption) TableName() string {
@ -30,17 +32,16 @@ func (t *CustomerOrderOption) AliasName(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n)
}
func (t *CustomerOrderOption) GetByActivityId(aid int64) (bool, error) {
func (t *CustomerOrderOption) GetByActivityId(aid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t)
}
func (t *CustomerOrderOption) GetOpen(aid int64) (bool, error) {
func (t *CustomerOrderOption) GetOpen(aid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, 1).
Desc("created_at").Get(t)
}
func (t *CustomerOrderOption) Switch(aid int64, status int) (int64, error) {
func (t *CustomerOrderOption) Switch(aid int, status int) (int64, error) {
t.Status = status
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
Cols("status").Update(t)
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Cols("status").Update(t)
}

45
models/customer_order_sub.go

@ -2,26 +2,27 @@ package models
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const CustomerOrderSubTN = TableNamePrefix + "customer_order_sub"
type CustomerOrderSub struct {
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
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"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
OrderNo string `json:"order_no" xorm:"not null default 0 comment('订单号') VARCHAR(128)"`
GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('商品id') INT(11)"`
OrderId int `json:"order_id" xorm:"not null default 0 comment('订单id') VARCHAR(128)"`
GoodsId int `json:"goods_id" xorm:"not null default 0 comment('商品id') INT(11)"`
GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
GoodName string `json:"good_name" xorm:"not null default '' comment('商品名字') VARCHAR(128)"`
GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18)"`
GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18,2)"`
// 无关变量
GoodsPicUrl string `json:"goods_pic_url" xorm:"extends"`
GoodsPicUrl interface{} `json:"goods_pic_url" xorm:"extends"`
}
func (t *CustomerOrderSub) TableName() string {
@ -32,21 +33,33 @@ func (t *CustomerOrderSub) Alias(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n)
}
func GetCustomerOrderSubsByOrderNos(orderNos ...string) (subs []map[string]string, err error) {
type SubOrderResult struct {
OrderId int `json:"order_id"`
GoodsId int `json:"goods_id"`
GoodsNum int `json:"goods_num"`
GoodName string `json:"good_name"`
GoodPrice float64 `json:"good_price"`
GoodsPicUrl []interface{} `json:"goods_pic_url"`
}
func GetCustomerOrderSubsByOrderIds(orderIds interface{}) (subs []*SubOrderResult, err error) {
err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
Select("s.order_no, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").
Select("s.order_id, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").
Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id").
Where("s.is_delete=0").In("s.order_no", orderNos).
Desc("s.created_at").Find(&subs)
Where("s.is_delete=0").In("s.order_id", orderIds).Desc("s.created_at").Find(&subs)
return
}
func GetSubOrdersByOrderNo(orderNo string) ([]*CustomerOrderSub, error) {
subs := make([]*CustomerOrderSub, 0)
err := core.GetXormAuto().Where("is_delete=0 and order_no=?", orderNo).Find(&subs)
return subs, err
func GetCustomerOrderSubsByOrderId(orderId interface{}) (subs []map[string]string, err error) {
err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
Select("s.order_id, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").
Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id").
Where("s.is_delete=0 and s.order_id", orderId).Desc("s.created_at").Find(&subs)
return
}
func (t *CustomerOrderSub) IncrStock() {
func GetSubOrdersByOrderId(orderId interface{}) ([]*CustomerOrderSub, error) {
subs := make([]*CustomerOrderSub, 0)
err := core.GetXormAuto().Where("is_delete=0 and order_id=?", orderId).Find(&subs)
return subs, err
}

9
models/dan_mu_server.go

@ -1,15 +1,16 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const DanMuServerTableName = TableNamePrefix + "dan_mu_server"
type DanMuServer struct {
Id int64 `json:"id" xorm:"not null pk autoincr"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)" description:"主活动id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)" description:"主活动id"`
DanmuSwitch string `json:"danmu_switch" xorm:"not null default('关闭') comment('弹幕服务开启、关闭') VARCHAR(255)"`
DanmuOpacity int `json:"danmu_opacity" xorm:"not null default(100) comment('弹幕透明度') INT(11)"`
DanmuSpeed int `json:"danmu_speed" xorm:"not null default(50) comment('弹幕速度') INT(11)"`
@ -27,6 +28,6 @@ func (t *DanMuServer) TableName() string {
return DanMuServerTableName
}
func (t *DanMuServer) GetByActivityId(aid int64) (bool, error) {
func (t *DanMuServer) GetByActivityId(aid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t)
}

6
models/invitation.go

@ -7,8 +7,8 @@ import (
)
type Invitation struct {
Id int64 `json:"id" description:"主键"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')" description:"主活动id"`
Id int `json:"id" xorm:"not null autoincr pk INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动id')" description:"主活动id"`
SettingBox string `json:"setting_box" xorm:"not null comment('表单选项json化')" description:"表单选项Json化"`
SelfBox string `json:"self_box" xorm:"not null comment('表单选项json化')" description:"自定义表单选项json"`
SubmitTimeLimit time.Time `json:"submit_time_limit" xorm:"not null comment('0为不限制 1为限制 限制必填时间段')" description:"0为不限制 1为限制 限制必填时间段"`
@ -20,6 +20,6 @@ type Invitation struct {
UpdatedAt time.Time `json:"-" xorm:"updated"`
}
func (i *Invitation) GetInvitationByActivityId(aid int64) (bool, error) {
func (i *Invitation) GetInvitationByActivityId(aid int) (bool, error) {
return core.GetXormAuto().Where("activity_id = ? and is_delete = ?", aid, false).Get(i)
}

24
models/invitation_letter.go

@ -9,11 +9,12 @@ import (
const InvitationLetterTableName = TableNamePrefix + "invitation_letter"
type InvitationLetter struct {
Id int64 `json:"id" xorm:"pk autoincr" description:"主键"`
UserId int64 `json:"user_id" xorm:"not null default(0) comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
InvitationId int64 `json:"invitation_id" xorm:"not null default(0) comment('邀请函id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"`
Id int `json:"id" xorm:"pk autoincr" description:"主键"`
UserId int `json:"user_id" xorm:"not null default(0) comment('用户id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
InvitationId int `json:"invitation_id" xorm:"not null default(0) comment('邀请函id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
ExtraData string `json:"extra_data" xorm:"comment('邀请函信息') TEXT"`
IsDelete bool `json:"is_delete" xorm:"default(0)" description:"删除"`
CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建"`
@ -25,14 +26,15 @@ func (t *InvitationLetter) TableName() string {
}
func (t *InvitationLetter) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func (t *InvitationLetter) GetByUserIdAndActivityId(uid, aid, rid int64) (bool, error) {
return core.GetXormAuto().Where("user_id=? and activity_id=? and rehearsal_id=? and is_delete=0", uid, aid, rid).Get(t)
func (t *InvitationLetter) GetByUserIdAndActivityId(userId, activityId, archId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("user_id=? and activity_id=? and arch_id=? and rehearsal_id=? and is_delete=0",
userId, activityId, archId, rehearsalId).Get(t)
}
func (t *InvitationLetter) Count(activityId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=?", activityId, rehearsalId).
Count(t)
func (t *InvitationLetter) Count(activityId, archId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and arch_id=? and rehearsal_id=?",
activityId, archId, rehearsalId).Count(t)
}

9
models/live_config.go

@ -1,22 +1,23 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LiveConfigTN = TableNamePrefix + "live_config"
type LiveConfig struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
CusId int `json:"cus_id" xorm:"not null default 0 comment('客户id') INT(11)"`
LiveSwitch int `json:"live_switch" xorm:"not null default 0 comment('直播开关0关1开') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地域') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地域') INT(11)"`
LiveRoomId string `json:"live_room_id" xorm:"not null default '' comment('直播间id') VARCHAR(128)"`
AdaptationFunc []interface{} `json:"adaptation_func" xorm:"json not null default '' comment('选中的适配功能及互动已买的服务id,json格式') VARCHAR(255)"`
StartTime time.Time `json:"start_time" xorm:"not null default '1970-01-01 08:00:00' comment('开播时间') DATETIME"`

9
models/live_config_area.go

@ -1,19 +1,20 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LiveConfigAreaTN = TableNamePrefix + "live_config_area"
type LiveConfigArea struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
LiveH5Url string `json:"live_h5_url" xorm:"not null default '' comment('h5直播地址') VARCHAR(255)"`
LiveH5Qrcode string `json:"live_h5_qrcode" xorm:"not null default '' comment('h5直播地址二维码') VARCHAR(255)"`
AdminLiveUrl string `json:"admin_live_url" xorm:"not null default '' comment('管理员直播地址,即直播页面中管理员登录页面') VARCHAR(255)"`

10
models/live_red_envelope_rule.go

@ -9,15 +9,15 @@ import (
const LiveRedPackInfoTN = TableNamePrefix + "live_red_envelope_rule"
type LiveRedEnvelopeRule struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"`
Prompt string `json:"prompt" xorm:"not null default 0 comment('祝福语') VARCHAR(255)"`
Amount float64 `json:"amount" xorm:"not null default 0 comment('红包金额') DECIMAL(18)"`
Num int `json:"num" xorm:"not null default 0 comment('红包个数') INT(11)"`

20
models/live_viewer.go

@ -1,27 +1,29 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LiveViewerTN = TableNamePrefix + "live_viewer"
type LiveViewer struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('活动id') INT(11)"`
LiveConfigId int64 `json:"live_config_id" xorm:"not null default 0 comment('直播id') INT(11)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('活动id') INT(11)"`
LiveConfigId int `json:"live_config_id" xorm:"not null default 0 comment('直播id') INT(11)"`
}
func (t *LiveViewer) TableName() string {
return LiveViewerTN
}
func (t *LiveViewer) Record(uid, aid, lid int64) error {
func (t *LiveViewer) Record(uid, aid, lid int) error {
session := core.GetXormAuto().NewSession()
defer session.Close()
session.Begin()
@ -53,7 +55,11 @@ func (t *LiveViewer) Record(uid, aid, lid int64) error {
func GetLiveViewerByLiveConfigIds(ids interface{}) ([]*LiveViewer, error) {
viewers := make([]*LiveViewer, 0)
err := core.GetXormAuto().Where("is_delete=0").In("live_config_id", ids).Find(&viewers)
err := core.GetXormAuto().Table(&LiveViewer{}).Alias("l").
Join("left", Alias(&Activity{}, "a"),
"a.id=l.activity_id and l.arch_id=a.arch_id").
Where("l.is_delete=0").In("l.live_config_id", ids).
Find(&viewers)
return viewers, err
}

13
models/lottery_draw_activity.go

@ -1,17 +1,18 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LotteryDrawActivityTableName = TableNamePrefix + "lottery_draw_activity"
//抽奖活动
type LotteryDrawActivity struct {
Id int64 `json:"id"`
ActivityId int64 `json:"activity_id" description:"主活动的id"`
CreatorId int64 `json:"creator_id" description:"创建者id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int `json:"activity_id" description:"主活动的id"`
CreatorId int `json:"creator_id" description:"创建者id"`
LotteryDrawActivityName string `json:"lottery_draw_activity_name" description:"抽奖轮次名称"`
LotteryDrawRule *LotteryDrawRule `json:"lottery_draw_rule" xorm:"-" description:"抽奖活动规则"`
IsDelete bool `json:"-" xorm:"default(0)"`
@ -23,8 +24,8 @@ func (t *LotteryDrawActivity) TableName() string {
return LotteryDrawActivityTableName
}
func GetLDActivityIdsByActivityId(aid int64) ([]int64, error) {
lotteryIds := make([]int64, 0)
func GetLDActivityIdsByActivityId(aid int) ([]int, error) {
lotteryIds := make([]int, 0)
err := core.GetXormAuto().Table(new(LotteryDrawActivity)).Select("id").
Where("is_delete=0 and activity_id=?", aid).Find(&lotteryIds)
return lotteryIds, err

4
models/lottery_draw_envelope_wallet.go

@ -6,8 +6,8 @@ import (
//抽奖红包钱包
type LotteryDrawEnvelopeWallet struct {
Id int64 `json:"id"`
CustomerId int64 `json:"customer_id" description:"客户id"`
Id int `json:"id" xorm:"not null autoincr pk INT(11)"`
CustomerId int `json:"customer_id" description:"客户id"`
Balance float64 `json:"balance" description:"余额"`
IsDelete bool `json:"is_delete" xorm:"default(0)"`
CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`

67
models/lottery_draw_record.go

@ -1,30 +1,31 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LotteryDrawRecordTableName = TableNamePrefix + "lottery_draw_record"
type LotteryDrawRecord struct {
Id int64 `json:"id" xorm:"pk autoincr"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"`
UserPrizeId int64 `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"`
LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"`
LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"`
LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"`
UserId int64 `json:"user_id" xorm:"not null comment('用户id')"`
Id int `json:"id" xorm:"pk autoincr not null INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') INT(11)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式') INT(11)"`
UserPrizeId int `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"`
LotteryDrawActivityId int `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id') INT(11)"`
LotteryDrawRuleId int `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') INT(20)"`
LotteryDrawRuleLadderId int `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
UserId int `json:"user_id" xorm:"not null comment('用户id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"`
RollNum int `json:"roll_num" xrom:"not null default 0 comment('滚动次数') INT(11)"`
UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"`
UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"`
PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"`
AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"`
AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id')"`
UserName string `json:"user_name" xorm:"not null comment('用户名') VARCHAR(128)"`
UserPhone string `json:"user_phone" xorm:"not null comment('电话号码') VARCHAR(128)"`
PrizeName string `json:"prize_name" xorm:"not null comment('奖品名字') VARCHAR(128)"`
AreaName string `json:"area_name" xorm:"not null comment('地区名字') VARCHAR(128)"`
EntryPersonName string `json:"entry_person_name" xorm:"not null default '' comment('录入人员名单') VARCHAR(128)"`
Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"`
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"`
Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"`
WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"`
Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"`
IsDelete bool `json:"-" xorm:"default(0)"`
@ -40,8 +41,9 @@ func (t *LotteryDrawRecord) TableName() string {
return LotteryDrawRecordTableName
}
func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{}, rollNum int) (bool, error) {
session := core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=?", userId, ladderId)
func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId, archId interface{}, rollNum int) (bool, error) {
session := core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=? and arch_id=?",
userId, ladderId, archId)
defer session.Close()
if rollNum > 0 {
session.Where("roll_num=?", rollNum)
@ -49,32 +51,19 @@ func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{},
return session.Get(t)
}
func (t *LotteryDrawRecord) GetByUserPrizeId(upId int64) (bool, error) {
func (t *LotteryDrawRecord) GetByUserPrizeId(upId int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and user_prize_id=?", upId).Get(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").
Where("r.is_delete=0 and r.lottery_draw_rule_ladder_id=? and "+
"r.rehearsal_id=?", ladderId, rehearsalId)
defer session.Close()
if rollNum > 0 {
session = session.Where("roll_num=?", rollNum)
}
return session.Find(&obj)
}
func GetUserIdsByLotteryDrawRuleId(ruleId, rehearsalId, areaId interface{}) ([]int64, error) {
recordIds := make([]int64, 0)
func GetUserIdsByLotteryDrawRuleId(ruleId, rehearsalId, areaId, archId interface{}) ([]int, error) {
recordIds := make([]int, 0)
err := core.GetXormAuto().Table(new(LotteryDrawRecord)).Select("user_id").
Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0",
ruleId, rehearsalId, areaId).Find(&recordIds)
Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and arch_id=? and is_delete=0",
ruleId, rehearsalId, areaId, archId).Find(&recordIds)
return recordIds, err
}
func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId interface{}) (int64, error) {
return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? "+
"and rehearsal_id=? and area_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId).
Count(t)
func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId, archId interface{}) (int64, error) {
return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? and rehearsal_id=? "+
" and area_id=? and arch_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId, archId).Count(t)
}

17
models/lottery_draw_rule.go

@ -1,20 +1,21 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LotteryDrawRuleTableName = TableNamePrefix + "lottery_draw_rule"
//抽奖活动规则
type LotteryDrawRule struct {
Id int64 `json:"id"`
LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" description:"红包轮次的id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)`
LotteryDrawActivityId int `json:"lottery_draw_activity_id" description:"红包轮次的id"`
LotteryDrawRuleLadders []*LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-" description:"阶梯"`
AreaId int64 `json:"area_id" description:"地区id"`
AreaId int `json:"area_id" description:"地区id"`
AreaStatus string `json:"area_status" description:"多地区[开启,关闭]"`
UseTimes int64 `json:"use_times" description:"使用次数"`
UseTimes int `json:"use_times" description:"使用次数"`
PrizeNum int `json:"prize_num" xorm:"-" description:"奖品总数"`
IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`
@ -25,14 +26,14 @@ func (t *LotteryDrawRule) TableName() string {
return LotteryDrawRuleTableName
}
func GetLDRuleIdsByLDActivityId(ids []int64) ([]int64, error) {
ruleIds := make([]int64, 0)
func GetLDRuleIdsByLDActivityId(ids []int) ([]int, error) {
ruleIds := make([]int, 0)
err := core.GetXormAuto().Table(new(LotteryDrawRule)).Select("id").
Where("is_delete=0").In("lottery_draw_activity_id", ids).Find(&ruleIds)
return ruleIds, err
}
//func UpdateLDRuleStatusByLDActiviytIds(ids []int64) (int64, error) {
//func UpdateLDRuleStatusByLDActiviytIds(ids []int) (int, error) {
// return core.GetXormAuto().Where("is_delete=0").In("lottery_draw_activity_id", ids).
// Update(&LotteryDrawRule{LotteryDrawStatus: define.StatusNotBegin})
//}

11
models/lottery_draw_rule_ladder.go

@ -1,17 +1,18 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/utils/define"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
const LotteryDrawRuleLadderTableName = TableNamePrefix + "lottery_draw_rule_ladder"
//抽奖活动规则阶梯
type LotteryDrawRuleLadder struct {
Id int64 `json:"id"`
LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" description:"红包轮次的id"`
Id int `json:"id" xorm:"autoincr pk not null INT(11)"`
LotteryDrawRuleId int `json:"lottery_draw_rule_id" description:"红包轮次的id"`
RollNum int `json:"roll_num" xorm:"not null default 0 comment('滚动次数') INT(11)"`
PrizeName string `json:"prize_name" description:"奖品名字"`
PrizeNumber int `json:"prize_number" description:"奖品数量"`
@ -29,10 +30,10 @@ func (t *LotteryDrawRuleLadder) TableName() string {
}
func (t *LotteryDrawRuleLadder) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func UpdateLDLadderStatusByLDRuleIds(ids []int64) (int64, error) {
func UpdateLDLadderStatusByLDRuleIds(ids []int) (int64, error) {
return core.GetXormAuto().Where("is_delete=0").
In("lottery_draw_rule_id", ids).
Update(&LotteryDrawRuleLadder{Status: define.StatusNotBegin})

4
models/lottery_draw_wallet_history.go

@ -6,8 +6,8 @@ import (
//抽奖活动钱包历史
type LotteryDrawWalletHistory struct {
Id int64 `json:"id"`
CustomerId int64 `json:"customer_id" description:"客户id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CustomerId int `json:"customer_id" description:"客户id"`
Money float64 `json:"money" description:"金额[分正负]"`
Mark string `json:"mark" description:"备注"`
IsDelete bool `json:"is_delete" xorm:"default(0)"`

8
models/lottery_draw_winner.go

@ -2,11 +2,11 @@ package models
//抽奖的中奖名单
//type LotteryDrawWinner struct {
// Id int64 `json:"id"`
// LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" description:"红包轮次的id"`
// LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" description:"抽奖奖品的id"`
// Id int `json:"id"`
// LotteryDrawRuleId int `json:"lottery_draw_rule_id" description:"红包轮次的id"`
// LotteryDrawRuleLadderId int `json:"lottery_draw_rule_ladder_id" description:"抽奖奖品的id"`
// LotteryDrawRuleLadder *LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-" description:"奖品得信息"`
// UserId int64 `json:"user_id" description:"用户表得id"`
// UserId int `json:"user_id" description:"用户表得id"`
// User *User `json:"user" xorm:"-" description:"用户信息"`
// IsDelete bool `json:"is_delete" xorm:"default(0)"`
// CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`

2
models/module_service.go

@ -8,7 +8,7 @@ import (
//模块服务表
type ModuleService struct {
Id int64 `json:"id"`
Id int `json:"id" xorm:"not null autoincr pk INT(11)"`
Name string `json:"name" description:"模块的名称"`
Price float64 `json:"price" description:"模块价格"`
Free string `json:"free" description:"模块是否收费[收费|免费]"`

16
models/module_service_history.go

@ -9,8 +9,8 @@ import (
const ModuleServiceHistoryTableName = TableNamePrefix + "module_service_history"
type ModuleServiceHistory struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ServiceModuleId int64 `json:"service_module_id" xorm:"not null comment('服务模块的id') INT(11)" description:"服务模块的id"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
ServiceModuleId int `json:"service_module_id" xorm:"not null comment('服务模块的id') INT(11)" description:"服务模块的id"`
Name string `json:"name" xorm:"not null comment('模块名字') VARCHAR(255)" description:"模块的名称"`
Price float64 `json:"price" xorm:"not null default(0.0) comment('模块价格') DECIMAL(10) " description:"模块价格"`
Free string `json:"free" xorm:"not null comment('模块是否收费[收费|免费]') VARCHAR(255)" description:"模块是否收费[收费|免费]"`
@ -26,19 +26,19 @@ func (t *ModuleServiceHistory) TableName() string {
}
func (t *ModuleServiceHistory) Alias(name string) string {
return AliasTableName(t, name)
return Alias(t, name)
}
func (t *ModuleServiceHistory) GetByModuleIdAndName(id int64, name string) (bool, error) {
func (t *ModuleServiceHistory) GetByModuleIdAndName(id int, name string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and service_module_id=? and name=?", id, name).Get(t)
}
func (t *ModuleServiceHistory) ExistSignModule(ids []interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and name=?", "签到").In("id", ids...).Exist(t)
func (t *ModuleServiceHistory) ExistSignModule(ids interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and name=?", "签到").In("id", ids).Exist(t)
}
func GetModuleServiceHistoryIdsByIdAndName(serviceId, serviceName interface{}) ([]int64, error) {
historyIds := make([]int64, 0)
func GetModuleServiceHistoryIdsByIdAndName(serviceId, serviceName interface{}) ([]int, error) {
historyIds := make([]int, 0)
err := core.GetXormAuto().Table(new(ModuleServiceHistory)).Select("id").
Where("is_delete=0 and service_module_id=? and name=?", serviceId, serviceName).Find(&historyIds)
return historyIds, err

4
models/module_style.go

@ -6,8 +6,8 @@ import (
//模块样式表
type ModuleStyle struct {
Id int64 `json:"id"`
ModuleServiceId int64 `json:"module_service_id" description:"服务模块的id"`
Id int `json:"id" xorm:"not null autoincr pk INT(11)"`
ModuleServiceId int `json:"module_service_id" description:"服务模块的id"`
StyleName string `json:"style_name" description:"样式名字"`
StyleImage string `json:"style_image" description:"样式图片"`
IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否已删除"`

6
models/msg_wall_server.go

@ -7,8 +7,8 @@ import (
)
type MsgWallServer struct {
Id int64 `json:"id" xorm:"pk autoincr"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"`
Id int `json:"id" xorm:"pk autoincr"`
ActivityId int `json:"activity_id" xorm:"not null comment('主活动id')"`
MsgWallBgUrl string `json:"msg_wall_bg_url" xorm:"not null comment('消息墙背景url')"`
MsgWallBgStatus string `json:"msg_wall_bg_status" xorm:"not null default('关闭') comment('自定义消息墙背景开关[开启|关闭]')"`
UpWallStatus string `json:"up_wall_status" xorm:"not null default('关闭') comment('消息上墙开关[开启|关闭]')"`
@ -18,6 +18,6 @@ type MsgWallServer struct {
UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新')"`
}
func (t *MsgWallServer) GetByActivityId(aid int64) (bool, error) {
func (t *MsgWallServer) GetByActivityId(aid int) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t)
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save