You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4 KiB

  1. <?php
  2. namespace backend\modules\shop\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. use backend\modules\shop\models\ars\OrderGoods;
  6. /**
  7. * This is the model class for table "ats_comment".
  8. *
  9. * @property int $id
  10. * @property int $user_id 用户id
  11. * @property int $order_goods_id 订单详情商品id
  12. * @property int $star 星级
  13. * @property string $content 评论内容
  14. * @property int $status 状态:1为显示,0为不显示
  15. * @property int $updated_at 更新时间
  16. * @property int $created_at 创建时间
  17. * @property string $nickname 昵称
  18. * @property int $avatar 头像
  19. */
  20. class Comment extends \yii\db\ActiveRecord
  21. {
  22. //状态
  23. const STATUS_DISPLAY = 1; //显示
  24. const STATUS_HIDE = 0; //隐藏
  25. public static $commentStatus = [
  26. self::STATUS_DISPLAY => '显示',
  27. self::STATUS_HIDE => '隐藏'
  28. ];
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return 'ats_comment';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['user_id', 'order_goods_id', 'star', 'status', 'avatar'], 'integer'],
  43. [['content'], 'string'],
  44. [['nickname'], 'string', 'max' => 120],
  45. ];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => 'id',
  54. 'user_id' => '用户id',
  55. 'order_goods_id' => '订单详情商品id',
  56. 'star' => '星级',
  57. 'content' => '评论内容',
  58. 'status' => '状态:1为显示,0为不显示',
  59. 'updated_at' => '更新时间',
  60. 'created_at' => '创建时间',
  61. 'nickname' => '昵称',
  62. 'avatar' => '头像',
  63. ];
  64. }
  65. /**
  66. * @author linyao
  67. * @email 602604991@qq.com
  68. * @created Nov 8, 2019
  69. *
  70. * 行为存储创建时间和更新时间
  71. */
  72. public function behaviors()
  73. {
  74. return [
  75. [
  76. 'class' => TimestampBehavior::className(),
  77. 'createdAtAttribute' => 'created_at',
  78. 'updatedAtAttribute' => 'updated_at',
  79. 'value' => function() {
  80. return time();
  81. },
  82. ],
  83. ];
  84. }
  85. public function getOrderGoods()
  86. {
  87. return $this->hasOne(OrderGoods::class,['id' => 'order_goods_id']);
  88. }
  89. }