| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace addons\Boss\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_boss_level_setting}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $level
- * @property string $commission_type 分佣类型:积分score;佣金:commission
- * @property string $from_type 分佣类型:股东;
- * @property float $prize 永久分红,单位:百分比
- * @property float $extra_prize 额外分红,单位:百分比
- * @property int $is_extra 是否开启额外分红【0否,1是】
- * @property string $extra_type 获取额外分红的类型:1条件,2购物,3手动
- * @property int $extra_is_limit 额外分红是否存在上限【0否,1是】
- * @property float $extra_limit_price 额外分红上限金额,单位:元
- * @property int $extra_restrict 股东额外分红限制【0=否,1=是】
- * @property string $extra_restrict_keys 被选中的额外分红限制条件key集合
- * @property string $extra_restrict_values 额外分红限制条件的值集合
- * @property int $extra_alone 股东分红单独分【0=否,1=是】
- * @property int $insatiable 高等级拿低等级分红
- * @property int $insatiable_extra 高等级拿低等级额外分红
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property float $digital_prize 数字币永久分红,单位:百分比
- * @property float $extra_digital_prize 额外分红数字币,单位:百分比
- */
- class AddonsBossLevelSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_level_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['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'],
- [['prize', 'extra_prize', 'extra_limit_price','performance_rate', 'digital_prize', 'extra_digital_prize'], 'number'],
- [['commission_type', 'from_type', 'extra_type', 'extra_restrict_keys', 'bonus_restrict_keys'], 'string', 'max' => 255],
- [['extra_restrict_values', 'bonus_restrict_values'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level' => 'Level',
- 'commission_type' => '分佣类型:积分score;佣金:commission',
- 'from_type' => '分佣类型:股东;',
- 'prize' => '永久分红,单位:百分比',
- 'extra_prize' => '额外分红,单位:百分比',
- 'is_extra' => '是否开启额外分红【0否,1是】',
- 'is_performance' => '是否开启业绩分红',
- 'performance_rate' => '业绩分红比例',
- 'extra_type' => '获取额外分红的类型:1条件,2购物,3手动',
- 'extra_is_limit' => '额外分红是否存在上限【0否,1是】',
- 'extra_limit_price' => '额外分红上限金额,单位:元',
- 'extra_restrict' => '股东额外分红限制【0=否,1=是】',
- 'extra_restrict_keys' => '被选中的额外分红限制条件key集合',
- 'extra_restrict_values' => '额外分红限制条件的值集合',
- 'extra_alone' => '股东分红单独分【0=否,1=是】',
- 'bonus_restrict' => '股东分红限制[0=关闭, 1=开启]',
- 'bonus_restrict_keys' => '股东分红限制条件key合集',
- 'bonus_restrict_values' => '股东分红限制条件值合集',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'insatiable' => '高等级拿低等级分红',
- 'insatiable_extra' => '高等级拿低等级额外分红',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'extra_digital_prize' => '额外分红数字币',
- 'digital_prize' => '数字币永久分红'
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/11/4 0004 14:23
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool
- */
- public static function setData($params)
- {
- try{
- isset($params['extra_type']) && $params['extra_type'] = Json::encode($params['extra_type']);
- isset($params['extra_restrict_keys']) && $params['extra_restrict_keys'] = Json::encode($params['extra_restrict_keys']);
- isset($params['extra_restrict_values']) && $params['extra_restrict_values'] = Json::encode($params['extra_restrict_values']);
- isset($params['bonus_restrict_keys']) && $params['bonus_restrict_keys'] = Json::encode($params['bonus_restrict_keys']);
- isset($params['bonus_restrict_values']) && $params['bonus_restrict_values'] = Json::encode($params['bonus_restrict_values']);
- if (empty($params['bonus_restrict_keys'])) $params['bonus_restrict_keys'] = "";
- $params['prize'] = isset($params['prize']) ? floatval($params['prize']) : 0;
- $model = self::findOne([
- 'mall_id' => $params['mall_id'],
- 'level' => $params['level'],
- 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]
- ]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->level = $params['level'];
- $model->loadDefaultValues();
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 获取等级分佣配置
- * @Author: lun
- * @DateTime: 2021/11/4 0004 14:23
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $cond
- * @param array $with
- * @param bool $is_array
- * @param string $select
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getBossLevelSetting(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
- $default_cond = [['=','status',StatusEnum::ENABLED]];
- $cond = array_merge($default_cond,$cond);
- $query = self::find()->select($select);
- self::paramPack(['where'=>$cond, 'with'=>$with],$query);
- $data = $query->asArray($is_array)->all();
- return $data;
- }
- }
|