Grade.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model\user;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 用户等级模型
  6. */
  7. class Grade extends BaseModel
  8. {
  9. protected $pk = 'grade_id';
  10. protected $name = 'user_grade';
  11. /**
  12. * 用户等级模型初始化
  13. */
  14. public static function init()
  15. {
  16. parent::init();
  17. }
  18. /**
  19. * 获取详情
  20. */
  21. public static function detail($grade_id)
  22. {
  23. return (new static())->find($grade_id);
  24. }
  25. /**
  26. * 获取列表记录
  27. */
  28. public function getLists()
  29. {
  30. return $this->where('is_delete', '=', 0)
  31. ->field('grade_id,name')
  32. ->order(['weight' => 'asc', 'create_time' => 'asc'])
  33. ->select();
  34. }
  35. /**
  36. * 获取可用的会员等级列表
  37. */
  38. public static function getUsableList($appId = null)
  39. {
  40. $model = new static;
  41. $appId = $appId ? $appId : $model::$app_id;
  42. return $model->where('is_delete', '=', '0')
  43. ->where('app_id', '=', $appId)
  44. ->order(['weight' => 'asc', 'create_time' => 'asc'])
  45. ->select();
  46. }
  47. /**
  48. * 获取默认等级id
  49. */
  50. public static function getDefaultGradeId(){
  51. $grade = (new static())->where('is_default', '=', 1)->find();
  52. return $grade['grade_id'];
  53. }
  54. }