截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DistributionLevel.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\model\distribution;
  3. use app\common\basics\Models;
  4. use think\model\concern\SoftDelete;
  5. class DistributionLevel extends Models
  6. {
  7. use SoftDelete;
  8. protected $deleteTime = 'delete_time';
  9. /**
  10. * 升级条件允许的字段
  11. * singleConsumptionAmount 单笔消费金额
  12. * cumulativeConsumptionAmount 累计消费金额
  13. * cumulativeConsumptionTimes 累计消费次数
  14. * returnedCommission 已结算佣金收入
  15. */
  16. const UPDATE_CONDITION_FIELDS = ['singleConsumptionAmount', 'cumulativeConsumptionAmount', 'cumulativeConsumptionTimes', 'returnedCommission'];
  17. /**
  18. * @notes 获取键对应值的字段名
  19. * @param $key
  20. * @return string
  21. * @author Tab
  22. * @date 2021/9/1 14:58
  23. */
  24. public static function getValueFiled($key)
  25. {
  26. switch($key) {
  27. case 'singleConsumptionAmount':
  28. case 'cumulativeConsumptionAmount':
  29. case 'returnedCommission':
  30. return 'value_decimal';
  31. case 'cumulativeConsumptionTimes':
  32. return 'value_int';
  33. default:
  34. return 'value_text';
  35. }
  36. }
  37. /**
  38. * @notes 权重描述获取器
  39. * @param $value
  40. * @param $data
  41. * @return string
  42. * @author Tab
  43. * @date 2021/9/1 11:40
  44. */
  45. public function getWeightsDescAttr($value, $data)
  46. {
  47. return $data['is_default'] ? $value . '级(默认等级)' : $value . '级';
  48. }
  49. /**
  50. * @notes 等级下分销会员数量
  51. * @param $value
  52. * @param $data
  53. * @return int
  54. * @author Tab
  55. * @date 2021/9/1 11:41
  56. */
  57. public function getMembersNumAttr($value, $data)
  58. {
  59. $num = Distribution::where('level_id', $data['id'])->count();
  60. return $num;
  61. }
  62. public static function getLevelName($levelId)
  63. {
  64. $level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
  65. if (empty($level)) {
  66. return '';
  67. }
  68. return $level['name']. '(' . $level['weights'] . ')级';
  69. }
  70. public static function getLevelNameTwo($levelId)
  71. {
  72. $level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
  73. if (empty($level)) {
  74. return '';
  75. }
  76. return $level['name'];
  77. }
  78. }