Apply.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. // 追加属性
  16. protected $append = [
  17. 'apply_type_text',
  18. 'agent_type_text',
  19. 'status_text'
  20. ];
  21. // 申请类型(使用枚举类常量)
  22. const APPLY_TYPE_PERSONAL = ApplyType::PERSONAL;
  23. const APPLY_TYPE_COMPANY = ApplyType::COMPANY;
  24. // 代理商类型(使用枚举类常量)
  25. const AGENT_TYPE_NORMAL = AgentType::NORMAL;
  26. const AGENT_TYPE_PROVINCE = AgentType::PROVINCE;
  27. const AGENT_TYPE_CITY = AgentType::CITY;
  28. const AGENT_TYPE_DISTRICT = AgentType::DISTRICT;
  29. // 申请状态(使用枚举类常量)
  30. const STATUS_PENDING = ApplyStatus::PENDING;
  31. const STATUS_APPROVED = ApplyStatus::APPROVED;
  32. const STATUS_REJECTED = ApplyStatus::REJECTED;
  33. public function getApplyTypeList()
  34. {
  35. return ApplyType::getAll();
  36. }
  37. public function getAgentTypeList()
  38. {
  39. return AgentType::getAll();
  40. }
  41. public function getStatusList()
  42. {
  43. return ApplyStatus::getAll();
  44. }
  45. public function getApplyTypeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['apply_type']) ? $data['apply_type'] : '');
  48. return ApplyType::getTypeText($value);
  49. }
  50. public function getAgentTypeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['agent_type']) ? $data['agent_type'] : '');
  53. return AgentType::getTypeText($value);
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. return ApplyStatus::getStatusText($value);
  59. }
  60. /**
  61. * 关联用户模型
  62. */
  63. public function user()
  64. {
  65. return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT');
  66. }
  67. /**
  68. * 关联代理商身份
  69. */
  70. public function identity()
  71. {
  72. return $this->belongsTo('app\common\model\commission\Identity', 'agent_identity_id', 'id', [], 'LEFT');
  73. }
  74. /**
  75. * 关联省份
  76. */
  77. public function province()
  78. {
  79. return $this->belongsTo('app\common\model\Area', 'province_id', 'id', [], 'LEFT');
  80. }
  81. /**
  82. * 关联城市
  83. */
  84. public function city()
  85. {
  86. return $this->belongsTo('app\common\model\Area', 'city_id', 'id', [], 'LEFT');
  87. }
  88. /**
  89. * 关联区域
  90. */
  91. public function district()
  92. {
  93. return $this->belongsTo('app\common\model\Area', 'district_id', 'id', [], 'LEFT');
  94. }
  95. /**
  96. * 关联审核管理员
  97. */
  98. public function admin()
  99. {
  100. return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT');
  101. }
  102. }