Reward.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\behaviors\BlameableBehavior;
  5. use yii\behaviors\TimestampBehavior;
  6. use yii\helpers\Html;
  7. /**
  8. * This is the model class for table "pop_reward".
  9. *
  10. * @property integer $id
  11. * @property integer $article_id
  12. * @property integer $user_id
  13. * @property integer $money
  14. * @property string $comment
  15. * @property integer $created_at
  16. * @property integer $updated_at
  17. */
  18. class Reward extends \yii\db\ActiveRecord
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%reward}}';
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['article_id', 'money'], 'required'],
  34. [['article_id', 'money'], 'integer'],
  35. ['comment', 'string', 'max' => 50],
  36. ['money', 'compare', 'operator' => '>', 'compareValue' => 0]
  37. ];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'article_id' => 'Article ID',
  47. 'user_id' => 'User ID',
  48. 'money' => 'Money',
  49. 'created_at' => 'Created At',
  50. 'updated_at' => 'Updated At',
  51. ];
  52. }
  53. public function behaviors()
  54. {
  55. return [
  56. TimestampBehavior::className(),
  57. [
  58. 'class' => BlameableBehavior::className(),
  59. 'createdByAttribute' => 'user_id',
  60. 'updatedByAttribute' => false
  61. ]
  62. ];
  63. }
  64. public function getArticle()
  65. {
  66. return $this->hasOne(Article::className(), ['id' => 'article_id']);
  67. }
  68. }