123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\common\model;
- use think\Model;
- use think\model\concern\SoftDelete;
- class Resident extends Model
- {
- use SoftDelete;
- protected $deleteTime = 'deletetime';
- protected $defaultSoftDelete = 0;
- // 设置字段信息
- protected $schema = [
- 'id' => 'int',
- 'userid' => 'int',
- 'workerid' => 'int',
- 'agentid' => 'int',
- 'title' => 'string',
- 'mobile' => 'string',
- 'weixin' => 'string',
- 'qq' => 'string',
-
- 'province' => 'string',
- 'city' => 'string',
- 'district' => 'string',
- 'details' => 'string',
-
- 'status' => 'tinyint',
- 'createtime' => 'int',
- 'deletetime' => 'int',
- ];
-
- // 设置字段自动转换类型
- protected $type = [
- 'createtime' => 'timestamp:Y-m-d H:i:s'
- ];
-
- public function getStatusTextAttr($value,$data)
- {
- $status = [1=>'正常',2=>'禁用'];
- return $status[$data['status']];
- }
-
- // 关联User
- public function user()
- {
- return $this->hasOne(User::class, "id", "userid");
- }
-
- // 关联Worker
- public function worker()
- {
- return $this->hasOne(Worker::class, "id", "workerid");
- }
-
- // 关联Agent
- public function agent()
- {
- return $this->hasOne(Agent::class, "id", "agentid");
- }
- }
|