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.

93 lines
2.2 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. */
  18. class Comment extends \yii\db\ActiveRecord
  19. {
  20. //状态
  21. const STATUS_DISPLAY = 1; //显示
  22. const STATUS_HIDE = 0; //隐藏
  23. public static $commentStatus = [
  24. self::STATUS_DISPLAY => '显示',
  25. self::STATUS_HIDE => '隐藏'
  26. ];
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return 'ats_comment';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['user_id'], 'required'],
  41. [['user_id', 'order_goods_id', 'star', 'status'], 'integer'],
  42. [['content'], 'string'],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'id',
  52. 'user_id' => '用户id',
  53. 'order_goods_id' => '订单详情商品id',
  54. 'star' => '星级',
  55. 'content' => '评论内容',
  56. 'status' => '状态:1为显示,0为不显示',
  57. 'updated_at' => '更新时间',
  58. 'created_at' => '创建时间',
  59. ];
  60. }
  61. /**
  62. * @author linyao
  63. * @email 602604991@qq.com
  64. * @created Nov 8, 2019
  65. *
  66. * 行为存储创建时间和更新时间
  67. */
  68. public function behaviors()
  69. {
  70. return [
  71. [
  72. 'class' => TimestampBehavior::className(),
  73. 'createdAtAttribute' => 'created_at',
  74. 'updatedAtAttribute' => 'updated_at',
  75. 'value' => function() {
  76. return time();
  77. },
  78. ],
  79. ];
  80. }
  81. public function getOrderGoods()
  82. {
  83. return $this->hasOne(OrderGoods::class,['id' => 'order_goods_id']);
  84. }
  85. }