Identity.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\common\model\commission;
  3. use app\common\Enum\AgentType;
  4. use think\Model;
  5. class Identity extends Model
  6. {
  7. protected $name = 'shop_commission_identity';
  8. // 开启自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'status_text',
  16. 'agent_type_text'
  17. ];
  18. // 状态
  19. const STATUS_DISABLED = 0;
  20. const STATUS_ENABLED = 1;
  21. // 代理商类型(使用枚举类常量)
  22. const AGENT_TYPE_NORMAL = AgentType::NORMAL;
  23. const AGENT_TYPE_PROVINCE = AgentType::PROVINCE;
  24. const AGENT_TYPE_CITY = AgentType::CITY;
  25. const AGENT_TYPE_DISTRICT = AgentType::DISTRICT;
  26. public function getStatusList()
  27. {
  28. return [
  29. self::STATUS_DISABLED => '禁用',
  30. self::STATUS_ENABLED => '启用'
  31. ];
  32. }
  33. public function getAgentTypeList()
  34. {
  35. return AgentType::getAll();
  36. }
  37. public function getStatusTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  40. $list = $this->getStatusList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getAgentTypeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['agent_type']) ? $data['agent_type'] : '');
  46. return AgentType::getTypeText($value);
  47. }
  48. /**
  49. * 获取启用的身份列表
  50. */
  51. public static function getEnabledList()
  52. {
  53. return self::where('status', self::STATUS_ENABLED)
  54. ->order('weigh asc, id asc')
  55. ->select();
  56. }
  57. }