Esempio n. 1
0
 /**
  * Изменение объема(количества продуктов) заказа
  * @param $amount
  * @return $this|null
  * @throws \Exception
  */
 public function updateAmount($amount)
 {
     $amount = intval($amount);
     if ($amount < 1) {
         $this->_delete();
         return null;
     }
     if ($amount === intval($this->amount)) {
         return $this;
     }
     $product = $this->product;
     \App\Helpers\Assistant::assertModel($product);
     $current_max_price_for_purchase = $product->getCurrentMaxPriceForPurchase($this->purchase_id);
     $sum = $current_max_price_for_purchase * $amount;
     \App\ActionLog::action('ORDER.UPDATE.BEFORE_TRANSACTION', ['order_id' => $this->id, 'current_max_price_for_purchase' => $current_max_price_for_purchase, 'purchase_id' => $this->purchase_id, 'product_id' => $this->product_id, 'amount' => $amount, 'sum' => $sum]);
     // Начало транзакции БД
     \DB::beginTransaction();
     $current_payment_transaction = $this->getCurrentPaymentTransaction();
     $current_payment_transaction->unblocking();
     $this->moneyBlocking($sum);
     $this->amount = $amount;
     $this->save();
     \DB::commit();
     // Окончание транзакции БД
     \App\ActionLog::action('ORDER.UPDATE.AFTER_TRANSACTION', ['order_id' => $this->id, 'current_max_price_for_purchase' => $current_max_price_for_purchase, 'purchase_id' => $this->purchase_id, 'product_id' => $this->product_id, 'amount' => $amount, 'sum' => $sum]);
     return $this;
 }
 /**
  * Создание транзакции Блокирование средств
  * @param double $sum
  * @param \App\BusinessLogic\Models\Order $order
  * @return \App\BusinessLogic\Models\PaymentTransaction
  */
 public static function makeBlocking($sum, \App\BusinessLogic\Models\Order $order)
 {
     // Начало транзакции БД
     \DB::beginTransaction();
     $payment_transaction = self::create(['sum' => $sum, 'user_id' => $order->user->id, 'operation_type' => self::OPERATION_TYPE_BLOCKING, 'operation_type_code' => self::OPERATION_TYPE_BLOCKING_CODE, 'order_id' => $order->id]);
     \App\ActionLog::action('PAYMENT_TRANSACTION.BLOCKING', ['payment_transaction_id' => $payment_transaction->id, 'sum' => $sum, 'user_id' => $order->user->id, 'operation_type' => self::OPERATION_TYPE_BLOCKING, 'operation_type_code' => self::OPERATION_TYPE_BLOCKING_CODE, 'order_id' => $order->id]);
     \DB::commit();
     // Окончание транзакции БД
     return $payment_transaction;
 }