This commit is contained in:
sl 2022-08-18 16:27:48 +08:00
commit 829ecfb759
18 changed files with 111 additions and 36 deletions

View File

@ -42,15 +42,15 @@ class CartRepo
$cart = Cart::query()->create([
'customer_id' => $customerId,
'shipping_address_id' => $defaultAddressId,
'shipping_method_code' => $shippingMethod->code,
'shipping_method_code' => $shippingMethod->code ?? '',
'payment_address_id' => $defaultAddressId,
'payment_method_code' => $paymentMethod->code
'payment_method_code' => $paymentMethod->code ?? ''
]);
} else {
if ($cart->shipping_address_id == 0) {
if ($cart->shipping_address_id == 0 || empty(AddressRepo::find($cart->shipping_address_id))) {
$cart->shipping_address_id = $defaultAddressId;
}
if ($cart->payment_address_id == 0) {
if ($cart->payment_address_id == 0 || empty(AddressRepo::find($cart->payment_address_id))) {
$cart->payment_address_id = $defaultAddressId;
}
$cart->save();

View File

@ -157,4 +157,30 @@ class PluginRepo
return $plugin && $plugin->getEnabled();
});
}
/**
* 检测对应配送方式是否可用
*
* @param $code
* @return bool
*/
public static function shippingEnabled($code): bool
{
$shippingMethods = self::getShippingMethods();
return $shippingMethods->where('code', $code)->count() > 0;
}
/**
* 检测对应支付方式是否可用
*
* @param $code
* @return bool
*/
public static function paymentEnabled($code): bool
{
$paymentMethods = self::getPaymentMethods();
return $paymentMethods->where('code', $code)->count() > 0;
}
}

View File

@ -96,6 +96,9 @@ class OrderController extends Controller
{
$customer = current_customer();
$order = OrderRepo::getOrderByNumber($number, $customer);
if (empty($order)) {
throw new \Exception('无效的订单');
}
StateMachineService::getInstance($order)->changeStatus(StateMachineService::COMPLETED);
return json_success(trans('shop/account.order_completed'));
}

View File

@ -53,10 +53,6 @@ class CheckoutController extends Controller
*/
public function confirm()
{
try {
return (new CheckoutService)->confirm();
} catch (\Exception $e) {
return json_fail($e->getMessage());
}
return (new CheckoutService)->confirm();
}
}

View File

@ -11,9 +11,9 @@
namespace Beike\Shop\Services;
use Beike\Repositories\CartRepo;
use Exception;
use Beike\Models\CartProduct;
use Beike\Repositories\CartRepo;
use Beike\Shop\Http\Resources\CartDetail;
class CartService
@ -116,6 +116,12 @@ class CartService
}
/**
* 删除购物车商品
*
* @param $customer
* @param $cartId
*/
public static function delete($customer, $cartId)
{
if (empty($cartId)) {
@ -149,6 +155,6 @@ class CartService
'amount' => $amount,
'amount_format' => currency_format($amount),
];
return $data;
return hook_filter('cart.data', $data);
}
}

View File

@ -12,6 +12,7 @@
namespace Beike\Shop\Services;
use Beike\Models\Order;
use Beike\Models\Address;
use Beike\Models\Customer;
use Beike\Repositories\CartRepo;
use Beike\Repositories\OrderRepo;
@ -88,6 +89,7 @@ class CheckoutService
$customer = current_customer();
$checkoutData = self::checkoutData();
$checkoutData['customer'] = $customer;
$this->validateConfirm($checkoutData);
try {
DB::beginTransaction();
@ -102,6 +104,35 @@ class CheckoutService
}
/**
* @throws \Exception
*/
private function validateConfirm($checkoutData)
{
$current = $checkoutData['current'];
$shippingAddressId = $current['shipping_address_id'];
if (empty(Address::query()->find($shippingAddressId))) {
throw new \Exception('配送地址无效');
}
$paymentAddressId = $current['payment_address_id'];
if (empty(Address::query()->find($paymentAddressId))) {
throw new \Exception('账单地址无效');
}
$shippingMethodCode = $current['shipping_method_code'];
if (!PluginRepo::shippingEnabled($shippingMethodCode)) {
throw new \Exception('配送方式不可用');
}
$paymentMethodCode = $current['payment_method_code'];
if (!PluginRepo::paymentEnabled($paymentMethodCode)) {
throw new \Exception('支付方式不可用');
}
}
private function updateShippingAddressId($shippingAddressId)
{
$this->cart->update(['shipping_address_id' => $shippingAddressId]);

View File

@ -59,15 +59,15 @@
</el-form-item>
<el-form-item label="右符号">
<el-input v-model="dialog.form.symbol_right" placeholder="符号"></el-input>
<el-input v-model="dialog.form.symbol_right" placeholder="符号"></el-input>
</el-form-item>
<el-form-item label="小数位数" prop="decimal_place">
<el-input v-model="dialog.form.decimal_place" placeholder="左符号"></el-input>
<el-input v-model="dialog.form.decimal_place" placeholder="小数位数"></el-input>
</el-form-item>
<el-form-item label="汇率值" prop="value">
<el-input v-model="dialog.form.value" placeholder="左符号"></el-input>
<el-input v-model="dialog.form.value" placeholder="汇率值"></el-input>
</el-form-item>
<el-form-item label=" 状态">

View File

@ -41,18 +41,16 @@
<th>#</th>
<th>名称</th>
<th>电话</th>
<th>注册来源</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody v-if="addresses.length">
<tr v-for="address, index in addresses" :key="index">
<td>@{{ index }}</td>
<td>@{{ index + 1}}</td>
<td>@{{ address.name }}</td>
<td>@{{ address.phone }}</td>
<td>222</td>
<td>222</td>
<td>@{{ address.created_at }}</td>
<td>
<button class="btn btn-outline-secondary btn-sm" type="button"
@click="editAddress(index)">编辑</button>
@ -283,6 +281,8 @@
closeAddressDialog(form) {
this.$refs[form].resetFields();
Object.keys(this.dialogAddress.form).forEach(key => this.dialogAddress.form[key] = '')
this.dialogAddress.form.country_id = @json((int)system_setting('base.country_id'));
this.dialogAddress.show = false
this.dialogAddress.index = null;
},

View File

@ -143,7 +143,7 @@
$http.post('customers', this.dialogCustomers.form).then((res) => {
this.$message.success(res.message);
this.customers.push(res.data);
this.loadData();// this.customers.data.push(res.data);
this.dialogCustomers.show = false
})
});

View File

@ -162,7 +162,7 @@
},
rules: {
status: [{required: true, message: '请输入用户名', trigger: 'blur'}, ],
status: [{required: true, message: '请选择状态', trigger: 'blur'}, ],
}
},

View File

@ -41,7 +41,7 @@
</div>
</td>
<td>
<el-switch :disabled="!plugin.installed" v-model="plugin.status" @change="(e) => {pluginStatusChange(e, plugin.code)}"></el-switch>
<el-switch :disabled="!plugin.installed" v-model="plugin.status" @change="(e) => {pluginStatusChange(e, plugin.code, index)}"></el-switch>
</td>
<td>
<div v-if="plugin.installed">
@ -74,12 +74,14 @@
},
methods: {
pluginStatusChange(e, code) {
pluginStatusChange(e, code, index) {
const self = this;
$http.put(`plugins/${code}/status`, {status: e * 1}).then((res) => {
layer.msg(res.message)
})
}).catch((res) => {
this.plugins[index].status = !this.plugins[index].status;
});
},
uploadFile(file) {

View File

@ -83,7 +83,7 @@
<div class="help-text font-size-12 lh-base">网站前台显示 380*100</div>
</x-admin-form-image>
<x-admin-form-image name="favicon" title="favicon" :value="old('web_icon', system_setting('base.web_icon', ''))">
<x-admin-form-image name="favicon" title="favicon" :value="old('favicon', system_setting('base.favicon', ''))">
<div class="help-text font-size-12 lh-base">显示在浏览器选项卡上的小图标必须为PNG格式大小为32*32</div>
</x-admin-form-image>

View File

@ -14,7 +14,7 @@ return [
'plugins_import' => 'Import',
'plugins_show' => 'Detail',
'plugins_update' => 'Update',
'plugins_update_status' => 'Delete',
'plugins_update_status' => 'Update Status',
'plugins_install' => 'Install',
'plugins_uninstall' => 'Uninstall',

View File

@ -14,7 +14,7 @@ return [
'plugins_import' => '上传插件',
'plugins_show' => '插件详情',
'plugins_update' => '插件更新',
'plugins_update_status' => '删除插件',
'plugins_update_status' => '更新状态',
'plugins_install' => '安装',
'plugins_uninstall' => '卸载',

View File

@ -54,7 +54,7 @@
class="text-muted">{{ __('shop/account.after_sales') }}</span></a>
</div>
<div class="order-wrap">
@if (!$latest_orders)
@if (!count($latest_orders))
<div class="no-order d-flex flex-column align-items-center">
<div class="icon mb-2"><i class="iconfont">&#xe60b;</i></div>
<div class="text mb-3 text-muted">{{ __('shop/account.no_order') }}<a href="">{{ __('shop/account.to_buy') }}</a></div>

View File

@ -147,7 +147,7 @@
@push('add-scripts')
<script>
$('.shipped-ed').click(function(event) {
$http.post('orders/{{ $order->id }}/complete').then((res) => {
$http.post('orders/{{ $order->number }}/complete').then((res) => {
layer.msg(res.message)
window.location.reload()
})

View File

@ -107,7 +107,7 @@
@endforeach
</ul>
<div class="d-grid gap-2 mt-3">
<button class="btn btn-primary" type="button" @click="checkedBtnCheckoutConfirm">提交订单</button>
<button class="btn btn-primary" type="button" :disabled="!isSubmit" @click="checkedBtnCheckoutConfirm">提交订单</button>
</div>
</div>
</div>
@ -168,6 +168,10 @@
// 计算属性
computed: {
isSubmit() {
// source.addresses.length > 0 && source.payment_methods.length > 0 && source.shipping_methods.length > 0
return this.source.addresses.length > 0 && this.source.payment_methods.length > 0 && this.source.shipping_methods.length > 0;
},
// isAddress: {
// this.form.shipping_address_id ==
// }

View File

@ -5,18 +5,25 @@
<div class="account-name">{{ $customer->name }}</div>
<div class="account-email">{{ $customer->email }}</div>
</div>
<nav class="list-group account-links">
<a class="list-group-item d-flex justify-content-between align-items-center active" href="{{ shop_route('account.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.index') ? 'active' : '' }}"
href="{{ shop_route('account.index') }}">
<span>{{ __('shop/account.index') }}</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.edit.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.edit.index') ? 'active' : '' }}"
href="{{ shop_route('account.edit.index') }}">
<span>修改个人信息</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.order.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.order.index') || equal_route('shop.account.order.show') ? 'active' : '' }}"
href="{{ shop_route('account.order.index') }}">
<span>我的订单</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.addresses.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.addresses.index') ? 'active' : '' }}"
href="{{ shop_route('account.addresses.index') }}">
<span>我的地址</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.wishlist.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.wishlist.index') ? 'active' : '' }}"
href="{{ shop_route('account.wishlist.index') }}">
<span>我的收藏</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.rma.index') }}">
<a class="list-group-item d-flex justify-content-between align-items-center {{ equal_route('shop.account.rma.index') || equal_route('shop.account.rma.show') ? 'active' : '' }}"
href="{{ shop_route('account.rma.index') }}">
<span>我的售后</span></a>
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('logout') }}">
<span>退出登录</span></a>