Identity.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\model\commission;
  3. use think\Model;
  4. class Identity extends Model
  5. {
  6. protected $name = 'shop_commission_identity';
  7. // 开启自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. // 追加属性
  13. protected $append = [
  14. 'status_text',
  15. 'agent_type_text'
  16. ];
  17. // 状态
  18. const STATUS_DISABLED = 0;
  19. const STATUS_ENABLED = 1;
  20. // 代理商类型
  21. const AGENT_TYPE_NORMAL = 'normal';
  22. const AGENT_TYPE_REGIONAL = 'regional';
  23. public function getStatusList()
  24. {
  25. return [
  26. self::STATUS_DISABLED => '禁用',
  27. self::STATUS_ENABLED => '启用'
  28. ];
  29. }
  30. public function getAgentTypeList()
  31. {
  32. return [
  33. self::AGENT_TYPE_NORMAL => '普通代理商',
  34. self::AGENT_TYPE_REGIONAL => '区域代理商'
  35. ];
  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. $list = $this->getAgentTypeList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. /**
  50. * 获取启用的身份列表
  51. */
  52. public static function getEnabledList()
  53. {
  54. return self::where('status', self::STATUS_ENABLED)
  55. ->order('weigh asc, id asc')
  56. ->select();
  57. }
  58. }