Resident.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class Resident extends Model
  6. {
  7. use SoftDelete;
  8. protected $deleteTime = 'deletetime';
  9. protected $defaultSoftDelete = 0;
  10. // 设置字段信息
  11. protected $schema = [
  12. 'id' => 'int',
  13. 'userid' => 'int',
  14. 'workerid' => 'int',
  15. 'agentid' => 'int',
  16. 'title' => 'string',
  17. 'mobile' => 'string',
  18. 'weixin' => 'string',
  19. 'qq' => 'string',
  20. 'province' => 'string',
  21. 'city' => 'string',
  22. 'district' => 'string',
  23. 'details' => 'string',
  24. 'status' => 'tinyint',
  25. 'createtime' => 'int',
  26. 'deletetime' => 'int',
  27. ];
  28. // 设置字段自动转换类型
  29. protected $type = [
  30. 'createtime' => 'timestamp:Y-m-d H:i:s'
  31. ];
  32. public function getStatusTextAttr($value,$data)
  33. {
  34. $status = [1=>'正常',2=>'禁用'];
  35. return $status[$data['status']];
  36. }
  37. // 关联User
  38. public function user()
  39. {
  40. return $this->hasOne(User::class, "id", "userid");
  41. }
  42. // 关联Worker
  43. public function worker()
  44. {
  45. return $this->hasOne(Worker::class, "id", "workerid");
  46. }
  47. // 关联Agent
  48. public function agent()
  49. {
  50. return $this->hasOne(Agent::class, "id", "agentid");
  51. }
  52. }