Commit 6c3b5dca authored by xiabin's avatar xiabin

添加一些时间戳行为

parent 10834f5c
...@@ -77,6 +77,6 @@ class BrowseRecord extends \yii\db\ActiveRecord ...@@ -77,6 +77,6 @@ class BrowseRecord extends \yii\db\ActiveRecord
->select("course_id,time,$tableB.name,$tableB.avatar,$tableB.price,$tableB.free_time,$tableB.intro,$tableB.preview_pic,$tableB.created_at") ->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", [ ->where("$tableA.user_id = :user_id", [
':user_id' => $userId ':user_id' => $userId
])->join('left join', $tableB, "$tableA.user_id=$tableB.id")->asArray()->one(); ])->join('left join', $tableB, "$tableA.user_id=$tableB.id")->asArray()->all();
} }
} }
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/** /**
* This is the model class for table "favorite". * This is the model class for table "favorite".
...@@ -22,13 +24,30 @@ class Favorite extends \yii\db\ActiveRecord ...@@ -22,13 +24,30 @@ class Favorite extends \yii\db\ActiveRecord
return 'favorite'; return 'favorite';
} }
/**
* @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', 'course_id', 'created_at'], 'required'], [['user_id', 'course_id',], 'required'],
[['user_id', 'course_id', 'created_at'], 'integer'], [['user_id', 'course_id', 'created_at'], 'integer'],
]; ];
} }
...@@ -45,4 +64,19 @@ class Favorite extends \yii\db\ActiveRecord ...@@ -45,4 +64,19 @@ class Favorite extends \yii\db\ActiveRecord
'created_at' => 'Created At', 'created_at' => 'Created At',
]; ];
} }
/**
* @param $userId
* @return array|null|ActiveRecord
*/
public static function getByUserId($userId)
{
$tableA = self::tableName();
$tableB = Course::tableName();
return self::find()
->select("course_id,$tableA.created_at as 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()->all();
}
} }
...@@ -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 "income". * This is the model class for table "income".
...@@ -24,13 +26,30 @@ class Income extends \yii\db\ActiveRecord ...@@ -24,13 +26,30 @@ class Income extends \yii\db\ActiveRecord
return 'income'; return 'income';
} }
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_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', 'orders_id', 'created_at', 'updated_at'], 'required'], [['user_id', 'orders_id'], 'required'],
[['user_id', 'orders_id', 'status', 'created_at', 'updated_at'], 'integer'], [['user_id', 'orders_id', 'status', 'created_at', 'updated_at'], 'integer'],
]; ];
} }
......
...@@ -12,6 +12,7 @@ namespace frontend\controllers; ...@@ -12,6 +12,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\BrowseRecord;
use common\models\Favorite;
use common\models\User; use common\models\User;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
...@@ -54,7 +55,6 @@ class UserCenterController extends Controller ...@@ -54,7 +55,6 @@ class UserCenterController extends Controller
*/ */
public function actionInfo() public function actionInfo()
{ {
// echo $th
return $this->render('info'); return $this->render('info');
} }
...@@ -65,7 +65,10 @@ class UserCenterController extends Controller ...@@ -65,7 +65,10 @@ class UserCenterController extends Controller
public function actionFavorite() public function actionFavorite()
{ {
return $this->render('favorite');
$favorite = Favorite::getByUserId(Yii::$app->user->getId());
var_dump($favorite);
// return $this->render('favorite');
} }
public function actionBrowseRecord() public function actionBrowseRecord()
......
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