Grade.php 1.5 KB

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