Broker.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class Broker 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. 'town' => 'string',
  24. 'village' => 'string',
  25. 'details' => 'string',
  26. 'status' => 'tinyint',
  27. 'powerreport' => 'tinyint',
  28. 'createtime' => 'int',
  29. 'income' => 'decimal',
  30. 'income_total' => 'decimal',
  31. 'region' => 'string',
  32. 'latitude' => 'float',
  33. 'longitude' => 'float',
  34. 'type' => 'tinyint',
  35. ];
  36. // 设置字段自动转换类型
  37. protected $type = [
  38. 'createtime' => 'timestamp:Y-m-d H:i:s',
  39. ];
  40. public function getStatusTextAttr($value, $data)
  41. {
  42. $status = [1 => '正常', 2 => '禁用'];
  43. return $status[$data['status']];
  44. }
  45. public function getPowerreportTextAttr($value, $data)
  46. {
  47. $status = [1 => '是', 2 => '否'];
  48. return $status[$data['powerreport']];
  49. }
  50. public function getTypeTextAttr($value, $data)
  51. {
  52. $status = [1 => '经纪人', 2 => '红色合伙人', 3 => '省外经纪人'];
  53. return $status[$data['type']];
  54. }
  55. // 关联User
  56. public function muser()
  57. {
  58. return $this->hasOne(User::class, "id", "userid");
  59. }
  60. // 关联Worker
  61. public function worker()
  62. {
  63. return $this->hasOne(Worker::class, "id", "workerid");
  64. }
  65. // 关联Agent
  66. public function agent()
  67. {
  68. return $this->hasOne(Agent::class, "id", "agentid");
  69. }
  70. // 关联User
  71. public function user()
  72. {
  73. return $this->hasMany(User::class, "brokerid", "id");
  74. }
  75. }