Apply.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\common\model\commission;
  3. use think\Model;
  4. class Apply extends Model
  5. {
  6. protected $name = 'shopro_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. 'status_text'
  16. ];
  17. // 申请类型
  18. const APPLY_TYPE_PERSONAL = 'personal';
  19. const APPLY_TYPE_COMPANY = 'company';
  20. // 申请状态
  21. const STATUS_PENDING = 'pending';
  22. const STATUS_APPROVED = 'approved';
  23. const STATUS_REJECTED = 'rejected';
  24. public function getApplyTypeList()
  25. {
  26. return [
  27. self::APPLY_TYPE_PERSONAL => '个人申请',
  28. self::APPLY_TYPE_COMPANY => '企业申请'
  29. ];
  30. }
  31. public function getStatusList()
  32. {
  33. return [
  34. self::STATUS_PENDING => '待审核',
  35. self::STATUS_APPROVED => '已通过',
  36. self::STATUS_REJECTED => '已拒绝'
  37. ];
  38. }
  39. public function getApplyTypeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['apply_type']) ? $data['apply_type'] : '');
  42. $list = $this->getApplyTypeList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  48. $list = $this->getStatusList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. /**
  52. * 关联用户模型
  53. */
  54. public function user()
  55. {
  56. return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT');
  57. }
  58. /**
  59. * 关联代理商身份
  60. */
  61. public function identity()
  62. {
  63. return $this->belongsTo('app\common\model\commission\Identity', 'agent_identity_id', 'id', [], 'LEFT');
  64. }
  65. /**
  66. * 关联省份
  67. */
  68. public function province()
  69. {
  70. return $this->belongsTo('app\common\model\Area', 'province_id', 'id', [], 'LEFT');
  71. }
  72. /**
  73. * 关联城市
  74. */
  75. public function city()
  76. {
  77. return $this->belongsTo('app\common\model\Area', 'city_id', 'id', [], 'LEFT');
  78. }
  79. /**
  80. * 关联区域
  81. */
  82. public function district()
  83. {
  84. return $this->belongsTo('app\common\model\Area', 'district_id', 'id', [], 'LEFT');
  85. }
  86. /**
  87. * 关联审核管理员
  88. */
  89. public function admin()
  90. {
  91. return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT');
  92. }
  93. }