DistributionLevel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use think\model\concern\SoftDelete;
  21. /**
  22. * 分销会员等级模型
  23. * Class DistributionLevel
  24. * @package app\common\model
  25. */
  26. class DistributionLevel extends BaseModel
  27. {
  28. use SoftDelete;
  29. protected $deleteTime = 'delete_time';
  30. /**
  31. * @notes 级别获取器
  32. * @param $value
  33. * @param $rule
  34. * @param $data
  35. * @return string
  36. * @author Tab
  37. * @date 2021/7/23 9:44
  38. */
  39. public function getWeightsDescAttr($value, $data)
  40. {
  41. $defaultStr = $data['is_default'] ? '级(默认等级)' : '级';
  42. return $value . $defaultStr;
  43. }
  44. /**
  45. * @notes 等级名称获取器
  46. * @param $value
  47. * @param $data
  48. * @return string
  49. * @author Tab
  50. * @date 2021/7/26 9:45
  51. */
  52. public function getNameDescAttr($value, $data)
  53. {
  54. $defaultStr = $data['is_default'] ? '(默认等级)' : '';
  55. return $value . $defaultStr;
  56. }
  57. /**
  58. * @notes 当前等级下的分销会员数
  59. * @param $value
  60. * @return int
  61. * @author Tab
  62. * @date 2021/7/23 9:48
  63. */
  64. public function getMemberNumAttr($value)
  65. {
  66. return Distribution::where(['level_id'=>$value,'is_distribution'=>1])->count();
  67. }
  68. /**
  69. * @notes 获取等级名称
  70. * @param $level_id
  71. * @return mixed|string
  72. * @author Tab
  73. * @date 2021/7/27 17:07
  74. */
  75. public static function getLevelName($level_id)
  76. {
  77. $level = self::findOrEmpty($level_id)->toArray();
  78. if($level) {
  79. return $level['name'] . '(' . $level['weights'] . '级)';
  80. }
  81. return '';
  82. }
  83. }