diff --git a/app/Services/SubmissionManager.php b/app/Services/SubmissionManager.php index 2b5937c016..7e920cd675 100644 --- a/app/Services/SubmissionManager.php +++ b/app/Services/SubmissionManager.php @@ -19,463 +19,7 @@ use Settings; class SubmissionManager extends Service { -<<<<<<< HEAD -======= - /** - * Creates a new submission. - * - * @param array $data - * @param \App\Models\User\User $user - * @param bool $isClaim - * - * @return mixed - */ - public function createSubmission($data, $user, $isClaim = false) { - DB::beginTransaction(); - - try { - // 1. check that the prompt can be submitted at this time - // 2. check that the characters selected exist (are visible too) - // 3. check that the currencies selected can be attached to characters - if (!$isClaim && !Settings::get('is_prompts_open')) { - throw new \Exception('The prompt queue is closed for submissions.'); - } elseif ($isClaim && !Settings::get('is_claims_open')) { - throw new \Exception('The claim queue is closed for submissions.'); - } - if (!$isClaim && !isset($data['prompt_id'])) { - throw new \Exception('Please select a prompt.'); - } - if (!$isClaim) { - $prompt = Prompt::active()->where('id', $data['prompt_id'])->with('rewards')->first(); - if (!$prompt) { - throw new \Exception('Invalid prompt selected.'); - } - - if ($prompt->staff_only && !$user->isStaff) { - throw new \Exception('This prompt may only be submitted to by staff members.'); - } - } else { - $prompt = null; - } - - // The character identification comes in both the slug field and as character IDs - // that key the reward ID/quantity arrays. - // We'll need to match characters to the rewards for them. - // First, check if the characters are accessible to begin with. - if (isset($data['slug'])) { - $characters = Character::myo(0)->visible()->whereIn('slug', $data['slug'])->get(); - if (count($characters) != count($data['slug'])) { - throw new \Exception('One or more of the selected characters do not exist.'); - } - } else { - $characters = []; - } - - $userAssets = createAssetsArray(); - - // Attach items. Technically, the user doesn't lose ownership of the item - we're just adding an additional holding field. - // We're also not going to add logs as this might add unnecessary fluff to the logs and the items still belong to the user. - if (isset($data['stack_id'])) { - foreach ($data['stack_id'] as $stackId) { - $stack = UserItem::with('item')->find($stackId); - if (!$stack || $stack->user_id != $user->id) { - throw new \Exception('Invalid item selected.'); - } - if (!isset($data['stack_quantity'][$stackId])) { - throw new \Exception('Invalid quantity selected.'); - } - $stack->submission_count += $data['stack_quantity'][$stackId]; - $stack->save(); - - addAsset($userAssets, $stack, $data['stack_quantity'][$stackId]); - } - } - - // Attach currencies. - if (isset($data['currency_id'])) { - foreach ($data['currency_id'] as $holderKey=> $currencyIds) { - $holder = explode('-', $holderKey); - $holderType = $holder[0]; - $holderId = $holder[1]; - - $holder = User::find($holderId); - - $currencyManager = new CurrencyManager; - foreach ($currencyIds as $key=> $currencyId) { - $currency = Currency::find($currencyId); - if (!$currency) { - throw new \Exception('Invalid currency selected.'); - } - if ($data['currency_quantity'][$holderKey][$key] < 0) { - throw new \Exception('Cannot attach a negative amount of currency.'); - } - if (!$currencyManager->debitCurrency($holder, null, null, null, $currency, $data['currency_quantity'][$holderKey][$key])) { - throw new \Exception('Invalid currency/quantity selected.'); - } - - addAsset($userAssets, $currency, $data['currency_quantity'][$holderKey][$key]); - } - } - } - - // Get a list of rewards, then create the submission itself - $promptRewards = createAssetsArray(); - if (!$isClaim) { - foreach ($prompt->rewards as $reward) { - addAsset($promptRewards, $reward->reward, $reward->quantity); - } - } - $promptRewards = mergeAssetsArrays($promptRewards, $this->processRewards($data, false, null, $isClaim)); - $submission = Submission::create([ - 'user_id' => $user->id, - 'url' => $data['url'] ?? null, - 'status' => 'Pending', - 'comments' => $data['comments'], - 'data' => json_encode([ - 'user' => Arr::only(getDataReadyAssets($userAssets), ['user_items', 'currencies']), - 'rewards' => getDataReadyAssets($promptRewards), - ]), // list of rewards and addons - ] + ($isClaim ? [] : ['prompt_id' => $prompt->id])); - - // Retrieve all reward IDs for characters - $currencyIds = []; - $itemIds = []; - $tableIds = []; - if (isset($data['character_currency_id'])) { - foreach ($data['character_currency_id'] as $c) { - foreach ($c as $currencyId) { - $currencyIds[] = $currencyId; - } - } // Non-expanded character rewards - } elseif (isset($data['character_rewardable_id'])) { - $data['character_rewardable_id'] = array_map([$this, 'innerNull'], $data['character_rewardable_id']); - foreach ($data['character_rewardable_id'] as $ckey => $c) { - foreach ($c as $key => $id) { - switch ($data['character_rewardable_type'][$ckey][$key]) { - case 'Currency': $currencyIds[] = $id; - break; - case 'Item': $itemIds[] = $id; - break; - case 'LootTable': $tableIds[] = $id; - break; - } - } - } // Expanded character rewards - } - array_unique($currencyIds); - array_unique($itemIds); - array_unique($tableIds); - $currencies = Currency::whereIn('id', $currencyIds)->where('is_character_owned', 1)->get()->keyBy('id'); - $items = Item::whereIn('id', $itemIds)->get()->keyBy('id'); - $tables = LootTable::whereIn('id', $tableIds)->get()->keyBy('id'); - - // Attach characters - foreach ($characters as $c) { - // Users might not pass in clean arrays (may contain redundant data) so we need to clean that up - $assets = $this->processRewards($data + ['character_id' => $c->id, 'currencies' => $currencies, 'items' => $items, 'tables' => $tables], true); - // Now we have a clean set of assets (redundant data is gone, duplicate entries are merged) - // so we can attach the character to the submission - SubmissionCharacter::create([ - 'character_id' => $c->id, - 'submission_id' => $submission->id, - 'data' => json_encode(getDataReadyAssets($assets)), - ]); - } - - return $this->commitReturn($submission); - } catch (\Exception $e) { - $this->setError('error', $e->getMessage()); - } - - return $this->rollbackReturn(false); - } - - /** - * Rejects a submission. - * - * @param array $data - * @param \App\Models\User\User $user - * - * @return mixed - */ - public function rejectSubmission($data, $user) { - DB::beginTransaction(); - - try { - // 1. check that the submission exists - // 2. check that the submission is pending - if (!isset($data['submission'])) { - $submission = Submission::where('status', 'Pending')->where('id', $data['id'])->first(); - } elseif ($data['submission']->status == 'Pending') { - $submission = $data['submission']; - } else { - $submission = null; - } - if (!$submission) { - throw new \Exception('Invalid submission.'); - } - - // Return all added items - $addonData = $submission->data['user']; - if (isset($addonData['user_items'])) { - foreach ($addonData['user_items'] as $userItemId => $quantity) { - $userItemRow = UserItem::find($userItemId); - if (!$userItemRow) { - throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); - } - if ($userItemRow->submission_count < $quantity) { - throw new \Exception('Cannot return more items than was held. ('.$userItemId.')'); - } - $userItemRow->submission_count -= $quantity; - $userItemRow->save(); - } - } - - // And currencies - $currencyManager = new CurrencyManager; - if (isset($addonData['currencies']) && $addonData['currencies']) { - foreach ($addonData['currencies'] as $currencyId=> $quantity) { - $currency = Currency::find($currencyId); - if (!$currency) { - throw new \Exception('Cannot return an invalid currency. ('.$currencyId.')'); - } - if (!$currencyManager->creditCurrency(null, $submission->user, null, null, $currency, $quantity)) { - throw new \Exception('Could not return currency to user. ('.$currencyId.')'); - } - } - } - - if (isset($data['staff_comments']) && $data['staff_comments']) { - $data['parsed_staff_comments'] = parse($data['staff_comments']); - } else { - $data['parsed_staff_comments'] = null; - } - - // The only things we need to set are: - // 1. staff comment - // 2. staff ID - // 3. status - $submission->update([ - 'staff_comments' => $data['staff_comments'], - 'parsed_staff_comments' => $data['parsed_staff_comments'], - 'staff_id' => $user->id, - 'status' => 'Rejected', - ]); - - Notifications::create($submission->prompt_id ? 'SUBMISSION_REJECTED' : 'CLAIM_REJECTED', $submission->user, [ - 'staff_url' => $user->url, - 'staff_name' => $user->name, - 'submission_id' => $submission->id, - ]); - - if (!$this->logAdminAction($user, 'Submission Rejected', 'Rejected submission #'.$submission->id.'')) { - throw new \Exception('Failed to log admin action.'); - } - - return $this->commitReturn($submission); - } catch (\Exception $e) { - $this->setError('error', $e->getMessage()); - } - - return $this->rollbackReturn(false); - } - - /** - * Approves a submission. - * - * @param array $data - * @param \App\Models\User\User $user - * - * @return mixed - */ - public function approveSubmission($data, $user) { - DB::beginTransaction(); - - try { - // 1. check that the submission exists - // 2. check that the submission is pending - $submission = Submission::where('status', 'Pending')->where('id', $data['id'])->first(); - if (!$submission) { - throw new \Exception('Invalid submission.'); - } - - // Remove any added items, hold counts, and add logs - $addonData = $submission->data['user']; - $inventoryManager = new InventoryManager; - if (isset($addonData['user_items'])) { - $stacks = $addonData['user_items']; - foreach ($addonData['user_items'] as $userItemId => $quantity) { - $userItemRow = UserItem::find($userItemId); - if (!$userItemRow) { - throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); - } - if ($userItemRow->submission_count < $quantity) { - throw new \Exception('Cannot return more items than was held. ('.$userItemId.')'); - } - $userItemRow->submission_count -= $quantity; - $userItemRow->save(); - } - - // Workaround for user not being unset after inventory shuffling, preventing proper staff ID assignment - $staff = $user; - - foreach ($stacks as $stackId=> $quantity) { - $stack = UserItem::find($stackId); - $user = User::find($submission->user_id); - if (!$inventoryManager->debitStack($user, $submission->prompt_id ? 'Prompt Approved' : 'Claim Approved', ['data' => 'Item used in submission (#'.$submission->id.')'], $stack, $quantity)) { - throw new \Exception('Failed to create log for item stack.'); - } - } - - // Set user back to the processing staff member, now that addons have been properly processed. - $user = $staff; - } - - // Log currency removal, etc. - $currencyManager = new CurrencyManager; - if (isset($addonData['currencies']) && $addonData['currencies']) { - foreach ($addonData['currencies'] as $currencyId=> $quantity) { - $currency = Currency::find($currencyId); - if (!$currencyManager->createLog( - $submission->user_id, - 'User', - null, - null, - $submission->prompt_id ? 'Prompt Approved' : 'Claim Approved', - 'Used in '.($submission->prompt_id ? 'prompt' : 'claim').' (#'.$submission->id.')', - $currencyId, - $quantity - )) { - throw new \Exception('Failed to create currency log.'); - } - } - } - - // The character identification comes in both the slug field and as character IDs - // that key the reward ID/quantity arrays. - // We'll need to match characters to the rewards for them. - // First, check if the characters are accessible to begin with. - if (isset($data['slug'])) { - $characters = Character::myo(0)->visible()->whereIn('slug', $data['slug'])->get(); - if (count($characters) != count($data['slug'])) { - throw new \Exception('One or more of the selected characters do not exist.'); - } - } else { - $characters = []; - } - - // Get the updated set of rewards - $rewards = $this->processRewards($data, false, true); - - // Logging data - $promptLogType = $submission->prompt_id ? 'Prompt Rewards' : 'Claim Rewards'; - $promptData = [ - 'data' => 'Received rewards for '.($submission->prompt_id ? 'submission' : 'claim').' (#'.$submission->id.')', - ]; - - // Distribute user rewards - if (!$rewards = fillUserAssets($rewards, $user, $submission->user, $promptLogType, $promptData)) { - throw new \Exception('Failed to distribute rewards to user.'); - } - - // Retrieve all reward IDs for characters - $currencyIds = []; - $itemIds = []; - $tableIds = []; - if (isset($data['character_currency_id'])) { - foreach ($data['character_currency_id'] as $c) { - foreach ($c as $currencyId) { - $currencyIds[] = $currencyId; - } - } // Non-expanded character rewards - } elseif (isset($data['character_rewardable_id'])) { - $data['character_rewardable_id'] = array_map([$this, 'innerNull'], $data['character_rewardable_id']); - foreach ($data['character_rewardable_id'] as $ckey => $c) { - foreach ($c as $key => $id) { - switch ($data['character_rewardable_type'][$ckey][$key]) { - case 'Currency': $currencyIds[] = $id; - break; - case 'Item': $itemIds[] = $id; - break; - case 'LootTable': $tableIds[] = $id; - break; - } - } - } // Expanded character rewards - } - array_unique($currencyIds); - array_unique($itemIds); - array_unique($tableIds); - $currencies = Currency::whereIn('id', $currencyIds)->where('is_character_owned', 1)->get()->keyBy('id'); - $items = Item::whereIn('id', $itemIds)->get()->keyBy('id'); - $tables = LootTable::whereIn('id', $tableIds)->get()->keyBy('id'); - - // We're going to remove all characters from the submission and reattach them with the updated data - $submission->characters()->delete(); - - // Distribute character rewards - foreach ($characters as $c) { - // Users might not pass in clean arrays (may contain redundant data) so we need to clean that up - $assets = $this->processRewards($data + ['character_id' => $c->id, 'currencies' => $currencies, 'items' => $items, 'tables' => $tables], true); - - if (!$assets = fillCharacterAssets($assets, $user, $c, $promptLogType, $promptData, $submission->user)) { - throw new \Exception('Failed to distribute rewards to character.'); - } - - SubmissionCharacter::create([ - 'character_id' => $c->id, - 'submission_id' => $submission->id, - 'data' => json_encode(getDataReadyAssets($assets)), - ]); - } - - // Increment user submission count if it's a prompt - if ($submission->prompt_id) { - $user->settings->submission_count++; - $user->settings->save(); - } - - if (isset($data['staff_comments']) && $data['staff_comments']) { - $data['parsed_staff_comments'] = parse($data['staff_comments']); - } else { - $data['parsed_staff_comments'] = null; - } - - // Finally, set: - // 1. staff comments - // 2. staff ID - // 3. status - // 4. final rewards - $submission->update([ - 'staff_comments' => $data['staff_comments'], - 'parsed_staff_comments' => $data['parsed_staff_comments'], - 'staff_id' => $user->id, - 'status' => 'Approved', - 'data' => json_encode([ - 'user' => $addonData, - 'rewards' => getDataReadyAssets($rewards), - ]), // list of rewards - ]); - - Notifications::create($submission->prompt_id ? 'SUBMISSION_APPROVED' : 'CLAIM_APPROVED', $submission->user, [ - 'staff_url' => $user->url, - 'staff_name' => $user->name, - 'submission_id' => $submission->id, - ]); - - if (!$this->logAdminAction($user, 'Submission Approved', 'Approved submission #'.$submission->id.'')) { - throw new \Exception('Failed to log admin action.'); - } - - return $this->commitReturn($submission); - } catch (\Exception $e) { - $this->setError('error', $e->getMessage()); - } - - return $this->rollbackReturn(false); - } ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f /* |-------------------------------------------------------------------------- | Submission Manager @@ -486,9 +30,8 @@ public function approveSubmission($data, $user) { */ /** - * Helper function to remove all empty/zero/falsey values. + * Creates a new submission. * -<<<<<<< HEAD * @param array $data * @param \App\Models\User\User $user * @param bool $isClaim @@ -515,6 +58,10 @@ public function createSubmission($data, $user, $isClaim = false) { if (!$prompt) { throw new \Exception('Invalid prompt selected.'); } + + if ($prompt->staff_only && !$user->isStaff) { + throw new \Exception('This prompt may only be submitted to by staff members.'); + } } else { $prompt = null; } @@ -563,7 +110,7 @@ public function createSubmission($data, $user, $isClaim = false) { // Attach currencies. if (isset($data['currency_id'])) { - foreach ($data['currency_id'] as $holderKey=>$currencyIds) { + foreach ($data['currency_id'] as $holderKey=> $currencyIds) { $holder = explode('-', $holderKey); $holderType = $holder[0]; $holderId = $holder[1]; @@ -571,7 +118,7 @@ public function createSubmission($data, $user, $isClaim = false) { $holder = User::find($holderId); $currencyManager = new CurrencyManager; - foreach ($currencyIds as $key=>$currencyId) { + foreach ($currencyIds as $key=> $currencyId) { $currency = Currency::find($currencyId); if (!$currency) { throw new \Exception('Invalid currency selected.'); @@ -595,16 +142,15 @@ public function createSubmission($data, $user, $isClaim = false) { addAsset($promptRewards, $reward->reward, $reward->quantity); } } - $promptRewards = mergeAssetsArrays($promptRewards, $this->processRewards($data, false)); - + $promptRewards = mergeAssetsArrays($promptRewards, $this->processRewards($data, false, null, $isClaim)); $submission = Submission::create([ 'user_id' => $user->id, 'url' => $data['url'] ?? null, 'status' => 'Pending', 'comments' => $data['comments'], 'data' => json_encode([ - 'user' => Arr::only(getDataReadyAssets($userAssets), ['user_items', 'currencies']), - 'rewards' => getDataReadyAssets($promptRewards), + 'user' => Arr::only(getDataReadyAssets($userAssets), ['user_items', 'currencies']), + 'rewards' => getDataReadyAssets($promptRewards), 'criterion' => $data['criterion'] ?? null, ]), // list of rewards and addons ] + ($isClaim ? [] : ['prompt_id' => $prompt->id])); @@ -622,7 +168,7 @@ public function createSubmission($data, $user, $isClaim = false) { } elseif (isset($data['character_rewardable_id'])) { $data['character_rewardable_id'] = array_map([$this, 'innerNull'], $data['character_rewardable_id']); foreach ($data['character_rewardable_id'] as $ckey => $c) { - foreach ($c as $key => $id) { + foreach ($c as $key => $id) { switch ($data['character_rewardable_type'][$ckey][$key]) { case 'Currency': $currencyIds[] = $id; break; @@ -707,7 +253,7 @@ public function rejectSubmission($data, $user) { // And currencies $currencyManager = new CurrencyManager; if (isset($addonData['currencies']) && $addonData['currencies']) { - foreach ($addonData['currencies'] as $currencyId=>$quantity) { + foreach ($addonData['currencies'] as $currencyId=> $quantity) { $currency = Currency::find($currencyId); if (!$currency) { throw new \Exception('Cannot return an invalid currency. ('.$currencyId.')'); @@ -741,6 +287,10 @@ public function rejectSubmission($data, $user) { 'submission_id' => $submission->id, ]); + if (!$this->logAdminAction($user, 'Submission Rejected', 'Rejected submission #'.$submission->id.'')) { + throw new \Exception('Failed to log admin action.'); + } + return $this->commitReturn($submission); } catch (\Exception $e) { $this->setError('error', $e->getMessage()); @@ -788,7 +338,7 @@ public function approveSubmission($data, $user) { // Workaround for user not being unset after inventory shuffling, preventing proper staff ID assignment $staff = $user; - foreach ($stacks as $stackId=>$quantity) { + foreach ($stacks as $stackId=> $quantity) { $stack = UserItem::find($stackId); $user = User::find($submission->user_id); if (!$inventoryManager->debitStack($user, $submission->prompt_id ? 'Prompt Approved' : 'Claim Approved', ['data' => 'Item used in submission (#'.$submission->id.')'], $stack, $quantity)) { @@ -803,7 +353,7 @@ public function approveSubmission($data, $user) { // Log currency removal, etc. $currencyManager = new CurrencyManager; if (isset($addonData['currencies']) && $addonData['currencies']) { - foreach ($addonData['currencies'] as $currencyId=>$quantity) { + foreach ($addonData['currencies'] as $currencyId=> $quantity) { $currency = Currency::find($currencyId); if (!$currencyManager->createLog( $submission->user_id, @@ -872,7 +422,7 @@ public function approveSubmission($data, $user) { } elseif (isset($data['character_rewardable_id'])) { $data['character_rewardable_id'] = array_map([$this, 'innerNull'], $data['character_rewardable_id']); foreach ($data['character_rewardable_id'] as $ckey => $c) { - foreach ($c as $key => $id) { + foreach ($c as $key => $id) { switch ($data['character_rewardable_type'][$ckey][$key]) { case 'Currency': $currencyIds[] = $id; break; @@ -933,8 +483,8 @@ public function approveSubmission($data, $user) { 'staff_id' => $user->id, 'status' => 'Approved', 'data' => json_encode([ - 'user' => $addonData, - 'rewards' => getDataReadyAssets($rewards), + 'user' => $addonData, + 'rewards' => getDataReadyAssets($rewards), 'criterion' => $data['criterion'] ?? null, ]), // list of rewards ]); @@ -945,6 +495,10 @@ public function approveSubmission($data, $user) { 'submission_id' => $submission->id, ]); + if (!$this->logAdminAction($user, 'Submission Approved', 'Approved submission #'.$submission->id.'')) { + throw new \Exception('Failed to log admin action.'); + } + return $this->commitReturn($submission); } catch (\Exception $e) { $this->setError('error', $e->getMessage()); @@ -953,12 +507,13 @@ public function approveSubmission($data, $user) { return $this->rollbackReturn(false); } -======= + /** + * Helper function to remove all empty/zero/falsey values. + * * @param array $value * * @return array */ ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f private function innerNull($value) { return array_values(array_filter($value)); } diff --git a/app/Services/TradeManager.php b/app/Services/TradeManager.php index d41c04cbf6..9b6cc1ae16 100644 --- a/app/Services/TradeManager.php +++ b/app/Services/TradeManager.php @@ -387,13 +387,10 @@ public function rejectTrade($data, $user) { 'trade_id' => $trade->id, ]); -<<<<<<< HEAD -======= if (!$this->logAdminAction($user, 'Rejected Trade', 'Rejected trade #'.$trade->id.'')) { throw new \Exception('Failed to log admin action.'); } ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $trade->reason = $data['reason'] ?? ''; $trade->status = 'Rejected'; $trade->staff_id = $user->id; @@ -431,12 +428,8 @@ private function handleTradeAssets($trade, $data, $user) { // First return any item stacks attached to the trade if (isset($tradeData[$type]['user_items'])) { -<<<<<<< HEAD - foreach ($tradeData[$type]['user_items'] as $userItemId=>$quantity) { -======= foreach ($tradeData[$type]['user_items'] as $userItemId=> $quantity) { $quantity = (int) $quantity; ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $userItemRow = UserItem::find($userItemId); if (!$userItemRow) { throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); @@ -453,12 +446,8 @@ private function handleTradeAssets($trade, $data, $user) { // This is stored in the data attribute $currencyManager = new CurrencyManager; if (isset($tradeData[$type]['currencies'])) { -<<<<<<< HEAD - foreach ($tradeData[$type]['currencies'] as $currencyId=>$quantity) { -======= foreach ($tradeData[$type]['currencies'] as $currencyId=> $quantity) { $quantity = (int) $quantity; ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $currencyManager->creditCurrency(null, $user, null, null, $currencyId, $quantity); } } @@ -484,11 +473,7 @@ private function handleTradeAssets($trade, $data, $user) { if (!$stack->item->allow_transfer || isset($stack->data['disallow_transfer'])) { throw new \Exception('One or more of the selected items cannot be transferred.'); } -<<<<<<< HEAD - $stack->trade_count += $data['stack_quantity'][$stackId]; -======= $stack->trade_count += intval($data['stack_quantity'][$stackId]); ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $stack->save(); addAsset($userAssets, $stack, intval($data['stack_quantity'][$stackId])); @@ -507,20 +492,12 @@ private function handleTradeAssets($trade, $data, $user) { //dd([$data['currency_id'], $data['currency_quantity']]); $data['currency_id'] = $data['currency_id']['user-'.$user->id]; $data['currency_quantity'] = $data['currency_quantity']['user-'.$user->id]; -<<<<<<< HEAD - foreach ($data['currency_id'] as $key=>$currencyId) { -======= foreach ($data['currency_id'] as $key=> $currencyId) { ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $currency = Currency::where('allow_user_to_user', 1)->where('id', $currencyId)->first(); if (!$currency) { throw new \Exception('Invalid currency selected.'); } -<<<<<<< HEAD - if (!$currencyManager->debitCurrency($user, null, null, null, $currency, $data['currency_quantity'][$key])) { -======= if (!$currencyManager->debitCurrency($user, null, null, null, $currency, intval($data['currency_quantity'][$key]))) { ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f throw new \Exception('Invalid currency/quantity selected.'); } @@ -590,10 +567,7 @@ private function returnAttachments($trade) { foreach (['sender', 'recipient'] as $type) { if (isset($tradeData[$type]['user_items'])) { foreach ($tradeData[$type]['user_items'] as $userItemId => $quantity) { -<<<<<<< HEAD -======= $quantity = (int) $quantity; ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $userItemRow = UserItem::find($userItemId); if (!$userItemRow) { throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); @@ -612,10 +586,7 @@ private function returnAttachments($trade) { foreach (['sender', 'recipient'] as $type) { if (isset($tradeData[$type]['currencies'])) { foreach ($tradeData[$type]['currencies'] as $currencyId => $quantity) { -<<<<<<< HEAD -======= $quantity = (int) $quantity; ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $currency = Currency::find($currencyId); if (!$currency) { throw new \Exception('Cannot return an invalid currency. ('.$currencyId.')'); @@ -666,17 +637,10 @@ private function creditAttachments($trade, $data = []) { $inventoryManager->moveStack($trade->sender, $trade->recipient, 'Trade', ['data' => 'Received in trade [#'.$trade->id.']'], $stack, $quantity); $userItemRow = UserItem::find($stack->id); if (!$userItemRow) { -<<<<<<< HEAD - throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); - } - if ($userItemRow->trade_count < $quantity) { - throw new \Exception('Cannot return more items than was held. ('.$userItemId.')'); -======= throw new \Exception('Cannot return an invalid item. ('.$userItemRow->id.')'); } if ($userItemRow->trade_count < $quantity) { throw new \Exception('Cannot return more items than was held. ('.$userItemRow->id.')'); ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f } $userItemRow->trade_count -= $quantity; $userItemRow->save(); @@ -689,17 +653,10 @@ private function creditAttachments($trade, $data = []) { $inventoryManager->moveStack($trade->recipient, $trade->sender, 'Trade', ['data' => 'Received in trade [#'.$trade->id.']'], $stack, $quantity); $userItemRow = UserItem::find($stack->id); if (!$userItemRow) { -<<<<<<< HEAD - throw new \Exception('Cannot return an invalid item. ('.$userItemId.')'); - } - if ($userItemRow->trade_count < $quantity) { - throw new \Exception('Cannot return more items than was held. ('.$userItemId.')'); -======= throw new \Exception('Cannot return an invalid item. ('.$userItemRow->id.')'); } if ($userItemRow->trade_count < $quantity) { throw new \Exception('Cannot return more items than was held. ('.$userItemRow->id.')'); ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f } $userItemRow->trade_count -= $quantity; $userItemRow->save(); @@ -731,10 +688,7 @@ private function creditAttachments($trade, $data = []) { $recipientType = ($type == 'sender') ? 'recipient' : 'sender'; if (isset($tradeData[$type]['currencies'])) { foreach ($tradeData[$type]['currencies'] as $currencyId => $quantity) { -<<<<<<< HEAD -======= $quantity = (int) $quantity; ->>>>>>> 0bd8f60b4c180aa79b99b732be933ad2eeed2a5f $currency = Currency::find($currencyId); if (!$currency) { throw new \Exception('Cannot credit an invalid currency. ('.$currencyId.')');