Broker.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 'details' => 'string',
  24. 'status' => 'tinyint',
  25. 'powerreport' => 'tinyint',
  26. 'createtime' => '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. public function getPowerreportTextAttr($value,$data)
  38. {
  39. $status = [1=>'是',2=>'否'];
  40. return $status[$data['powerreport']];
  41. }
  42. // 关联User
  43. public function muser()
  44. {
  45. return $this->hasOne(User::class, "id", "userid");
  46. }
  47. // 关联Worker
  48. public function worker()
  49. {
  50. return $this->hasOne(Worker::class, "id", "workerid");
  51. }
  52. // 关联Agent
  53. public function agent()
  54. {
  55. return $this->hasOne(Agent::class, "id", "agentid");
  56. }
  57. // 关联User
  58. public function user()
  59. {
  60. return $this->hasMany(User::class, "brokerid", "id");
  61. }
  62. }