Manager.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%manager}}".
  6. *
  7. * @property string $id
  8. * @property integer $company
  9. * @property string $realname
  10. * @property string $introduction
  11. * @property integer $created_at
  12. * @property integer $updated_at
  13. * @property integer $status
  14. */
  15. class Manager extends \yii\db\ActiveRecord
  16. {
  17. const STATUS_YES = 10; //正常
  18. const STATUS_NO = 0; //删除
  19. /**
  20. * @inheritdoc
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%manager}}';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['company', 'realname', 'introduction'], 'required'],
  33. [['created_at','updated_at'], 'default', 'value' => time()],
  34. [['company', 'created_at', 'updated_at', 'status'], 'integer'],
  35. [['realname'], 'string', 'max' => 32],
  36. [['introduction'], 'string', 'max' => 255],
  37. [['status'], 'default', 'value' => self::STATUS_YES],
  38. ];
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'company' => '公司ID',
  48. 'realname' => '名称',
  49. 'introduction' => '简介',
  50. 'created_at' => '创建时间',
  51. 'updated_at' => 'Updated At',
  52. 'status' => '状态',
  53. ];
  54. }
  55. public function getUser(){
  56. return $this->hasOne(User::className(),['id'=>'company']);
  57. }
  58. // public function getCompanyInfo(){
  59. // return $this->hasOne(UserCompany::className(),['id'=>'company']);
  60. // }
  61. public function getImage(){
  62. return $this->hasOne(ImageSource::className(),['topid'=>'id'])->where('type=:type AND status = :status',[':type'=>ImageSource::TYPE_MANAGER,':status'=>ImageSource::STATUS_YES]);
  63. }
  64. //相关的样板房、工地
  65. public function getBuilding(){
  66. return $this->hasMany(Building::className(),['manager_id'=>'id']);
  67. }
  68. }