Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
quxiu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冷斌
quxiu
Commits
00c206cf
Commit
00c206cf
authored
May 22, 2020
by
冷斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
d43a7c73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
49 deletions
+50
-49
api/Appapi/Model/Guard.php
+50
-49
No files found.
api/Appapi/Model/Guard.php
View file @
00c206cf
...
...
@@ -3,20 +3,20 @@
class
Model_Guard
extends
PhalApi_Model_NotORM
{
/* 守护用户列表 */
public
function
getGuardList
(
$data
)
{
$rs
=
array
();
$liveuid
=
$data
[
'liveuid'
];
$nowtime
=
time
();
$w
=
date
(
'w'
,
$nowtime
);
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$w
=
date
(
'w'
,
$nowtime
);
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$first
=
1
;
//周一
$week
=
date
(
'Y-m-d H:i:s'
,
strtotime
(
date
(
"Ymd"
,
$nowtime
)
.
"-"
.
(
$w
?
$w
-
$first
:
6
)
.
' days'
));
$week_start
=
strtotime
(
date
(
"Ymd"
,
$nowtime
)
.
"-"
.
(
$w
?
$w
-
$first
:
6
)
.
' days'
);
$week
=
date
(
'Y-m-d H:i:s'
,
strtotime
(
date
(
"Ymd"
,
$nowtime
)
.
"-"
.
(
$w
?
$w
-
$first
:
6
)
.
' days'
));
$week_start
=
strtotime
(
date
(
"Ymd"
,
$nowtime
)
.
"-"
.
(
$w
?
$w
-
$first
:
6
)
.
' days'
);
//本周结束日期
//本周结束日期
//周天
$week_end
=
strtotime
(
"
{
$week
}
+1 week"
);
...
...
@@ -29,22 +29,22 @@ class Model_Guard extends PhalApi_Model_NotORM {
->
fetchAll
();
foreach
(
$list
as
$k
=>
$v
){
$userinfo
=
getUserInfo
(
$v
[
'uid'
]);
$userinfo
[
'type'
]
=
$v
[
'type'
];
$userinfo
[
'contribute'
]
=
$this
->
getWeekContribute
(
$v
[
'uid'
],
$week_start
,
$week_end
);
$order
[]
=
$userinfo
[
'contribute'
];
$order2
[]
=
$userinfo
[
'type'
];
$rs
[]
=
$userinfo
;
}
array_multisort
(
$order
,
SORT_DESC
,
$order2
,
SORT_DESC
,
$rs
);
return
$rs
;
}
}
public
function
getWeekContribute
(
$uid
,
$starttime
=
0
,
$endtime
=
0
){
$contribute
=
'0'
;
if
(
$uid
>
0
){
...
...
@@ -55,7 +55,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
if
(
$endtime
>
0
){
$where
.=
" and addtime <
{
$endtime
}
"
;
}
$contribute
=
DI
()
->
notorm
->
users_coinrecord
->
where
(
$where
)
->
sum
(
'totalcoin'
);
...
...
@@ -63,7 +63,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$contribute
=
0
;
}
}
return
(
string
)
$contribute
;
}
...
...
@@ -76,7 +76,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
return
$list
;
}
/* 购买守护 */
public
function
buyGuard
(
$data
){
$rs
=
array
(
'code'
=>
0
,
'msg'
=>
'购买成功'
,
'info'
=>
array
());
...
...
@@ -84,7 +84,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$liveuid
=
$data
[
'liveuid'
];
$stream
=
$data
[
'stream'
];
$guardid
=
$data
[
'guardid'
];
$guardinfo
=
DI
()
->
notorm
->
guard
->
select
(
'*'
)
->
where
(
'id=?'
,
$guardid
)
...
...
@@ -94,7 +94,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs
[
'msg'
]
=
'守护信息不存在'
;
return
$rs
;
}
$addtime
=
time
();
$isexist
=
DI
()
->
notorm
->
guard_users
->
select
(
'*'
)
...
...
@@ -104,13 +104,13 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs
[
'code'
]
=
1004
;
$rs
[
'msg'
]
=
'已经是尊贵守护了,不能购买普通守护'
;
return
$rs
;
}
}
$type
=
'expend'
;
$action
=
'buyguard'
;
$giftid
=
$guardinfo
[
'id'
];
$total
=
$guardinfo
[
'coin'
];
/* 更新用户余额 消费 */
$isok
=
DI
()
->
notorm
->
users
->
where
(
'id = ? and coin>=?'
,
$uid
,
$total
)
...
...
@@ -120,16 +120,16 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs
[
'msg'
]
=
'余额不足'
;
return
$rs
;
}
/* 分销 */
/* 分销 */
setAgentProfit
(
$uid
,
$total
);
DI
()
->
notorm
->
users
->
where
(
'id = ?'
,
$liveuid
)
->
update
(
array
(
'votes'
=>
new
NotORM_Literal
(
"votes +
{
$total
}
"
),
'votestotal'
=>
new
NotORM_Literal
(
"votestotal +
{
$total
}
"
)
));
$insert_votes
=
[
'type'
=>
'income'
,
'action'
=>
$action
,
...
...
@@ -138,7 +138,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
'addtime'
=>
$addtime
,
];
DI
()
->
notorm
->
users_voterecord
->
insert
(
$insert_votes
);
$showid
=
0
;
if
(
$stream
){
$stream2
=
explode
(
'_'
,
$stream
);
...
...
@@ -147,13 +147,14 @@ class Model_Guard extends PhalApi_Model_NotORM {
$showid
=
0
;
}
}
$total
=
$total
*
0.7
;
$insert
=
array
(
"type"
=>
$type
,
"action"
=>
$action
,
"uid"
=>
$uid
,
"touid"
=>
$liveuid
,
"giftid"
=>
$giftid
,
"giftcount"
=>
'1'
,
"totalcoin"
=>
$total
,
"showid"
=>
$showid
,
"addtime"
=>
$addtime
);
DI
()
->
notorm
->
users_coinrecord
->
insert
(
$insert
);
$endtime
=
$addtime
+
$guardinfo
[
'length_time'
];
if
(
$isexist
){
if
(
$isexist
[
'type'
]
==
$guardinfo
[
'type'
]
&&
$isexist
[
'endtime'
]
>
$addtime
){
/* 同类型未到期 只更新到期时间 */
DI
()
->
notorm
->
guard_users
...
...
@@ -180,34 +181,34 @@ class Model_Guard extends PhalApi_Model_NotORM {
);
DI
()
->
notorm
->
guard_users
->
insert
(
$data
);
}
/* 清除缓存 */
delCache
(
"userinfo_"
.
$uid
);
delCache
(
"userinfo_"
.
$liveuid
);
$userinfo2
=
DI
()
->
notorm
->
users
->
select
(
'consumption,coin'
)
->
where
(
'id = ?'
,
$uid
)
->
fetchOne
();
$level
=
getLevel
(
$userinfo2
[
'consumption'
]);
$guard
=
DI
()
->
notorm
->
guard_users
->
select
(
'type,endtime'
)
->
where
(
'uid = ? and liveuid=?'
,
$uid
,
$liveuid
)
->
fetchOne
();
$key
=
'getUserGuard_'
.
$uid
.
'_'
.
$liveuid
;
setcaches
(
$key
,
$guard
);
$liveuidinfo
=
DI
()
->
notorm
->
users
->
select
(
'votestotal'
)
->
where
(
'id = ?'
,
$liveuid
)
->
fetchOne
();
$guard_nums
=
$this
->
getGuardNums
(
$liveuid
);
$info
=
array
(
'coin'
=>
$userinfo2
[
'coin'
],
'votestotal'
=>
$liveuidinfo
[
'votestotal'
],
...
...
@@ -217,12 +218,12 @@ class Model_Guard extends PhalApi_Model_NotORM {
'type'
=>
$guard
[
'type'
],
'endtime'
=>
date
(
"Y.m.d"
,
$guard
[
'endtime'
]),
);
$rs
[
'info'
][
0
]
=
$info
;
return
$rs
;
}
/* 获取用户守护信息 */
public
function
getUserGuard
(
$uid
,
$liveuid
){
$rs
=
array
(
...
...
@@ -235,11 +236,11 @@ class Model_Guard extends PhalApi_Model_NotORM {
$guardinfo
=
DI
()
->
notorm
->
guard_users
->
select
(
'type,endtime'
)
->
where
(
'uid = ? and liveuid=?'
,
$uid
,
$liveuid
)
->
fetchOne
();
->
fetchOne
();
setcaches
(
$key
,
$guardinfo
);
}
$nowtime
=
time
();
if
(
$guardinfo
&&
$guardinfo
[
'endtime'
]
>
$nowtime
){
$rs
=
array
(
'type'
=>
$guardinfo
[
'type'
],
...
...
@@ -248,15 +249,15 @@ class Model_Guard extends PhalApi_Model_NotORM {
}
return
$rs
;
}
/* 获取主播守护总数 */
public
function
getGuardNums
(
$liveuid
){
$nowtime
=
time
();
$nums
=
DI
()
->
notorm
->
guard_users
->
where
(
'liveuid=? and endtime>?'
,
$liveuid
,
$nowtime
)
->
count
();
->
count
();
return
(
string
)
$nums
;
}
}
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