Edward Yang 2023-05-10 09:59:17 +08:00
parent 4ef9eeac5b
commit 8fcd26dcd7
7 changed files with 84 additions and 64 deletions

View File

@ -12,6 +12,7 @@
namespace Beike\Admin\Http\Controllers;
use Beike\Admin\Http\Requests\CurrencyRequest;
use Beike\Models\Order;
use Beike\Repositories\CurrencyRepo;
use Illuminate\Http\Request;
@ -66,9 +67,19 @@ class CurrencyController extends Controller
public function destroy(Request $request, int $currencyId)
{
try {
$currency = CurrencyRepo::find($currencyId);
$orderExist = Order::query()->where('currency_code', $currency->code)->exists();
if ($orderExist) {
throw new \Exception(trans('admin/currency.order_exist'));
}
CurrencyRepo::delete($currencyId);
hook_action('admin.currency.destroy.after', $currencyId);
return json_success(trans('common.deleted_success'));
} catch (\Exception $e) {
return json_fail($e->getMessage());
}
}
}

View File

@ -42,12 +42,17 @@ class CurrencyService
return $amount;
}
$symbol_left = $this->currencies[$currency]->symbol_left;
$symbol_right = $this->currencies[$currency]->symbol_right;
$decimal_place = $this->currencies[$currency]->decimal_place;
$currencyRow = $this->currencies[$currency] ?? null;
if (empty($currencyRow)) {
return $amount;
}
$symbol_left = $currencyRow->symbol_left;
$symbol_right = $currencyRow->symbol_right;
$decimal_place = $currencyRow->decimal_place;
if (! $value) {
$value = $this->currencies[$currency]->value;
$value = $currencyRow->value;
}
$amount = $value ? (float) $amount * $value : (float) $amount;

View File

@ -16,4 +16,5 @@ return [
'currencies_show' => 'Detail',
'currencies_update' => 'Edit',
'currencies_delete' => 'Delete',
'order_exist' => 'This currency has orders in use and cannot be deleted!',
];

View File

@ -16,4 +16,6 @@ return [
'currencies_show' => '货币详情',
'currencies_update' => '更新货币',
'currencies_delete' => '删除货币',
'order_exist' => '该货币有订单正在使用, 无法删除!',
];

View File

@ -16,4 +16,5 @@ return [
'currencies_show' => '貨幣詳情',
'currencies_update' => '更新貨幣',
'currencies_delete' => '刪除貨幣',
'order_exist' => '該貨幣有訂單正在使用,無法删除!',
];