Announce.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\models;
  3. use app\modules\admin\models\Admin;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%announce}}".
  7. *
  8. * @property int $id ID
  9. * @property string $title 标题
  10. * @property string $content 内容
  11. * @property int $start_time 开始显示时间
  12. * @property int $end_time 停止显示时间
  13. * @property int $admin_id 发布人
  14. * @property int $create_time 添加时间
  15. * @property int $hits 点击量
  16. * @property int $disabled 0:启用 1:禁用
  17. */
  18. class Announce extends \app\common\models\EActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%announce}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['title', 'content', 'start_time', 'end_time', 'admin_id'], 'required'],
  34. [['content'], 'string'],
  35. [[ 'admin_id', 'create_time', 'hits', 'disabled'], 'integer'],
  36. [['title'], 'string', 'max' => 100],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => Yii::t('attr','announce.id'),
  46. 'title' => Yii::t('attr','announce.title'),
  47. 'content' => Yii::t('attr','announce.content'),
  48. 'start_time' => Yii::t('attr','announce.start_time'),
  49. 'end_time' => Yii::t('attr','announce.end_time'),
  50. 'admin_id' => Yii::t('attr','announce.admin_id'),
  51. 'create_time' => Yii::t('attr','announce.create_time'),
  52. 'hits' => Yii::t('attr','announce.hits'),
  53. 'disabled' => Yii::t('attr','announce.disabled'),
  54. ];
  55. }
  56. public function getUsername()
  57. {
  58. if($this->admin_id)
  59. {
  60. $admin = Admin::findOne($this->admin_id);
  61. return $admin->real_name;
  62. }
  63. else
  64. {
  65. return '管理员';
  66. }
  67. }
  68. }