Broker.php 1.7 KB

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