Apply.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\common\model\commission;
  3. use app\common\Enum\AgentType;
  4. use app\common\Enum\ApplyType;
  5. use app\common\Enum\ApplyStatus;
  6. use think\Model;
  7. class Apply extends Model
  8. {
  9. protected $name = 'shop_commission_apply';
  10. // 添加默认字段值,防止字段不存在错误
  11. protected $field = [
  12. 'id', 'user_id', 'apply_type', 'agent_identity_id', 'agent_type',
  13. 'province_id', 'city_id', 'district_id', 'province_name', 'city_name', 'district_name',
  14. 'real_name', 'id_card', 'id_card_front', 'id_card_back', 'mobile',
  15. 'company_name', 'legal_person', 'legal_mobile', 'legal_id_card', 'legal_id_front', 'legal_id_back', 'business_license',
  16. 'status', 'reject_reason', 'admin_id', 'audit_time', 'createtime', 'updatetime'
  17. ];
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = 'int';
  20. // 定义时间戳字段名
  21. protected $createTime = 'createtime';
  22. protected $updateTime = 'updatetime';
  23. // 追加属性
  24. protected $append = [
  25. 'apply_type_text',
  26. 'agent_type_text',
  27. 'status_text'
  28. ];
  29. // 申请类型(使用枚举类常量)
  30. const APPLY_TYPE_PERSONAL = ApplyType::PERSONAL;
  31. const APPLY_TYPE_COMPANY = ApplyType::COMPANY;
  32. // 代理商类型(使用枚举类常量)
  33. const AGENT_TYPE_NORMAL = AgentType::NORMAL;
  34. const AGENT_TYPE_PROVINCE = AgentType::PROVINCE;
  35. const AGENT_TYPE_CITY = AgentType::CITY;
  36. const AGENT_TYPE_DISTRICT = AgentType::DISTRICT;
  37. // 申请状态(使用枚举类常量)
  38. const STATUS_PENDING = ApplyStatus::PENDING;
  39. const STATUS_APPROVED = ApplyStatus::APPROVED;
  40. const STATUS_REJECTED = ApplyStatus::REJECTED;
  41. public function getApplyTypeList()
  42. {
  43. return ApplyType::getAll();
  44. }
  45. public function getAgentTypeList()
  46. {
  47. return AgentType::getAll();
  48. }
  49. public function getStatusList()
  50. {
  51. return ApplyStatus::getAll();
  52. }
  53. public function getApplyTypeTextAttr($value, $data)
  54. {
  55. $value = $value ? $value : (isset($data['apply_type']) ? $data['apply_type'] : '');
  56. return ApplyType::getTypeText($value);
  57. }
  58. public function getAgentTypeTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : (isset($data['agent_type']) ? $data['agent_type'] : '');
  61. return AgentType::getTypeText($value);
  62. }
  63. public function getStatusTextAttr($value, $data)
  64. {
  65. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  66. return ApplyStatus::getStatusText($value);
  67. }
  68. /**
  69. * 关联用户模型
  70. */
  71. public function user()
  72. {
  73. return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT');
  74. }
  75. /**
  76. * 关联代理商身份
  77. */
  78. public function identity()
  79. {
  80. return $this->belongsTo('app\common\model\commission\Identity', 'agent_identity_id', 'id', [], 'LEFT');
  81. }
  82. /**
  83. * 关联省份
  84. */
  85. public function province()
  86. {
  87. return $this->belongsTo('app\common\model\Area', 'province_id', 'id', [], 'LEFT');
  88. }
  89. /**
  90. * 关联城市
  91. */
  92. public function city()
  93. {
  94. return $this->belongsTo('app\common\model\Area', 'city_id', 'id', [], 'LEFT');
  95. }
  96. /**
  97. * 关联区域
  98. */
  99. public function district()
  100. {
  101. return $this->belongsTo('app\common\model\Area', 'district_id', 'id', [], 'LEFT');
  102. }
  103. /**
  104. * 关联审核管理员
  105. */
  106. public function admin()
  107. {
  108. return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT');
  109. }
  110. }