Agent.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class Agent 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. 'loginname' => 'string',
  16. 'password' => 'string',
  17. 'idnumber' => 'string',
  18. 'title' => 'string',
  19. 'tilpic' => 'string',
  20. 'picall' => 'string',
  21. 'realname' => 'string',
  22. 'mobile' => 'string',
  23. 'telephone' => 'string',
  24. 'latitude' => 'float',
  25. 'longitude' => 'float',
  26. 'province' => 'string',
  27. 'city' => 'string',
  28. 'district' => 'string',
  29. 'address' => 'string',
  30. 'details' => 'string',
  31. 'priority' => 'int',
  32. 'remark' => 'string',
  33. 'status' => 'tinyint',
  34. 'createtime' => 'int',
  35. 'wxampcode' => 'string',
  36. 'income' => 'decimal',
  37. 'income_total' => 'decimal',
  38. 'is_settle' => 'tinyint',
  39. 'money' => 'decimal',
  40. 'money_total' => 'decimal',
  41. 'type' => 'tinyint',
  42. 'default_broker_id' => 'int',
  43. 'header_image' => 'string',
  44. ];
  45. // 设置字段自动转换类型
  46. protected $type = [
  47. 'picall' => 'json',
  48. 'createtime' => 'timestamp:Y-m-d H:i:s',
  49. ];
  50. protected $jsonAssoc = true;
  51. public function getStatusTextAttr($value, $data)
  52. {
  53. $status = [1 => '正常', 2 => '禁用'];
  54. return $status[$data['status']];
  55. }
  56. // 关联User
  57. public function muser()
  58. {
  59. return $this->hasOne(User::class, "id", "userid");
  60. }
  61. // 关联Worker
  62. public function worker()
  63. {
  64. return $this->hasOne(Worker::class, "id", "workerid");
  65. }
  66. // 关联Broker
  67. public function broker()
  68. {
  69. return $this->hasMany(Broker::class, "agentid", "id");
  70. }
  71. // 关联Partjob
  72. public function partjob()
  73. {
  74. return $this->hasMany(Partjob::class, "agentid", "id");
  75. }
  76. }