Comment.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%comment}}".
  6. *
  7. * @property string $id
  8. * @property integer $pid
  9. * @property integer $type
  10. * @property integer $uid
  11. * @property integer $reply_uid
  12. * @property integer $star
  13. * @property string $content
  14. * @property integer $created_at
  15. * @property integer $updated_at
  16. * @property integer $status
  17. */
  18. class Comment extends \yii\db\ActiveRecord
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. const STATUS_DELETED = 0;
  24. const STATUS_ACTIVE = 10;
  25. const TYPE_SITE = 1;//工地类型
  26. const TYPE_HOUSE = 2;//样板房类型
  27. public static function tableName()
  28. {
  29. return '{{%comment}}';
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['pid', 'type', 'uid', 'created_at', 'updated_at', 'status'], 'required'],
  38. [['pid', 'type', 'uid', 'reply_uid', 'star', 'created_at', 'updated_at', 'status'], 'integer'],
  39. [['content'], 'string', 'max' => 120],
  40. ['type','in','range'=>[self::TYPE_SITE,self::TYPE_HOUSE]]
  41. ];
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'pid' => '工地ID',
  51. 'type' => '类型',
  52. 'uid' => '留言人',
  53. 'reply_uid' => '回复人',
  54. 'star' => '星级',
  55. 'content' => '评价内容',
  56. 'created_at' => 'Created At',
  57. 'updated_at' => 'Updated At',
  58. 'status' => 'Status',
  59. ];
  60. }
  61. //用户信息
  62. public function getUserinfo(){
  63. return $this->hasOne(UserInfo::className(),['uid'=>'uid']);
  64. }
  65. //公司信息
  66. public function getCompanyinfo(){
  67. return $this->hasOne(UserCompany::className(),['uid'=>'reply_uid']);
  68. }
  69. //工地信息
  70. public function getHouseinfo(){
  71. return $this->hasOne(Building::className(),['id'=>'pid']);
  72. }
  73. //评价回复
  74. public function getReply(){
  75. return $this->hasMany(Reply::className(),['cid'=>'id']);
  76. }
  77. //评论图片
  78. public function getImgs(){
  79. return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where(['type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES]);
  80. }
  81. static function time_tran($the_time)
  82. {
  83. $now_time = time();
  84. $show_time = $the_time;
  85. $dur = $now_time - $show_time;
  86. if($dur < 0){
  87. return $the_time;
  88. }else{
  89. if($dur < 60){
  90. return $dur.'秒前';
  91. }else{
  92. if($dur < 3600){
  93. return floor($dur/60).'分钟前';
  94. }else{
  95. if($dur < 86400){
  96. return floor($dur/3600).'小时前';
  97. }else{
  98. return floor($dur/86400).'天前';
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }