| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\Happiness\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_happiness_business".
- *
- * @property int $id
- * @property int $user_id 用户ID
- * @property int $mall_id 商城ID
- * @property int $level 权重
- * @property int $status 状态
- * @property int $created_at
- * @property int $updated_at
- */
- class HappinessBusiness extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_happiness_business';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id', 'mall_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
- [['level'], 'required'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => 'User ID',
- 'mall_id' => 'Mall ID',
- 'level' => 'Level',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public static function setData($params)
- {
- try {
- if (isset($params['user_id']) && !empty($params['user_id'])) {
- $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- }
- else if(isset($params['id']) && !empty($params['id']))
- $model = self::findOne($params['id']);
- else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if(!$model)
- {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|