123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace common\models;
- use Yii;
- /**
- * This is the model class for table "{{%building}}".
- *
- * @property string $id
- * @property integer $uid
- * @property integer $type
- * @property string $latitude
- * @property string $longitude
- * @property string $province
- * @property string $city
- * @property string $district
- * @property string $address
- * @property integer $created_at
- * @property integer $status
- * @property integer $updated_at
- * @property string $layout
- * @property double $acreage
- * @property integer $opening_begin
- * @property integer $opening_end
- * @property string $contact
- * @property string $stage
- * @property string $pattern
- * @property string $budget
- * @property string $style
- * @property string $name
- * @property string $hashcode
- * @property string $manager_id
- * @property string $designer_id
- * @property string $posted
- */
- class Building extends \yii\db\ActiveRecord
- {
- const TYPE_SITE = 1;//工地类型
- const TYPE_HOUSE = 2;//样板房类型
- public $distance;
- //默认房屋图片
- const DEFAULT_PIC = '../images/tj-img.png';
- const STATUS_REVIEW = 1;//等待审核中
- const STATUS_FAIL = -1;//审核失败
- const STATUS_SUCCESS = 10;//审核成功
- const POSTED_DELETE = 2;//删除
- const POSTED_YES = 1;//发布
- const POSTED_NO = 0;//停止
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%building}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['uid', 'type', 'city', 'address', 'created_at', 'status', 'updated_at', 'manager_id', 'designer_id'], 'required'],
- [['uid', 'type', 'created_at', 'status', 'updated_at', 'opening_begin', 'opening_end','posted'], 'integer'],
- [['acreage', 'budget'], 'number'],
- [['latitude', 'longitude','province' , 'city', 'district', 'address', 'layout', 'stage', 'pattern', 'style', 'name', 'hashcode'], 'string', 'max' => 32],
- [['contact'], 'string', 'max' => 120],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'uid' => 'Uid',
- 'type' => 'Type',
- 'latitude' => 'Latitude',
- 'longitude' => 'Longitude',
- 'province' => '省份编号',
- 'city' => '城市编号',
- 'district' => '地区编号',
- 'address' => '地址',
- 'created_at' => '创建时间',
- 'status' => 'Status',
- 'updated_at' => 'Updated At',
- 'layout' => '户型',
- 'acreage' => '面积',
- 'opening_begin' => '可约时间',
- 'opening_end' => '可约时间',
- 'contact' => '联系方式',
- 'stage' => '装修进度',
- 'pattern' => '装修模式',
- 'budget' => '单价',
- 'style' => '风格',
- 'name' => 'Name',
- 'hashcode' => 'Hashcode',
- 'manager_id' => '项目经理id',
- 'designer_id' => '设计师id',
- 'posted' => '是否发布',
- ];
- }
- //项目经理
- public function getManager(){
- return $this->hasOne(Manager::className(),['id'=>'manager_id']);
- }
- //设计师
- public function getDesigner(){
- return $this->hasOne(Designer::className(),['id'=>'designer_id']);
- }
- //工程相关照片
- public function getImage(){
- return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where(['bd_image.type' => [20, 30, 40,50], 'bd_image.status' => ImageSource::STATUS_YES]);
- }
- public function getAppointment(){
- return $this->hasMany(Appointment::className(),['pid'=>'id'])->limit(6);
- }
- //客厅照片
- public function getLiving(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>20,':status'=>ImageSource::STATUS_YES]);
- }
- //主卧照片
- public function getMaster(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>30,':status'=>ImageSource::STATUS_YES]);
- }
- //局部美图
- public function getPortion(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>40,':status'=>ImageSource::STATUS_YES]);
- }
- //局部美图2
- public function getPortion2(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES]);
- }
- //局部美图3
- public function getPortion3(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES]);
- }
- //局部美图4
- public function getPortion4(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES]);
- }
- //局部美图5
- public function getPortion5(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES]);
- }
- //平面图
- public function getFlat(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>50,':status'=>ImageSource::STATUS_YES]);
- }
- //施工图
- public function getBuild(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES]);
- }
- //施工图2
- public function getBuild2(){
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES]);
- }
- //所有图片的第一张
- public function getAll(){
- //return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type or type=:type1 or type=:type2 or type=:type3',[':type'=>20,':type1'=>30,':type2'=>40,':type3'=>50,]);
- return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where(['type'=>[ImageSource::TYPE_LIVING_ROOM,ImageSource::TYPE_MASTER_BEDROOM,ImageSource::TYPE_PORTION,ImageSource::TYPE_FLAT,ImageSource::TYPE_PORTION2,ImageSource::TYPE_PORTION3,ImageSource::TYPE_PORTION4,ImageSource::TYPE_PORTION5,ImageSource::TYPE_BUILD,ImageSource::TYPE_BUILD2],'status'=>ImageSource::STATUS_YES]);
- }
- //所有图片
- public function getAllimg(){
- //return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where('type=:type or type=:type1 or type=:type2 or type=:type3',[':type'=>20,':type1'=>30,':type2'=>40,':type3'=>50,]);
- return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where(['type'=>[ImageSource::TYPE_LIVING_ROOM,ImageSource::TYPE_MASTER_BEDROOM,ImageSource::TYPE_PORTION,ImageSource::TYPE_FLAT,ImageSource::TYPE_PORTION2,ImageSource::TYPE_PORTION3,ImageSource::TYPE_PORTION4,ImageSource::TYPE_PORTION5,ImageSource::TYPE_BUILD,ImageSource::TYPE_BUILD2],'status'=>ImageSource::STATUS_YES]);
- }
- public function getCompany()
- {
- return $this->hasOne(UserCompany::className(),['uid'=>'uid']);
- }
-
- }
|