Agent.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ];
  42. // 设置字段自动转换类型
  43. protected $type = [
  44. 'picall' => 'json',
  45. 'createtime' => 'timestamp:Y-m-d H:i:s',
  46. ];
  47. protected $jsonAssoc = true;
  48. public function getStatusTextAttr($value, $data)
  49. {
  50. $status = [1 => '正常', 2 => '禁用'];
  51. return $status[$data['status']];
  52. }
  53. // 关联User
  54. public function muser()
  55. {
  56. return $this->hasOne(User::class, "id", "userid");
  57. }
  58. // 关联Worker
  59. public function worker()
  60. {
  61. return $this->hasOne(Worker::class, "id", "workerid");
  62. }
  63. // 关联Broker
  64. public function broker()
  65. {
  66. return $this->hasMany(Broker::class, "agentid", "id");
  67. }
  68. // 关联Partjob
  69. public function partjob()
  70. {
  71. return $this->hasMany(Partjob::class, "agentid", "id");
  72. }
  73. }