| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace common\models\census;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_census_mall_user_level".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $level 用户等级
- * @property int $numbers 数量
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at 上次更新数据时间
- */
- class CensusMallUserLevel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%census_mall_user_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'level', 'numbers', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level' => '用户等级',
- 'numbers' => '数量',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => '上次更新数据时间',
- ];
- }
- public static function setData($params)
- {
- try {
- if (empty($params['mall_id'])&&empty($params['numbers'])) {
- return false;
- }
- $model = self::findOne(['mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->level = $params['level']??0;
- $model->loadDefaultValues();
- }
- if (!empty($params['numbers'])) $model->numbers += $params['numbers'];
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|