20], [['cover', 'link'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'title' => 'Title', 'cover' => 'Cover', 'link' => 'Link', 'sort' => 'Sort', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * 保存数据 * * @param [type] $mall_id * @param array $params * @return void */ public static function setData($mall_id, array $params){ try{ if(!empty($params['id'])){ $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['=','status', 1]]); if(empty($model)) throw new \Exception('活动不存在或已删除'); }else{ $model = new self(); $model->loadDefaultValues(); $model->mall_id = $mall_id; } // 将内容转为json字符串 !empty($params['link']) && $params['link'] = Json::encode($params['link']); if(!$model->load($params,'') || !$model->save()) throw new \yii\db\Exception($model->getErrorMessage()); return $model; }catch(\Exception $e){ self::$error = $e->getMessage(); return false; } } }