Identity.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. ];
  16. // 状态
  17. const STATUS_DISABLED = 0;
  18. const STATUS_ENABLED = 1;
  19. public function getStatusList()
  20. {
  21. return [
  22. self::STATUS_DISABLED => '禁用',
  23. self::STATUS_ENABLED => '启用'
  24. ];
  25. }
  26. public function getStatusTextAttr($value, $data)
  27. {
  28. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  29. $list = $this->getStatusList();
  30. return isset($list[$value]) ? $list[$value] : '';
  31. }
  32. /**
  33. * 获取启用的身份列表
  34. */
  35. public static function getEnabledList()
  36. {
  37. return self::where('status', self::STATUS_ENABLED)
  38. ->order('weigh asc, id asc')
  39. ->select();
  40. }
  41. }