切换导航条
此项目
正在载入...
登录
景龙
/
xingqiu
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
景龙
6 years ago
提交
ea7e8235a172447eb699fba3e3ee09891ac2c8ce
1 个父辈
df7a8e3a
1 个管道 的构建
通过
耗费 1 秒
增加收藏点赞功能
变更
6
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
209 行增加
和
8 行删除
app/portal/controller/StarController.php
app/portal/model/CollectionModel.php
app/portal/model/LikeModel.php
public/themes/simpleboot3/public/assets/js/public.js
public/themes/simpleboot3/public/slide.html
simplewind/cmf/controller/HomeBaseController.php
app/portal/controller/StarController.php
查看文件 @
ea7e823
...
...
@@ -15,6 +15,8 @@ use cmf\controller\HomeBaseController;
use
app\portal\model\CityCategoryModel
;
use
app\portal\validate\CommentValidate
;
use
app\portal\model\PortalPostModel
;
use
app\portal\model\CollectionModel
;
use
app\portal\model\LikeModel
;
use
think\Db
;
//星球奇境
class
StarController
extends
HomeBaseController
...
...
@@ -360,4 +362,90 @@ class StarController extends HomeBaseController
}
}
//收藏
public
function
collection
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'article_id'
);
//文章id
if
(
$login
){
$data
[
'uid'
]
=
cmf_get_current_user_id
();
$data
[
'post_id'
]
=
$article_id
;
$data
[
'create_time'
]
=
time
();
$data
[
'update_time'
]
=
time
();
$collectionModel
=
new
CollectionModel
();
$res
=
$collectionModel
->
allowField
(
true
)
->
save
(
$data
);
$contentModel
=
new
PortalPostModel
();
$contentModel
->
where
(
'id'
,
$article_id
)
->
setInc
(
'post_favorites'
,
1
);
if
(
$res
){
$this
->
apiResponse
(
1
,
'收藏成功!'
);
}
else
{
$this
->
apiResponse
(
0
,
'收藏失败!'
);
}
}
else
{
$this
->
apiResponse
(
0
,
'请登录后操作!'
);
}
}
//取消收藏
public
function
cancelCollection
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'article_id'
);
//文章id
if
(
$login
){
$uid
=
cmf_get_current_user_id
();
$collectionModel
=
new
CollectionModel
();
$res
=
$collectionModel
->
where
([
'uid'
=>
$uid
,
'post_id'
=>
$article_id
])
->
delete
();
$contentModel
=
new
PortalPostModel
();
$contentModel
->
where
(
'id'
,
$article_id
)
->
setDec
(
'post_favorites'
,
1
);
if
(
$res
){
$this
->
apiResponse
(
1
,
'已取消!'
);
}
else
{
$this
->
apiResponse
(
0
,
'取消失败!'
);
}
}
else
{
$this
->
apiResponse
(
0
,
'请登录后操作!'
);
}
}
//点赞
public
function
like
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'article_id'
);
//文章id
if
(
$login
){
$data
[
'uid'
]
=
cmf_get_current_user_id
();
$data
[
'post_id'
]
=
$article_id
;
$data
[
'create_time'
]
=
time
();
$data
[
'update_time'
]
=
time
();
$likeModel
=
new
LikeModel
();
$res
=
$likeModel
->
allowField
(
true
)
->
save
(
$data
);
if
(
$res
){
$this
->
apiResponse
(
1
,
'点赞成功!'
);
}
else
{
$this
->
apiResponse
(
0
,
'点赞失败!'
);
}
}
else
{
$this
->
apiResponse
(
0
,
'请登录后操作!'
);
}
}
//取消点赞
public
function
cancelLike
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'article_id'
);
//文章id
if
(
$login
){
$uid
=
cmf_get_current_user_id
();
$likeModel
=
new
LikeModel
();
$res
=
$likeModel
->
where
([
'uid'
=>
$uid
,
'post_id'
=>
$article_id
])
->
delete
();
if
(
$res
){
$this
->
apiResponse
(
1
,
'已取消!'
);
}
else
{
$this
->
apiResponse
(
0
,
'取消失败!'
);
}
}
else
{
$this
->
apiResponse
(
0
,
'请登录后操作!'
);
}
}
}
...
...
app/portal/model/CollectionModel.php
0 → 100644
查看文件 @
ea7e823
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace
app\portal\model
;
use
think\Model
;
class
CollectionModel
extends
Model
{
}
\ No newline at end of file
...
...
app/portal/model/LikeModel.php
0 → 100644
查看文件 @
ea7e823
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace
app\portal\model
;
use
think\Model
;
class
LikeModel
extends
Model
{
}
\ No newline at end of file
...
...
public/themes/simpleboot3/public/assets/js/public.js
查看文件 @
ea7e823
$
(
function
(){
var
host
=
'http://'
+
window
.
location
.
host
;
// 点击收藏与爱心
$
(
'.collections'
).
click
(
function
()
{
// 点赞
$
(
'.likes'
).
click
(
function
()
{
if
(
$
(
this
).
children
(
'img'
).
attr
(
'src'
)
==
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_02.png'
)
{
operation
(
'/portal/star/like'
);
$
(
this
).
children
(
'img'
).
attr
(
'src'
,
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_15.png'
);
}
else
{
operation
(
'/portal/star/cancelLike'
);
$
(
this
).
children
(
'img'
).
attr
(
'src'
,
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_02.png'
);
}
});
$
(
'.likes'
).
click
(
function
()
{
//收藏
$
(
'.collections'
).
click
(
function
()
{
if
(
$
(
this
).
children
(
'img'
).
attr
(
'src'
)
==
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_03.png'
)
{
operation
(
'/portal/star/collection'
);
$
(
this
).
children
(
'img'
).
attr
(
'src'
,
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_16.png'
);
}
else
{
operation
(
'/portal/star/cancelCollection'
);
$
(
this
).
children
(
'img'
).
attr
(
'src'
,
host
+
'/themes/simpleboot3/public/assets/starImg/bicon_03.png'
);
}
});
...
...
@@ -112,6 +117,25 @@ $(function(){
});
});
//点赞收藏
function
operation
(
url
){
var
article_id
=
getUrlParam
(
'id'
);
$
.
ajax
({
type
:
'POST'
,
url
:
url
,
data
:
{
'article_id'
:
article_id
,
},
dataType
:
'json'
,
success
:
function
(
data
)
{
if
(
data
.
code
==
1
)
{
mask
(
data
.
msg
);
}
else
{
mask
(
data
.
msg
);
}
}
});
}
//弹框
function
mask
(
msg
)
{
$
(
'.mask'
).
text
(
msg
);
...
...
public/themes/simpleboot3/public/slide.html
查看文件 @
ea7e823
<div
class=
"sidebar"
>
<!-- 点赞 -->
<div
class=
"likes"
>
<notempty
name=
"is_like"
>
<img
src=
"__TMPL__/public/assets/starImg/bicon_15.png"
alt=
""
>
<else/>
<img
src=
"__TMPL__/public/assets/starImg/bicon_02.png"
alt=
""
>
</notempty>
</div>
<!-- 收藏 -->
<div
class=
"collections"
>
<img
src=
"__TMPL__/public/assets/starImg/bicon_02.png"
alt=
""
>
</div>
<!-- 喜欢 -->
<div
class=
"likes"
>
<img
src=
"__TMPL__/public/assets/starImg/bicon_03.png"
alt=
""
>
<notempty
name=
"is_collection"
>
<img
src=
"__TMPL__/public/assets/starImg/bicon_16.png"
alt=
""
>
<else/>
<img
src=
"__TMPL__/public/assets/starImg/bicon_03.png"
alt=
""
>
</notempty>
</div>
<!-- wx分享 -->
<div
class=
"wx_go"
>
...
...
simplewind/cmf/controller/HomeBaseController.php
查看文件 @
ea7e823
...
...
@@ -13,6 +13,8 @@ namespace cmf\controller;
use
think\Db
;
use
app\admin\model\ThemeModel
;
use
think\View
;
use
app\portal\model\CollectionModel
;
use
app\portal\model\LikeModel
;
use
think\Session
;
class
HomeBaseController
extends
BaseController
...
...
@@ -30,6 +32,8 @@ class HomeBaseController extends BaseController
$this
->
getFooter
();
$this
->
getHeader
();
$this
->
getComment
();
$this
->
is_collection
();
$this
->
is_like
();
}
protected
function
_initializeView
()
...
...
@@ -341,4 +345,42 @@ hello;
$this
->
assign
(
'comment'
,
$comment
);
}
//是否收藏
public
function
is_collection
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'id'
);
//文章id
if
(
$login
){
$uid
=
cmf_get_current_user_id
();
$collectionModel
=
new
CollectionModel
();
$res
=
$collectionModel
->
where
([
'uid'
=>
$uid
,
'post_id'
=>
$article_id
])
->
find
();
if
(
$res
){
$this
->
assign
(
'is_collection'
,
1
);
}
else
{
$this
->
assign
(
'is_collection'
,
0
);
}
}
else
{
$this
->
assign
(
'is_collection'
,
0
);
}
}
//是否点赞
public
function
is_like
(){
//判断是否登录
$login
=
cmf_is_user_login
();
$article_id
=
$this
->
request
->
param
(
'id'
);
//文章id
if
(
$login
){
$uid
=
cmf_get_current_user_id
();
$likeModel
=
new
LikeModel
();
$res
=
$likeModel
->
where
([
'uid'
=>
$uid
,
'post_id'
=>
$article_id
])
->
find
();
if
(
$res
){
$this
->
assign
(
'is_like'
,
1
);
}
else
{
$this
->
assign
(
'is_like'
,
0
);
}
}
else
{
$this
->
assign
(
'is_like'
,
0
);
}
}
}
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论