Building.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%building}}".
  6. *
  7. * @property string $id
  8. * @property integer $uid
  9. * @property integer $type
  10. * @property string $latitude
  11. * @property string $longitude
  12. * @property string $province
  13. * @property string $city
  14. * @property string $district
  15. * @property string $address
  16. * @property integer $created_at
  17. * @property integer $status
  18. * @property integer $updated_at
  19. * @property string $layout
  20. * @property double $acreage
  21. * @property integer $opening_begin
  22. * @property integer $opening_end
  23. * @property string $contact
  24. * @property string $stage
  25. * @property string $pattern
  26. * @property string $budget
  27. * @property string $style
  28. * @property string $name
  29. * @property string $hashcode
  30. * @property string $manager_id
  31. * @property string $designer_id
  32. * @property string $posted
  33. */
  34. class Building extends \yii\db\ActiveRecord
  35. {
  36. const TYPE_SITE = 1;//工地类型
  37. const TYPE_HOUSE = 2;//样板房类型
  38. public $distance;
  39. //默认房屋图片
  40. const DEFAULT_PIC = '../images/tj-img.png';
  41. const STATUS_REVIEW = 1;//等待审核中
  42. const STATUS_FAIL = -1;//审核失败
  43. const STATUS_SUCCESS = 10;//审核成功
  44. const POSTED_DELETE = 2;//删除
  45. const POSTED_YES = 1;//发布
  46. const POSTED_NO = 0;//停止
  47. /**
  48. * @inheritdoc
  49. */
  50. public static function tableName()
  51. {
  52. return '{{%building}}';
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function rules()
  58. {
  59. return [
  60. [['uid', 'type', 'city', 'address', 'created_at', 'status', 'updated_at', 'manager_id', 'designer_id'], 'required'],
  61. [['uid', 'type', 'created_at', 'status', 'updated_at', 'opening_begin', 'opening_end','posted'], 'integer'],
  62. [['acreage', 'budget'], 'number'],
  63. [['latitude', 'longitude','province' , 'city', 'district', 'address', 'layout', 'stage', 'pattern', 'style', 'name', 'hashcode'], 'string', 'max' => 32],
  64. [['contact'], 'string', 'max' => 120],
  65. ];
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function attributeLabels()
  71. {
  72. return [
  73. 'id' => 'ID',
  74. 'uid' => 'Uid',
  75. 'type' => 'Type',
  76. 'latitude' => 'Latitude',
  77. 'longitude' => 'Longitude',
  78. 'province' => '省份编号',
  79. 'city' => '城市编号',
  80. 'district' => '地区编号',
  81. 'address' => '地址',
  82. 'created_at' => '创建时间',
  83. 'status' => 'Status',
  84. 'updated_at' => 'Updated At',
  85. 'layout' => '户型',
  86. 'acreage' => '面积',
  87. 'opening_begin' => '可约时间',
  88. 'opening_end' => '可约时间',
  89. 'contact' => '联系方式',
  90. 'stage' => '装修进度',
  91. 'pattern' => '装修模式',
  92. 'budget' => '单价',
  93. 'style' => '风格',
  94. 'name' => 'Name',
  95. 'hashcode' => 'Hashcode',
  96. 'manager_id' => '项目经理id',
  97. 'designer_id' => '设计师id',
  98. 'posted' => '是否发布',
  99. ];
  100. }
  101. //项目经理
  102. public function getManager(){
  103. return $this->hasOne(Manager::className(),['id'=>'manager_id']);
  104. }
  105. //设计师
  106. public function getDesigner(){
  107. return $this->hasOne(Designer::className(),['id'=>'designer_id']);
  108. }
  109. //工程相关照片
  110. public function getImage(){
  111. return $this->hasMany(ImageSource::className(),['topid'=>'id'])->where(['bd_image.type' => [20, 30, 40,50], 'bd_image.status' => ImageSource::STATUS_YES]);
  112. }
  113. public function getAppointment(){
  114. return $this->hasMany(Appointment::className(),['pid'=>'id'])->limit(6);
  115. }
  116. //客厅照片
  117. public function getLiving(){
  118. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>20,':status'=>ImageSource::STATUS_YES]);
  119. }
  120. //主卧照片
  121. public function getMaster(){
  122. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>30,':status'=>ImageSource::STATUS_YES]);
  123. }
  124. //局部美图
  125. public function getPortion(){
  126. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>40,':status'=>ImageSource::STATUS_YES]);
  127. }
  128. //局部美图2
  129. public function getPortion2(){
  130. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES]);
  131. }
  132. //局部美图3
  133. public function getPortion3(){
  134. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES]);
  135. }
  136. //局部美图4
  137. public function getPortion4(){
  138. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES]);
  139. }
  140. //局部美图5
  141. public function getPortion5(){
  142. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES]);
  143. }
  144. //平面图
  145. public function getFlat(){
  146. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>50,':status'=>ImageSource::STATUS_YES]);
  147. }
  148. //施工图
  149. public function getBuild(){
  150. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES]);
  151. }
  152. //施工图2
  153. public function getBuild2(){
  154. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES]);
  155. }
  156. //所有图片的第一张
  157. public function getAll(){
  158. //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,]);
  159. 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]);
  160. }
  161. //所有图片
  162. public function getAllimg(){
  163. //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,]);
  164. 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]);
  165. }
  166. public function getCompany()
  167. {
  168. return $this->hasOne(UserCompany::className(),['uid'=>'uid']);
  169. }
  170. }