Apply.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\common\model\commission;
  3. use think\Model;
  4. class Apply extends Model
  5. {
  6. protected $name = 'shop_commission_apply';
  7. // 开启自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. // 追加属性
  13. protected $append = [
  14. 'apply_type_text',
  15. 'agent_type_text',
  16. 'status_text'
  17. ];
  18. // 申请类型
  19. const APPLY_TYPE_PERSONAL = 'personal';
  20. const APPLY_TYPE_COMPANY = 'company';
  21. // 代理商类型
  22. const AGENT_TYPE_NORMAL = 'normal';
  23. const AGENT_TYPE_REGIONAL = 'regional';
  24. // 申请状态
  25. const STATUS_PENDING = 'pending';
  26. const STATUS_APPROVED = 'approved';
  27. const STATUS_REJECTED = 'rejected';
  28. public function getApplyTypeList()
  29. {
  30. return [
  31. self::APPLY_TYPE_PERSONAL => '个人申请',
  32. self::APPLY_TYPE_COMPANY => '企业申请'
  33. ];
  34. }
  35. public function getAgentTypeList()
  36. {
  37. return [
  38. self::AGENT_TYPE_NORMAL => '普通代理商',
  39. self::AGENT_TYPE_REGIONAL => '区域代理商'
  40. ];
  41. }
  42. public function getStatusList()
  43. {
  44. return [
  45. self::STATUS_PENDING => '待审核',
  46. self::STATUS_APPROVED => '已通过',
  47. self::STATUS_REJECTED => '已拒绝'
  48. ];
  49. }
  50. public function getApplyTypeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['apply_type']) ? $data['apply_type'] : '');
  53. $list = $this->getApplyTypeList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getAgentTypeTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['agent_type']) ? $data['agent_type'] : '');
  59. $list = $this->getAgentTypeList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getStatusTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  65. $list = $this->getStatusList();
  66. return isset($list[$value]) ? $list[$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. }