| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace addons\BusinessBonus\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_business_bonus_level_info}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string|null $upgrade_bgi 升级申请背景图
- * @property string|null $level_desc 等级说明
- * @property string|null $benefit_intro 福利介绍
- * @property int|null $status 状态:-1删除,0禁用,1启用
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class BusinessBonusLevelInfo extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_business_bonus_level_info}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'business_bonus_level', 'status', 'created_at', 'updated_at'], 'integer'],
- [['benefit_intro'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'business_bonus_level' => '招商员等级',
- 'benefit_intro' => '福利介绍',
- '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['business_bonus_level']) && !empty($params['business_bonus_level'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'business_bonus_level' => $params['business_bonus_level'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
- }
- if (!isset($model) || empty($model)) {
- $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;
- }
- }
- /**
- * 获取福利介绍
- */
- public static function getBenefitIntro($mall_id, $business_bonus_level)
- {
- $info = self::getOne([
- ['=', 'mall_id', $mall_id],
- ['=', 'business_bonus_level', $business_bonus_level],
- ['=', 'status', StatusEnum::ENABLED],
- ], true);
- return $info['benefit_intro'] ?? '';
- }
- }
|