Broker.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ];
  33. // 设置字段自动转换类型
  34. protected $type = [
  35. 'createtime' => 'timestamp:Y-m-d H:i:s',
  36. ];
  37. public function getStatusTextAttr($value, $data)
  38. {
  39. $status = [1 => '正常', 2 => '禁用'];
  40. return $status[$data['status']];
  41. }
  42. public function getPowerreportTextAttr($value, $data)
  43. {
  44. $status = [1 => '是', 2 => '否'];
  45. return $status[$data['powerreport']];
  46. }
  47. // 关联User
  48. public function muser()
  49. {
  50. return $this->hasOne(User::class, "id", "userid");
  51. }
  52. // 关联Worker
  53. public function worker()
  54. {
  55. return $this->hasOne(Worker::class, "id", "workerid");
  56. }
  57. // 关联Agent
  58. public function agent()
  59. {
  60. return $this->hasOne(Agent::class, "id", "agentid");
  61. }
  62. // 关联User
  63. public function user()
  64. {
  65. return $this->hasMany(User::class, "brokerid", "id");
  66. }
  67. }