AddonsBossLevelSetting.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace addons\BossWeight\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_boss_weight_level_setting}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property int $level
  11. * @property string $commission_type 分佣类型:积分score;佣金:commission
  12. * @property string $from_type 分佣类型:股东;
  13. * @property float $prize 永久分红,单位:百分比
  14. * @property float $extra_prize 额外分红,单位:百分比
  15. * @property int $is_extra 是否开启额外分红【0否,1是】
  16. * @property int $extra_type 获取额外分红的类型:1购物,2条件,3任意
  17. * @property int $extra_is_limit 额外分红是否存在上限【0否,1是】
  18. * @property float $extra_limit_price 额外分红上限金额,单位:元
  19. * @property int $weight_status 是否开启加权分红。0-不开启,1-开启
  20. * @property int $weight_member_num 加权分红条件,直推会员数量
  21. * @property int $weight_product_num 加权分红条件,购买产品数量
  22. * @property int $weight_num 加权分红配置,满足条件奖励的权重数量
  23. * @property int $weight_level_ratio 加权分红配置,等级分红比例
  24. * @property int $weight_turnover_ratio 加权分红配置,营业额比例
  25. * @property int $weight_max_price 加权分红配置。分红上限金额
  26. * @property int $status 状态[-1:删除;0:禁用;1启用]
  27. * @property int $created_at
  28. * @property int $updated_at
  29. * @property int $weight_member_num_team 伞下团队每有一个市场业绩
  30. * @property int $weight_num_team 市场业绩达标,获得权重数量
  31. */
  32. class AddonsBossLevelSetting extends \common\models\base\BaseActiveRecord
  33. {
  34. const STATUS_ENABLE = 1;
  35. const STATUS_DISABLE = 0;
  36. const STATUS_DELETE = -1;
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public static function tableName()
  41. {
  42. return '{{%addons_boss_weight_level_setting}}';
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['mall_id'], 'required'],
  51. [['mall_id', 'level', 'is_extra', 'extra_type', 'extra_is_limit', 'status','created_at', 'updated_at',
  52. 'weight_status', 'weight_member_num', 'weight_product_num', 'weight_num','weight_num_team', 'weight_level_ratio', 'weight_turnover_ratio','weight_max_price','weight_is_limit','weight_member_level_second','weight_num_second'], 'integer'],
  53. [['prize', 'extra_prize', 'extra_limit_price','weight_member_num_team'], 'number'],
  54. [['commission_type', 'from_type','weight_member_num_second'], 'string', 'max' => 255],
  55. [['checked_weight_values'],'safe']
  56. ];
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'id' => 'ID',
  65. 'mall_id' => '商城ID',
  66. 'level' => 'Level',
  67. 'commission_type' => '分佣类型:积分score;佣金:commission',
  68. 'from_type' => '分佣类型:股东;',
  69. 'prize' => '永久分红,单位:百分比',
  70. 'extra_prize' => '额外分红,单位:百分比',
  71. 'is_extra' => '是否开启额外分红【0否,1是】',
  72. 'extra_type' => '获取额外分红的类型:1购物,2条件,3任意',
  73. 'extra_is_limit' => '额外分红是否存在上限【0否,1是】',
  74. 'extra_limit_price' => '额外分红上限金额,单位:元',
  75. 'weight_status' => '是否开启加权分红。0-不开启,1-开启',
  76. 'weight_member_num' => '加权分红条件,直推会员数量',
  77. 'weight_product_num' => '加权分红条件,购买产品数量',
  78. 'weight_num' => '加权分红配置,满足条件奖励的权重数量',
  79. 'weight_level_ratio' => '加权分红配置,等级分红比例',
  80. 'weight_turnover_ratio' => '加权分红配置,营业额比例',
  81. 'weight_max_price' => '加权分红配置。分红上限金额',
  82. 'status' => '状态[-1:删除;0:禁用;1启用]',
  83. 'created_at' => 'Created At',
  84. 'updated_at' => 'Updated At',
  85. 'weight_is_limit' => '是否开启权重限制',
  86. 'checked_weight_values' => '权重限制规则',
  87. 'weight_member_num_second' => '加权分红条件,直推会员数量',
  88. 'weight_member_level_second' => '加权分红条件,会员等级',
  89. 'weight_num_second' => '加权分红配置,满足条件奖励的权重数量',
  90. 'weight_member_num_team' => '伞下团队每有一个市场业绩',
  91. 'weight_num_team' => '市场业绩达标,获得权重数量'
  92. ];
  93. }
  94. /**
  95. * 保存数据
  96. * @Author: lun
  97. * @DateTime: 2021/11/4 0004 14:23
  98. * @Copyright: copyright (c) 2021 广东七件事集团
  99. * @param $params
  100. * @return bool
  101. */
  102. public static function setData($params)
  103. {
  104. try{
  105. $model = self::findOne([
  106. 'mall_id' => $params['mall_id'],
  107. 'level' => $params['level'],
  108. 'status' => [StatusEnum::ENABLED]
  109. ]);
  110. if (empty($model)) {
  111. $model = new self();
  112. $model->mall_id = $params['mall_id'];
  113. $model->level = $params['level'];
  114. $model->loadDefaultValues();
  115. }
  116. if(!$model->load($params,'') || !$model->save()){
  117. throw new \Exception($model->getErrorMessage());
  118. }
  119. return true;
  120. }catch(\Exception $e){
  121. self::$static_error = $e->getMessage();
  122. return false;
  123. }
  124. }
  125. /**
  126. * 获取等级分佣配置
  127. * @Author: lun
  128. * @DateTime: 2021/11/4 0004 14:23
  129. * @Copyright: copyright (c) 2021 广东七件事集团
  130. * @param array $cond
  131. * @param array $with
  132. * @param bool $is_array
  133. * @param string $select
  134. * @return array|\yii\db\ActiveRecord[]
  135. */
  136. public static function getBossLevelSetting(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
  137. $default_cond = [['<>','status',StatusEnum::DELETE]];
  138. $cond = array_merge($default_cond,$cond);
  139. $query = self::find()->select($select);
  140. self::paramPack(['where'=>$cond, 'with'=>$with],$query);
  141. $data = $query->asArray($is_array)->all();
  142. return $data;
  143. }
  144. }