Commit 10834f5c authored by xiabin's avatar xiabin

添加代码结构假数据

parent 9d4117b2
...@@ -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 "browse_record". * This is the model class for table "browse_record".
...@@ -22,13 +24,29 @@ class BrowseRecord extends \yii\db\ActiveRecord ...@@ -22,13 +24,29 @@ class BrowseRecord extends \yii\db\ActiveRecord
return 'browse_record'; return 'browse_record';
} }
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['time'],
],
// 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', 'course_id', 'time'], 'required'], [['user_id', 'course_id',], 'required'],
[['user_id', 'course_id', 'time'], 'integer'], [['user_id', 'course_id', 'time'], 'integer'],
]; ];
} }
...@@ -45,4 +63,20 @@ class BrowseRecord extends \yii\db\ActiveRecord ...@@ -45,4 +63,20 @@ class BrowseRecord extends \yii\db\ActiveRecord
'time' => 'Time', 'time' => 'Time',
]; ];
} }
/**
* 获取浏览记录
* @param $userId
* @return mixed
*/
public static function getByUserId($userId)
{
$tableA = self::tableName();
$tableB = Course::tableName();
return self::find()
->select("course_id,time,$tableB.name,$tableB.avatar,$tableB.price,$tableB.free_time,$tableB.intro,$tableB.preview_pic,$tableB.created_at")
->where("$tableA.user_id = :user_id", [
':user_id' => $userId
])->join('left join', $tableB, "$tableA.user_id=$tableB.id")->asArray()->one();
}
} }
...@@ -11,6 +11,7 @@ namespace frontend\controllers; ...@@ -11,6 +11,7 @@ namespace frontend\controllers;
use common\libs\Message; use common\libs\Message;
use common\libs\Test; use common\libs\Test;
use common\models\BrowseRecord;
use common\models\User; use common\models\User;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
...@@ -57,9 +58,9 @@ class UserCenterController extends Controller ...@@ -57,9 +58,9 @@ class UserCenterController extends Controller
return $this->render('info'); return $this->render('info');
} }
public function actionCourse() public function actionPurchasedCourse()
{ {
return $this->render('course'); return $this->render('purchased_course');
} }
public function actionFavorite() public function actionFavorite()
...@@ -69,7 +70,9 @@ class UserCenterController extends Controller ...@@ -69,7 +70,9 @@ class UserCenterController extends Controller
public function actionBrowseRecord() public function actionBrowseRecord()
{ {
$browseRecord = BrowseRecord::getByUserId(Yii::$app->user->getId());
var_dump($browseRecord);
return $this->render('browse_record');
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/29
* Time: 上午9:59
*/
\frontend\assets\AppAsset::addScript($this, '@web/assets/user_center_browse_record.js')
?>
<h1>user-center/browse_record</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/27
* Time: 下午4:16
*/
\frontend\assets\AppAsset::addScript($this,'@web/assets/user_favorite.js')
?>
<h1>user-center/favorite</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
\ No newline at end of file
...@@ -5,5 +5,11 @@ ...@@ -5,5 +5,11 @@
* Date: 2016/9/27 * Date: 2016/9/27
* Time: 下午4:16 * Time: 下午4:16
*/ */
\frontend\assets\AppAsset::addScript($this,'@web/assets/user_center_info.js')
?> ?>
info <h1>user-center/info</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/29
* Time: 上午9:59
*/
\frontend\assets\AppAsset::addScript($this, '@web/assets/user_center_purchased_course.js')
?>
<h1>user-center/purchased_course</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
/**
* Created by xiabin on 2016/9/29.
*/
layer.msg('玩命提示中');
/**
* Created by xiabin on 2016/9/29.
*/
layer.msg('玩命提示中');
/**
* Created by xiabin on 2016/9/29.
*/
layer.msg('玩命提示中');
/**
* Created by xiabin on 2016/9/29.
*/
layer.msg('玩命提示中');
...@@ -15,6 +15,10 @@ var entry = { ...@@ -15,6 +15,10 @@ var entry = {
signup: [js_dir + '/site/signup.js'], signup: [js_dir + '/site/signup.js'],
login: [js_dir + '/site/login.js'], login: [js_dir + '/site/login.js'],
request_password_reset: [js_dir + '/site/request_password_reset'], request_password_reset: [js_dir + '/site/request_password_reset'],
user_center_info: [js_dir + '/user-center/info.js'],
user_favorite: [js_dir + '/user-center/favorite.js'],
user_center_browse_record: [js_dir + '/user-center/browse_record.js'],
user_center_purchased_course: [js_dir + '/user-center/purchased_course.js'],
course_publish: [js_dir + '/my-course/publish.js'] course_publish: [js_dir + '/my-course/publish.js']
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment