AddonsBossLevelSetting.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace addons\Boss\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\helpers\Json;
  6. /**
  7. * This is the model class for table "{{%addons_boss_level_setting}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $level
  12. * @property string $commission_type 分佣类型:积分score;佣金:commission
  13. * @property string $from_type 分佣类型:股东;
  14. * @property float $prize 永久分红,单位:百分比
  15. * @property float $extra_prize 额外分红,单位:百分比
  16. * @property int $is_extra 是否开启额外分红【0否,1是】
  17. * @property string $extra_type 获取额外分红的类型:1条件,2购物,3手动
  18. * @property int $extra_is_limit 额外分红是否存在上限【0否,1是】
  19. * @property float $extra_limit_price 额外分红上限金额,单位:元
  20. * @property int $extra_restrict 股东额外分红限制【0=否,1=是】
  21. * @property string $extra_restrict_keys 被选中的额外分红限制条件key集合
  22. * @property string $extra_restrict_values 额外分红限制条件的值集合
  23. * @property int $extra_alone 股东分红单独分【0=否,1=是】
  24. * @property int $insatiable 高等级拿低等级分红
  25. * @property int $insatiable_extra 高等级拿低等级额外分红
  26. * @property int $status 状态[-1:删除;0:禁用;1启用]
  27. * @property int $created_at
  28. * @property int $updated_at
  29. * @property float $digital_prize 数字币永久分红,单位:百分比
  30. * @property float $extra_digital_prize 额外分红数字币,单位:百分比
  31. */
  32. class AddonsBossLevelSetting extends \common\models\base\BaseActiveRecord
  33. {
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public static function tableName()
  38. {
  39. return '{{%addons_boss_level_setting}}';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['mall_id'], 'required'],
  48. [['mall_id', 'level', 'is_extra', 'extra_is_limit', 'extra_restrict', 'bonus_restrict', 'extra_alone','is_performance', 'status', 'created_at', 'updated_at', 'insatiable', 'insatiable_extra', 'is_static_extra'], 'integer'],
  49. [['prize', 'extra_prize', 'extra_limit_price','performance_rate', 'digital_prize', 'extra_digital_prize'], 'number'],
  50. [['commission_type', 'from_type', 'extra_type', 'extra_restrict_keys', 'bonus_restrict_keys'], 'string', 'max' => 255],
  51. [['extra_restrict_values', 'bonus_restrict_values'], 'string'],
  52. ];
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'mall_id' => '商城ID',
  62. 'level' => 'Level',
  63. 'commission_type' => '分佣类型:积分score;佣金:commission',
  64. 'from_type' => '分佣类型:股东;',
  65. 'prize' => '永久分红,单位:百分比',
  66. 'extra_prize' => '额外分红,单位:百分比',
  67. 'is_extra' => '是否开启额外分红【0否,1是】',
  68. 'is_performance' => '是否开启业绩分红',
  69. 'performance_rate' => '业绩分红比例',
  70. 'extra_type' => '获取额外分红的类型:1条件,2购物,3手动',
  71. 'extra_is_limit' => '额外分红是否存在上限【0否,1是】',
  72. 'extra_limit_price' => '额外分红上限金额,单位:元',
  73. 'extra_restrict' => '股东额外分红限制【0=否,1=是】',
  74. 'extra_restrict_keys' => '被选中的额外分红限制条件key集合',
  75. 'extra_restrict_values' => '额外分红限制条件的值集合',
  76. 'extra_alone' => '股东分红单独分【0=否,1=是】',
  77. 'bonus_restrict' => '股东分红限制[0=关闭, 1=开启]',
  78. 'bonus_restrict_keys' => '股东分红限制条件key合集',
  79. 'bonus_restrict_values' => '股东分红限制条件值合集',
  80. 'status' => '状态[-1:删除;0:禁用;1启用]',
  81. 'insatiable' => '高等级拿低等级分红',
  82. 'insatiable_extra' => '高等级拿低等级额外分红',
  83. 'created_at' => 'Created At',
  84. 'updated_at' => 'Updated At',
  85. 'extra_digital_prize' => '额外分红数字币',
  86. 'digital_prize' => '数字币永久分红'
  87. ];
  88. }
  89. /**
  90. * 保存数据
  91. * @Author: lun
  92. * @DateTime: 2021/11/4 0004 14:23
  93. * @Copyright: copyright (c) 2021 广东七件事集团
  94. * @param $params
  95. * @return bool
  96. */
  97. public static function setData($params)
  98. {
  99. try{
  100. isset($params['extra_type']) && $params['extra_type'] = Json::encode($params['extra_type']);
  101. isset($params['extra_restrict_keys']) && $params['extra_restrict_keys'] = Json::encode($params['extra_restrict_keys']);
  102. isset($params['extra_restrict_values']) && $params['extra_restrict_values'] = Json::encode($params['extra_restrict_values']);
  103. isset($params['bonus_restrict_keys']) && $params['bonus_restrict_keys'] = Json::encode($params['bonus_restrict_keys']);
  104. isset($params['bonus_restrict_values']) && $params['bonus_restrict_values'] = Json::encode($params['bonus_restrict_values']);
  105. if (empty($params['bonus_restrict_keys'])) $params['bonus_restrict_keys'] = "";
  106. $params['prize'] = isset($params['prize']) ? floatval($params['prize']) : 0;
  107. $model = self::findOne([
  108. 'mall_id' => $params['mall_id'],
  109. 'level' => $params['level'],
  110. 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]
  111. ]);
  112. if (empty($model)) {
  113. $model = new self();
  114. $model->mall_id = $params['mall_id'];
  115. $model->level = $params['level'];
  116. $model->loadDefaultValues();
  117. }
  118. if(!$model->load($params,'') || !$model->save()){
  119. throw new \Exception($model->getErrorMessage());
  120. }
  121. return true;
  122. }catch(\Exception $e){
  123. self::$static_error = $e->getMessage();
  124. return false;
  125. }
  126. }
  127. /**
  128. * 获取等级分佣配置
  129. * @Author: lun
  130. * @DateTime: 2021/11/4 0004 14:23
  131. * @Copyright: copyright (c) 2021 广东七件事集团
  132. * @param array $cond
  133. * @param array $with
  134. * @param bool $is_array
  135. * @param string $select
  136. * @return array|\yii\db\ActiveRecord[]
  137. */
  138. public static function getBossLevelSetting(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
  139. $default_cond = [['=','status',StatusEnum::ENABLED]];
  140. $cond = array_merge($default_cond,$cond);
  141. $query = self::find()->select($select);
  142. self::paramPack(['where'=>$cond, 'with'=>$with],$query);
  143. $data = $query->asArray($is_array)->all();
  144. return $data;
  145. }
  146. }