Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.6 kB
1
Indexable
Never
 $user = Auth::user();
        $balance = (int)($user->balance - 0.5);
        User::where('id', $user->id)->update([
            'balance' => $balance,
        ]);
        
        if( ($arr_res->auth_code != 00) || (($arr_res->auth_code != "00"))){
            //Заказ
            $order = Order::where([
              ['id', $order->id],
              ['status_id', self::active(Order::table)],
            ])->first();
            //Пользователь
            $user = User::where([
              ['id', $order->user_id]
            ])->first();
        
        
            if ($order != null){
              //Вернули карту(недействительна)
              $order->status_id = self::remove(Order::table);
              $order->save();
        
              //Вернуть деньги пользователю
              $price_card = $order->card->price;
              $balance = $order->user->balance;
                $user->balance = $balance + $price_card;
                $user->save();
        
              if($order->card->base_id != null){
                //Забираем монету у владельца базы
                $seller = User::where('id', $order->card->bases->user_id)->first();
                $new_balance_seller = (int)$seller->balance - (int)$price_card * 0.7;
                User::where('id', $order->card->bases->user_id)->update([
                  'balance' => round($new_balance_seller,2),
                ]);
              }
            }
        }

        return 200;
    }
Leave a Comment