123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace common\models;
- use Yii;
- /**
- * This is the model class for table "{{%comment}}".
- *
- * @property string $id
- * @property integer $pid
- * @property integer $type
- * @property integer $uid
- * @property integer $reply_uid
- * @property integer $star
- * @property string $content
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $status
- */
- class Comment extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- const STATUS_DELETED = 0;
- const STATUS_ACTIVE = 10;
- const TYPE_SITE = 1;//工地类型
- const TYPE_HOUSE = 2;//样板房类型
- public static function tableName()
- {
- return '{{%comment}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['pid', 'type', 'uid', 'created_at', 'updated_at', 'status'], 'required'],
- [['pid', 'type', 'uid', 'reply_uid', 'star', 'created_at', 'updated_at', 'status'], 'integer'],
- [['content'], 'string', 'max' => 120],
- ['type','in','range'=>[self::TYPE_SITE,self::TYPE_HOUSE]]
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'pid' => '工地ID',
- 'type' => '类型',
- 'uid' => '留言人',
- 'reply_uid' => '回复人',
- 'star' => '星级',
- 'content' => '评价内容',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => 'Status',
- ];
- }
- //用户信息
- public function getUserinfo(){
- return $this->hasOne(UserInfo::className(),['uid'=>'uid']);
- }
- //公司信息
- public function getCompanyinfo(){
- return $this->hasOne(UserCompany::className(),['uid'=>'reply_uid']);
- }
- //工地信息
- public function getHouseinfo(){
- return $this->hasOne(Building::className(),['id'=>'pid']);
- }
- //评价回复
- public function getReply(){
- return $this->hasMany(Reply::className(),['cid'=>'id']);
- }
- //评论图片
- public function getImgs(){
- return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where(['type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES]);
- }
- static function time_tran($the_time)
- {
- $now_time = time();
- $show_time = $the_time;
- $dur = $now_time - $show_time;
- if($dur < 0){
- return $the_time;
- }else{
- if($dur < 60){
- return $dur.'秒前';
- }else{
- if($dur < 3600){
- return floor($dur/60).'分钟前';
- }else{
- if($dur < 86400){
- return floor($dur/3600).'小时前';
- }else{
- return floor($dur/86400).'天前';
- }
- }
- }
- }
- }
- }
|