mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-24 22:11:01 -06:00
commit
4c81790ab5
@ -1,9 +1,9 @@
|
|||||||
<?php namespace Visiosoft\AdvsModule\Adv;
|
<?php namespace Visiosoft\AdvsModule\Adv;
|
||||||
|
|
||||||
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
|
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
|
||||||
|
use Anomaly\Streams\Platform\Message\MessageBag;
|
||||||
use Anomaly\Streams\Platform\Model\Advs\AdvsCustomFieldsEntryModel;
|
use Anomaly\Streams\Platform\Model\Advs\AdvsCustomFieldsEntryModel;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
|
use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
|
||||||
@ -112,10 +112,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
|||||||
public function foreignCurrency($currency, $price, $isUpdate, $settings)
|
public function foreignCurrency($currency, $price, $isUpdate, $settings)
|
||||||
{
|
{
|
||||||
$currencies = setting_value('visiosoft.module.advs::enabled_currencies');
|
$currencies = setting_value('visiosoft.module.advs::enabled_currencies');
|
||||||
|
$messages = app(MessageBag::class);
|
||||||
$foreign_currency = array();
|
$foreign_currency = array();
|
||||||
|
|
||||||
$client = new Client();
|
|
||||||
|
|
||||||
foreach ($currencies as $currencyIn) {
|
foreach ($currencies as $currencyIn) {
|
||||||
if ($currencyIn == $currency) {
|
if ($currencyIn == $currency) {
|
||||||
$foreign_currency[$currency] = (int)$price;
|
$foreign_currency[$currency] = (int)$price;
|
||||||
@ -123,8 +122,14 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
|||||||
try {
|
try {
|
||||||
$url = $currency . "_" . $currencyIn;
|
$url = $currency . "_" . $currencyIn;
|
||||||
$freeCurrencyKey = $settings->value('visiosoft.module.advs::free_currencyconverterapi_key');
|
$freeCurrencyKey = $settings->value('visiosoft.module.advs::free_currencyconverterapi_key');
|
||||||
$response = $client->get('http://free.currencyconverterapi.com/api/v6/convert?q='
|
|
||||||
. $url . '&compact=y&apiKey=' . $freeCurrencyKey);
|
$client = new \GuzzleHttp\Client();
|
||||||
|
$response = $client->request('GET', 'http://free.currencyconverterapi.com/api/v6/convert', ['query' => [
|
||||||
|
'q' => $url,
|
||||||
|
'compact' => 'y',
|
||||||
|
'apiKey' => $freeCurrencyKey
|
||||||
|
]]);
|
||||||
|
|
||||||
if ($response->getStatusCode() == '200') {
|
if ($response->getStatusCode() == '200') {
|
||||||
$response = (array)\GuzzleHttp\json_decode($response->getBody()->getContents());
|
$response = (array)\GuzzleHttp\json_decode($response->getBody()->getContents());
|
||||||
if (!empty($response)) {
|
if (!empty($response)) {
|
||||||
@ -132,8 +137,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
|||||||
$foreign_currency[$currencyIn] = $price * $rate;
|
$foreign_currency[$currencyIn] = $price * $rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||||
$this->messages->error((!is_null($e->getMessage())) ? $e->getMessage() : trans('streams::error.500.message'));
|
$response = $e->getResponse();
|
||||||
|
$responseBodyAsString = $response->getBody()->getContents();
|
||||||
|
$response = json_decode($responseBodyAsString, true);
|
||||||
|
$messages->error($response['error']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,20 +102,26 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
|
|||||||
if (!empty($param['user'])) {
|
if (!empty($param['user'])) {
|
||||||
$query = $query->where('advs_advs.created_by_id', $param['user']);
|
$query = $query->where('advs_advs.created_by_id', $param['user']);
|
||||||
}
|
}
|
||||||
|
$currency = setting_value('streams::currency');
|
||||||
|
|
||||||
if (!empty($param['currency'])) {
|
if (!empty($param['currency'])) {
|
||||||
if (!empty($param['min_price'])) {
|
$currency = $param['currency'];
|
||||||
$num = $param['min_price'];
|
|
||||||
$int = (int)$num;
|
|
||||||
$column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') >=" . $int;
|
|
||||||
$query = $query->whereRaw($column);
|
|
||||||
}
|
|
||||||
if (!empty($param['max_price'])) {
|
|
||||||
$num = $param['max_price'];
|
|
||||||
$int = (int)$num;
|
|
||||||
$column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') <=" . $int;
|
|
||||||
$query = $query->whereRaw($column);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($param['min_price'])) {
|
||||||
|
$num = $param['min_price'];
|
||||||
|
$int = (int)$num;
|
||||||
|
$column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') >= " . $int;
|
||||||
|
$query = $query->whereRaw($column);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($param['max_price'])) {
|
||||||
|
$num = $param['max_price'];
|
||||||
|
$int = (int)$num;
|
||||||
|
$column = "JSON_EXTRACT(foreign_currencies, '$." . $currency . "') <= " . $int;
|
||||||
|
$query = $query->whereRaw($column);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($param['date'])) {
|
if (!empty($param['date'])) {
|
||||||
if ($param['date'] === 'day') {
|
if ($param['date'] === 'day') {
|
||||||
$query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDay());
|
$query = $query->where('advs_advs.publish_at', '>=', Carbon::now()->subDay());
|
||||||
|
|||||||
@ -13,7 +13,9 @@ class ConvertCurrency extends ActionHandler
|
|||||||
|
|
||||||
foreach ($selected as $id) {
|
foreach ($selected as $id) {
|
||||||
$entry = $model->newQuery()->find($id);
|
$entry = $model->newQuery()->find($id);
|
||||||
$model->foreignCurrency($entry->currency, $entry->price, $id, $settingRepository);
|
if ($entry) {
|
||||||
|
$model->foreignCurrency($entry->currency, $entry->price, $id, $settingRepository);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($selected) {
|
if ($selected) {
|
||||||
$this->messages->success(trans('visiosoft.module.advs::message.currency_converted'));
|
$this->messages->success(trans('visiosoft.module.advs::message.currency_converted'));
|
||||||
|
|||||||
@ -120,4 +120,22 @@ class AdvsModulePlugin extends Plugin
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the filters.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFilters()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new \Twig_SimpleFilter(
|
||||||
|
'ksort',
|
||||||
|
function (array $array) {
|
||||||
|
ksort($array);
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,21 +43,5 @@ class ProfileModuleSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
// Users Fields Seeder
|
// Users Fields Seeder
|
||||||
$this->call(UsersFieldsSeeder::class);
|
$this->call(UsersFieldsSeeder::class);
|
||||||
|
|
||||||
if (is_null($this->folders->findBy('slug', 'favicon'))) {
|
|
||||||
$disk = $this->disks->findBySlug('local');
|
|
||||||
|
|
||||||
$this->folders->create([
|
|
||||||
'en' => [
|
|
||||||
'name' => 'Favicon',
|
|
||||||
'description' => 'A folder for Favicon.',
|
|
||||||
],
|
|
||||||
'slug' => 'favicon',
|
|
||||||
'disk' => $disk,
|
|
||||||
'allowed_types' => [
|
|
||||||
'ico','png',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,5 +156,23 @@ class DatabaseSeeder extends Seeder
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Favicon Folder
|
||||||
|
if (is_null($this->folders->findBy('slug', 'favicon'))) {
|
||||||
|
$disk = $this->disks->findBySlug('local');
|
||||||
|
|
||||||
|
$this->folders->create([
|
||||||
|
'en' => [
|
||||||
|
'name' => 'Favicon',
|
||||||
|
'description' => 'A folder for Favicon.',
|
||||||
|
],
|
||||||
|
'slug' => 'favicon',
|
||||||
|
'disk' => $disk,
|
||||||
|
'allowed_types' => [
|
||||||
|
'ico','png',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user