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
60d38060
Commit
60d38060
authored
Mar 26, 2020
by
冷斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
动态
parent
ca8a5fe8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
257 additions
and
0 deletions
+257
-0
api/Appapi/Api/Home.php
+0
-0
api/Appapi/Domain/Home.php
+54
-0
api/Appapi/Model/Home.php
+203
-0
No files found.
api/Appapi/Api/Home.php
View file @
60d38060
This diff is collapsed.
Click to expand it.
api/Appapi/Domain/Home.php
View file @
60d38060
...
...
@@ -173,4 +173,58 @@ class Domain_Home {
return
$rs
;
}
// 动态
public
function
dynamic
(
$type
,
$uid
,
$p
,
$lng
,
$lat
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
dynamic
(
$type
,
$uid
,
$p
,
$lng
,
$lat
);
return
$rs
;
}
// 发布动态
public
function
publishDynamic
(
$params
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
publishDynamic
(
$params
);
return
$rs
;
}
// 删除
public
function
deleteDynamic
(
$id
,
$uid
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
deleteDynamic
(
$id
,
$uid
);
return
$rs
;
}
// 举报
public
function
reportDynamic
(
$params
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
reportDynamic
(
$params
);
return
$rs
;
}
// 点赞
public
function
zanDynamic
(
$id
,
$uid
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
zanDynamic
(
$id
,
$uid
);
return
$rs
;
}
public
function
commentDynamic
(
$params
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
commentDynamic
(
$params
);
return
$rs
;
}
public
function
deleteCommentDynamic
(
$id
,
$uid
)
{
$model
=
new
Model_Home
();
$rs
=
$model
->
deleteCommentDynamic
(
$id
,
$uid
);
return
$rs
;
}
}
api/Appapi/Model/Home.php
View file @
60d38060
...
...
@@ -1284,4 +1284,207 @@ class Model_Home extends PhalApi_Model_NotORM {
return
!
empty
(
$result
)
?
$result
[
0
]
:
[];
}
/**
* 人性化时间显示
*
* @param int $time
*
* @return false|string
*/
public
function
formatTime
(
$time
)
{
$rtime
=
date
(
"Y-m-d H:i:s"
,
$time
);
$time
=
time
()
-
$time
;
if
(
$time
<
60
)
{
$str
=
'刚刚'
;
}
elseif
(
$time
<
60
*
60
)
{
$min
=
floor
(
$time
/
60
);
$str
=
$min
.
'分钟前'
;
}
elseif
(
$time
<
60
*
60
*
24
)
{
$h
=
floor
(
$time
/
(
60
*
60
));
$str
=
$h
.
'小时前 '
;
// } elseif ($time < 60 * 60 * 24 * 3) {
//// $d = floor($time / (60 * 60 * 24));
//// if ($d == 1) {
//// $str = '昨天 ' . $rtime;
//// } else {
//// $str = '前天 ' . $rtime;
//// }
// $str = $rtime;
}
else
{
$d
=
floor
(
$time
/
(
60
*
60
*
24
));
$str
=
$d
.
'天前 '
;
}
return
$str
;
}
/**
* lbs 2点计算距离
*
* @param float $lat 纬度
* @param float $lng 经度
* @param string $latName
* @param string $lngName
*
* @return string
*/
public
function
distanceSql
(
$lat
,
$lng
,
$latName
=
'lat'
,
$lngName
=
'lng'
)
{
$sql
=
"(2 * 6371.393 * ASIN(SQRT(COS( 23.99 * PI( ) / 180 ) * COS( 23.99 * PI( ) / 180 ) * POW( SIN( (
{
$lng
}
-
{
$lngName
}
) * PI( ) / 360 ), 2 ) + POW( SIN( (
{
$lat
}
-
{
$latName
}
) * PI( ) / 360 ), 2 )) ) * 1000 ) "
;
return
$sql
;
}
// 动态
public
function
dynamic
(
$type
,
$uid
,
$p
,
$lng
,
$lat
)
{
if
(
$p
<
1
){
$p
=
1
;
}
$pnum
=
50
;
$start
=
(
$p
-
1
)
*
$pnum
;
$where
=
'1=1 '
;
if
(
$type
)
{
$where
.=
' and uid = '
.
$type
;
}
$select
=
'*'
;
if
(
!
empty
(
$lng
)
&&
!
empty
(
$lat
))
{
$select
.=
", (
{
$this
->
distanceSql
(
$lat
,
$lng
)
}
) as distance"
;
$orderBy
=
'distance desc'
;
}
else
{
$orderBy
=
'addtime desc'
;
}
$results
=
DI
()
->
notorm
->
dynamic
->
select
(
$select
)
->
where
(
$where
)
->
order
(
$orderBy
)
->
limit
(
$start
,
$pnum
)
->
fetchAll
();
foreach
(
$results
as
$key
=>
$v
)
{
$userinfo
=
getUserInfo
(
$v
[
'uid'
]);
$results
[
$key
][
'avatar'
]
=
$userinfo
[
'avatar'
];
$results
[
$key
][
'avatar_thumb'
]
=
$userinfo
[
'avatar_thumb'
];
$results
[
$key
][
'user_nicename'
]
=
$userinfo
[
'user_nicename'
];
$results
[
$key
][
'image'
]
=
explode
(
'|'
,
$v
[
'image'
]);
$results
[
$key
][
'time'
]
=
$v
[
'addtime'
];
$results
[
$key
][
'addtime'
]
=
$this
->
formatTime
(
$v
[
'addtime'
]);
$zan
=
[];
if
(
$uid
>
0
)
{
$zan
=
DI
()
->
notorm
->
users_dynamic
->
where
(
'dynamic_id = ? and uid = ?'
,
$v
[
'id'
],
$uid
)
->
fetchAll
();
}
$results
[
$key
][
'is_zan'
]
=
!
empty
(
$zan
)
?
1
:
0
;
$zan2
=
DI
()
->
notorm
->
users_dynamic
->
where
(
'dynamic_id = ?'
,
$v
[
'id'
])
->
fetchAll
();
$results
[
$key
][
'zan'
]
=
count
(
$zan2
);
}
return
[
'list'
=>
$results
,
'count'
=>
DI
()
->
notorm
->
dynamic
->
where
(
$where
)
->
count
(),
];
}
// 发布动态
public
function
publishDynamic
(
$params
)
{
$auth
=
DI
()
->
notorm
->
users_auth
->
where
(
"uid=?"
,
$params
[
'uid'
])
->
fetchOne
();
if
(
!
empty
(
$auth
)
&&
$auth
[
'status'
]
==
1
)
{
DI
()
->
notorm
->
dynamic
->
insert
(
$params
);
}
else
{
return
1
;
}
return
0
;
}
// 删除
public
function
deleteDynamic
(
$id
,
$uid
)
{
$model
=
DI
()
->
notorm
->
dynamic
->
where
(
'id = ? and uid = ?'
,
$id
,
$uid
);
$zan
=
$model
->
fetchOne
();
if
(
!
empty
(
$zan
))
{
$model
->
delete
();
}
else
{
return
1
;
}
return
0
;
}
// 举报
public
function
reportDynamic
(
$params
)
{
$model
=
DI
()
->
notorm
->
users_report_dynamic
->
where
(
'dynamic_id = ? and uid = ?'
,
$params
[
'dynamic_id'
],
$params
[
'uid'
])
->
fetchOne
();
if
(
!
empty
(
$model
))
{
return
1
;
}
DI
()
->
notorm
->
users_report_dynamic
->
insert
(
$params
);
return
0
;
}
// 点赞
public
function
zanDynamic
(
$id
,
$uid
)
{
$model
=
DI
()
->
notorm
->
users_dynamic
->
where
(
'dynamic_id = ? and uid = ?'
,
$id
,
$uid
);
$zan
=
$model
->
fetchOne
();
if
(
!
empty
(
$zan
))
{
$model
->
delete
();
}
else
{
DI
()
->
notorm
->
users_dynamic
->
insert
([
'dynamic_id'
=>
$id
,
'uid'
=>
$uid
,
]);
}
return
[];
}
// 评论
public
function
commentDynamic
(
$params
)
{
$model
=
DI
()
->
notorm
->
dynamic
->
where
(
'id='
.
$params
[
'dynamic_id'
])
->
fetchOne
();
if
(
empty
(
$model
))
{
return
1
;
}
if
(
$params
[
'pid'
]
>
0
)
{
$model2
=
DI
()
->
notorm
->
users_comment_dynamic
->
where
(
'id='
.
$params
[
'pid'
])
->
fetchOne
();
if
(
empty
(
$model2
))
{
return
2
;
}
$params
[
'puid'
]
=
$model2
[
'uid'
];
}
DI
()
->
notorm
->
users_comment_dynamic
->
insert
(
$params
);
return
0
;
}
// 评论 删除
public
function
deleteCommentDynamic
(
$id
,
$uid
)
{
$model
=
DI
()
->
notorm
->
users_comment_dynamic
->
where
(
'id = ? and uid = ?'
,
$id
,
$uid
);
$zan
=
$model
->
fetchOne
();
if
(
!
empty
(
$zan
))
{
DI
()
->
notorm
->
users_comment_dynamic
->
where
(
"pid=
{
$id
}
"
)
->
delete
();
$model
->
delete
();
}
else
{
return
1
;
}
return
0
;
}
}
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