Designer.php 2.0 KB

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