Grade.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model\user;
  13. use cores\BaseModel;
  14. use app\common\library\helper;
  15. /**
  16. * 用户会员等级模型
  17. * Class Grade
  18. * @package app\common\model\user
  19. */
  20. class Grade extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'user_grade';
  24. // 定义主键
  25. protected $pk = 'grade_id';
  26. /**
  27. * 获取器:升级条件
  28. * @param $json
  29. * @return mixed
  30. */
  31. public function getUpgradeAttr($json)
  32. {
  33. return helper::jsonDecode($json);
  34. }
  35. /**
  36. * 获取器:等级权益
  37. * @param $json
  38. * @return mixed
  39. */
  40. public function getEquityAttr($json)
  41. {
  42. return helper::jsonDecode($json);
  43. }
  44. /**
  45. * 修改器:升级条件
  46. * @param $data
  47. * @return mixed
  48. */
  49. public function setUpgradeAttr($data)
  50. {
  51. return helper::jsonEncode($data);
  52. }
  53. /**
  54. * 修改器:等级权益
  55. * @param $data
  56. * @return mixed
  57. */
  58. public function setEquityAttr($data)
  59. {
  60. return helper::jsonEncode($data);
  61. }
  62. /**
  63. * 会员等级详情
  64. * @param int $gradId
  65. * @param array $with
  66. * @return static|array|null
  67. */
  68. public static function detail(int $gradId, array $with = [])
  69. {
  70. return static::get($gradId, $with);
  71. }
  72. /**
  73. * 验证等级权重是否存在
  74. * @param int $weight 验证的权重
  75. * @param int $gradeId 自身的等级ID
  76. * @return bool
  77. */
  78. public static function checkExistByWeight(int $weight, int $gradeId = 0): bool
  79. {
  80. $filter = [];
  81. $gradeId > 0 && $filter[] = ['grade_id', '<>', (int)$gradeId];
  82. return !!(new static)->where('weight', '=', (int)$weight)
  83. ->where($filter)
  84. ->where('is_delete', '=', 0)
  85. ->value('grade_id');
  86. }
  87. }