Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
930f6fd7
Commit
930f6fd7
authored
Oct 09, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
编写部分接口
parent
08a28d97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
1 deletion
+98
-1
Support.php
src/common/models/Support.php
+33
-1
HomeController.php
src/frontend/controllers/HomeController.php
+65
-0
No files found.
src/common/models/Support.php
View file @
930f6fd7
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
namespace
common\models
;
namespace
common\models
;
use
Yii
;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
yii\redis\ActiveRecord
;
/**
/**
* This is the model class for table "support".
* This is the model class for table "support".
...
@@ -22,13 +24,30 @@ class Support extends \yii\db\ActiveRecord
...
@@ -22,13 +24,30 @@ class Support extends \yii\db\ActiveRecord
return
'support'
;
return
'support'
;
}
}
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
[
'class'
=>
TimestampBehavior
::
className
(),
'attributes'
=>
[
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
[
'created_at'
],
],
// if you're using datetime instead of UNIX timestamp:
// 'value' => new Expression('NOW()'),
],];
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'user_id'
,
'courseware_id'
,
'created_at'
],
'required'
],
[[
'user_id'
,
'courseware_id'
,],
'required'
],
[[
'user_id'
,
'courseware_id'
,
'created_at'
],
'integer'
],
[[
'user_id'
,
'courseware_id'
,
'created_at'
],
'integer'
],
];
];
}
}
...
@@ -45,4 +64,17 @@ class Support extends \yii\db\ActiveRecord
...
@@ -45,4 +64,17 @@ class Support extends \yii\db\ActiveRecord
'created_at'
=>
'Created At'
,
'created_at'
=>
'Created At'
,
];
];
}
}
/**
* 获取该课程是否点赞
* @param $userId
* @param $coursewareId
* @return mixed
*/
public
static
function
findByUserIdAndCoursewareId
(
$userId
,
$coursewareId
)
{
return
self
::
find
()
->
select
(
'id,user_id,courseware_id,created_at'
)
->
where
(
"user_id=:user_id and courseware_id=:courseware_id"
,
[
'user_id'
=>
$userId
,
'courseware_id'
=>
$coursewareId
])
->
asArray
()
->
one
();
}
}
}
src/frontend/controllers/HomeController.php
View file @
930f6fd7
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
namespace
frontend\controllers
;
namespace
frontend\controllers
;
use
common\models\Support
;
use
Yii
;
use
common\libs\Utils
;
class
HomeController
extends
\yii\web\Controller
class
HomeController
extends
\yii\web\Controller
{
{
public
function
actionIndex
()
public
function
actionIndex
()
...
@@ -9,4 +13,65 @@ class HomeController extends \yii\web\Controller
...
@@ -9,4 +13,65 @@ class HomeController extends \yii\web\Controller
return
$this
->
render
(
'index'
);
return
$this
->
render
(
'index'
);
}
}
/**
* 点赞或者取消点赞
* @param $coursewareId
* @throws \yii\web\ForbiddenHttpException
*/
public
function
actionSupport
(
$coursewareId
)
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
$support
=
Support
::
findByUserIdAndCoursewareId
(
$userId
,
$coursewareId
);
//没有点赞则点赞否则则取消点赞
if
(
count
(
$support
)
===
0
)
{
$support
=
new
Support
();
$support
->
user_id
=
$userId
;
$support
->
courseware_id
=
$coursewareId
;
$support
->
save
();
}
else
{
Support
::
deleteAll
(
'id=:id'
,
[
'id'
=>
$support
[
'id'
]]);
}
Utils
::
ajaxResponse
(
TRUE
);
}
else
{
throw
new
\yii\web\ForbiddenHttpException
(
'非法请求'
);
}
}
/**
* 收藏
* @param $courseId
* @throws \yii\web\ForbiddenHttpException
*/
public
function
actionFavorite
(
$courseId
)
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
Utils
::
ajaxResponse
(
TRUE
,
$courseId
,
$userId
);
}
else
{
throw
new
\yii\web\ForbiddenHttpException
(
'非法请求'
);
}
}
/**
* 评论
* @throws \yii\web\ForbiddenHttpException
*/
public
function
actionComments
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
Utils
::
ajaxResponse
(
TRUE
,
''
,
$userId
);
}
else
{
throw
new
\yii\web\ForbiddenHttpException
(
'非法请求'
);
}
}
}
}
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