Broker.php 1.9 KB

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