public static function upload($value) { $document = new Documents(); foreach ($value as $item => $i) { $document->{$item} = $i; } $document->created_at = time(); $document->updated_at = time(); $document->user = $value['user']; $token = Util::generateRandomStringCode(20); $document->token = $token; // echo \yii\helpers\Url::home(true) . $value['original_url'];die; $document->money_url = Util::makeOuoUrl(\yii\helpers\Url::home(true) . $value['original_url']); //$value['user'] = 1; //for testing $user = Users::findOne(['id' => $value['user']]); if (!$user) { return Util::arrayError('Error !'); } if ($document->save()) { $user->number_upload += 1; $user->points += 3; $user->save(); return Util::arraySuccess('Success', $document->id); } return Util::arrayError('Error !'); }