Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
f0250bec
Commit
f0250bec
authored
Apr 18, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开斋节活动
parent
2aa5cb18
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
47 deletions
+85
-47
act_m.go
internal/model/act_m/act_m.go
+0
-47
activity.go
rpc/activity.go
+85
-0
No files found.
internal/model/act_m/act_m.go
deleted
100644 → 0
View file @
2aa5cb18
package
act_m
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
)
type
ActPoint
struct
{
AcId
uint64
`json:"ac_id"`
UserId
uint64
`json:"user_id"`
Point
uint64
`json:"point"`
}
type
ActPointLog
struct
{
Id
uint64
`json:"id"`
AcId
uint64
`json:"ac_id"`
UserId
uint64
`json:"user_id"`
Point
uint64
`json:"point"`
AddReduce
uint8
`json:"add_reduce"`
// 1.增加2.减少
Remark
string
`json:"remark"`
}
func
(
this
*
ActPoint
)
Add
(
model
*
domain
.
Model
)
error
{
sql
:=
"insert into hilo.act_point (ac_id,user_id,point) "
+
"values(?,?,?) on duplicate key update point = point+values(point);"
return
model
.
DB
()
.
Exec
(
sql
,
this
.
AcId
,
this
.
UserId
,
this
.
Point
)
.
Error
}
func
(
this
*
ActPoint
)
Reduce
(
model
*
domain
.
Model
)
error
{
sql
:=
"update hilo.act_point set point = point - ? where ac_id=? and user_id=? and point >= ?;"
result
:=
model
.
DB
()
.
Exec
(
sql
,
this
.
Point
,
this
.
AcId
,
this
.
UserId
,
this
.
Point
)
if
result
.
Error
!=
nil
{
return
result
.
Error
}
if
result
.
RowsAffected
<=
0
{
return
fmt
.
Errorf
(
"bizerr.TransactionFailed"
)
}
return
nil
}
func
CreateActPointLog
(
model
*
domain
.
Model
,
info
*
ActPointLog
)
error
{
err
:=
model
.
DB
()
.
Create
(
&
info
)
.
Error
if
err
!=
nil
{
return
err
}
return
nil
}
rpc/activity.go
0 → 100644
View file @
f0250bec
package
rpc
import
(
"encoding/json"
"errors"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/consul"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"github.com/hashicorp/consul/api"
"math/rand"
)
const
(
defaultActivityConsulName
=
"hiloActivity"
defaultActivityServerScheme
=
"http"
defaultActivityServerAddr
=
"127.0.0.1:9010"
// 默认内网转发,本地回环
)
var
activityServerHost
=
[]
string
{
defaultActivityServerAddr
}
func
init
()
{
go
func
()
{
address
:=
api
.
DefaultConfig
()
.
Address
// 用consul api的default config
if
err
:=
consul
.
RegisterWatcher
(
"services"
,
nil
,
address
,
func
(
serviceStatus
map
[
string
]
map
[
string
][]
string
)
{
if
statusAddrs
,
ok
:=
serviceStatus
[
defaultActivityConsulName
];
ok
{
healthAddrs
,
_
:=
statusAddrs
[
api
.
HealthPassing
]
l
:=
len
(
healthAddrs
)
if
l
>
0
{
mylogrus
.
MyLog
.
Infof
(
"consul service update state:%v-%v"
,
defaultActivityConsulName
,
healthAddrs
)
activityServerHost
=
healthAddrs
}
else
{
mylogrus
.
MyLog
.
Warnf
(
"consul service update local state:%v-%v"
,
defaultActivityConsulName
,
defaultActivityServerAddr
)
activityServerHost
=
[]
string
{
defaultActivityServerAddr
}
// 有其他问题都用默认的
}
for
status
:=
range
statusAddrs
{
if
status
==
api
.
HealthPassing
{
continue
}
mylogrus
.
MyLog
.
Warnf
(
"consul service wrong state:%v-%v-%v"
,
defaultActivityConsulName
,
status
,
statusAddrs
[
status
])
}
}
});
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"启动 consul 的watch监控失败"
)
}
}()
}
// 活动积分增加 fType: 1.上麦 2.ludo游戏完成 3.slots游戏完成 4.fruit游戏完成 5.特定座驾进入房间
func
AddActPoint
(
model
*
domain
.
Model
,
actId
,
userId
mysql
.
ID
,
fType
mysql
.
Type
)
error
{
defer
utils
.
CheckGoPanic
()
type
Response
struct
{
Code
int
`json:"code"`
Message
string
`json:"message"`
}
_url
:=
fmt
.
Sprintf
(
"%v://%v/inner/act/addPoint"
,
defaultActivityServerScheme
,
getActivityHost
())
resp
,
err
:=
HttpPostForm
(
model
,
_url
,
nil
,
map
[
string
]
string
{
"userId"
:
fmt
.
Sprintf
(
"%d"
,
userId
),
"actId"
:
fmt
.
Sprintf
(
"%d"
,
actId
),
"fType"
:
fmt
.
Sprintf
(
"%d"
,
fType
),
})
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddActPoint fail:%v"
,
err
)
return
err
}
response
:=
new
(
Response
)
if
err
=
json
.
Unmarshal
(
resp
,
response
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddActPoint json fail:%v"
,
err
)
return
err
}
if
response
.
Code
!=
200
{
model
.
Log
.
Errorf
(
"AddActPoint fail:%v"
,
*
response
)
return
errors
.
New
(
response
.
Message
)
}
return
nil
}
func
getActivityHost
()
string
{
l
:=
len
(
activityServerHost
)
r
:=
rand
.
Intn
(
l
)
// 随机一个
mylogrus
.
MyLog
.
Infof
(
"getHostActivity:%v---%v"
,
r
,
activityServerHost
[
r
])
return
activityServerHost
[
r
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment