Exemplo n.º 1
0
 /**
  * @var User $user
  *
  * @param $id
  * @return string
  * @throws ErrorException
  */
 public function actionRepeat($id)
 {
     $user = Yii::$app->user->identity;
     $order = Order::findOne($id);
     $db = Yii::$app->db;
     if ($order->user_id === $user->getId()) {
         if ($user->money >= $order->sum) {
             $user->debitMoney($order->sum);
             $transaction = $db->beginTransaction();
             try {
                 $user->save();
                 $id = Api::setTaskByNetwork($order);
                 if ($id !== NULL) {
                     $order->status = Order::PROCESSED;
                     $order->foreign_id = $id;
                     $order->save(false);
                     $transaction->commit();
                     Yii::$app->session->setFlash('message', ['type' => 'success', 'message' => 'Задание отправлено на повторное выполнение']);
                 } else {
                     throw new ErrorException();
                 }
             } catch (ErrorException $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         throw new ErrorException('Что-то не так');
     }
     return $this->redirect(Yii::$app->urlManager->createUrl('task/order/view-all'));
 }
Exemplo n.º 2
0
 /**
  * @var \common\modules\statistics\models\Order $model
  * @param $id
  * @return \yii\web\Response
  * @throws Exception
  * @throws NotFoundHttpException
  */
 public function actionApply($id)
 {
     $model = $this->findModel($id);
     $id = Api::setTaskByNetwork($model);
     if ($id !== NULL) {
         $model->status = Order::PROCESSED;
         $model->foreign_id = $id;
         $model->save(false);
     }
     return $this->redirect(['index']);
 }