| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace addons\BusinessBonus\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_business_bonus_level}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string|null $level_name 等级名称
- * @property int|null $level_weight 等级权重,数字越大,等级越高
- * @property float|null $bonus_rate 分红比例,5%,填5
- * @property int|null $status 状态:-1删除,0禁用,1启用
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class BusinessBonusLevel extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_business_bonus_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
- [['bonus_rate'], 'number'],
- [['level_name'], 'string', 'max' => 128],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level_name' => '等级名称',
- 'level' => '等级(权重),数字越大,等级越高',
- 'bonus_rate' => '分红比例,5%,填5',
- 'status' => '状态:-1删除,0禁用,1启用',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
- if(empty($model)) throw new Exception('招商员等级不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
-
- }
|