fix

parent 8de0928f
...@@ -36,19 +36,13 @@ class BidController extends \common\components\BaseController ...@@ -36,19 +36,13 @@ class BidController extends \common\components\BaseController
$model = new Bid; $model = new Bid;
$model->scenario = Yii::$app->request->post('scenario'); $model->scenario = Yii::$app->request->post('scenario');
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
{
$transaction = Yii::$app->db->beginTransaction(); $transaction = Yii::$app->db->beginTransaction();
try {
try if ($model->save()) {
{
if($model->save())
{
// Yii::$app->user->identity->afterSubscribe(12); // Yii::$app->user->identity->afterSubscribe(12);
if($model->file) if ($model->file) {
{ foreach ($model->file as $filename) {
foreach ($model->file as $filename)
{
$file = new BidFile; $file = new BidFile;
$file->bid_id = $model->id; $file->bid_id = $model->id;
$file->filename = $filename; $file->filename = $filename;
...@@ -58,24 +52,17 @@ class BidController extends \common\components\BaseController ...@@ -58,24 +52,17 @@ class BidController extends \common\components\BaseController
} }
$model->send(); $model->send();
$transaction->commit(); $transaction->commit();
return ['success' => true]; return ['success' => true];
} } else {
else
{
return ActiveForm::validate($model); return ActiveForm::validate($model);
} }
} } catch (Exception $e) {
catch (Exception $e)
{
$transaction->rollBack(); $transaction->rollBack();
throw $e; throw $e;
} }
} } else {
else
{
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }
...@@ -92,19 +79,12 @@ class BidController extends \common\components\BaseController ...@@ -92,19 +79,12 @@ class BidController extends \common\components\BaseController
$model = new Bid; $model = new Bid;
$model->blog = true; $model->blog = true;
$model->scenario = Yii::$app->request->post('scenario'); $model->scenario = Yii::$app->request->post('scenario');
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
{
$transaction = Yii::$app->db->beginTransaction(); $transaction = Yii::$app->db->beginTransaction();
try {
try if ($model->save()) {
{ if ($model->file) {
if($model->save()) foreach ($model->file as $filename) {
{
// Yii::$app->user->identity->afterSubscribe(12);
if($model->file)
{
foreach ($model->file as $filename)
{
$file = new BidFile; $file = new BidFile;
$file->bid_id = $model->id; $file->bid_id = $model->id;
$file->filename = $filename; $file->filename = $filename;
...@@ -114,24 +94,17 @@ class BidController extends \common\components\BaseController ...@@ -114,24 +94,17 @@ class BidController extends \common\components\BaseController
} }
$model->send(); $model->send();
$transaction->commit(); $transaction->commit();
return ['success' => true]; return ['success' => true];
} } else {
else
{
return ActiveForm::validate($model); return ActiveForm::validate($model);
} }
} } catch (Exception $e) {
catch (Exception $e)
{
$transaction->rollBack(); $transaction->rollBack();
throw $e; throw $e;
} }
} } else {
else
{
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }
...@@ -144,10 +117,8 @@ class BidController extends \common\components\BaseController ...@@ -144,10 +117,8 @@ class BidController extends \common\components\BaseController
$model = new BidFile; $model = new BidFile;
$model->file = UploadedFile::getInstanceByName('file'); $model->file = UploadedFile::getInstanceByName('file');
if($model->file) if($model->file) {
{ if (!file_exists(BidFile::path())) {
if(!file_exists(BidFile::path()))
{
mkdir(BidFile::path(), 0777, true); mkdir(BidFile::path(), 0777, true);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment