Broker.php 1.8 KB

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