vip
parent
fec7c689cf
commit
73ed204da2
|
|
@ -2,18 +2,37 @@
|
|||
|
||||
namespace App\Admin\Controllers\Store;
|
||||
|
||||
use Dcat\Admin\{Form, Grid, Admin};
|
||||
use Dcat\Admin\{Form, Grid, Admin, Show};
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use App\Models\Order;
|
||||
use App\Models\{Order, OrderProduct, OrderPackage};
|
||||
use App\Enums\PayWay;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Widgets\{Box, Tab, Card};
|
||||
|
||||
class OrderController extends AdminController
|
||||
{
|
||||
public $statusMap = [
|
||||
0 => '待付款',
|
||||
1 => '待发货',
|
||||
2 => '发货中',
|
||||
3 => '已发货',
|
||||
9 => '已完成',
|
||||
10 => '已取消',
|
||||
];
|
||||
public $statusColor = [
|
||||
0 => 'primary',
|
||||
1 => 'warning',
|
||||
2 => 'danger',
|
||||
3 => 'success',
|
||||
9 => 'success',
|
||||
10 => '#b3b9bf',
|
||||
];
|
||||
protected $translation = 'store-order';
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(Order::with(['user', 'inviter']));
|
||||
$grid->model()->whereNotNull('inviter_id');
|
||||
$grid->model()->whereNotNull('inviter_id')->orderBy('created_at', 'desc');
|
||||
|
||||
$grid->column('sn')->copyable();
|
||||
$grid->column('user.phone')->copyable();
|
||||
|
|
@ -22,27 +41,15 @@ class OrderController extends AdminController
|
|||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('sales_value');
|
||||
$grid->column('order_status')->using([
|
||||
0 => '待付款',
|
||||
1 => '待发货',
|
||||
2 => '发货中',
|
||||
3 => '已发货',
|
||||
9 => '已完成',
|
||||
10 => '已取消',
|
||||
])->dot([
|
||||
0=>'primary',
|
||||
1=>'warning',
|
||||
2=>'danger',
|
||||
3=>'success',
|
||||
9=>'success',
|
||||
10=>'#b3b9bf',
|
||||
]);
|
||||
$grid->column('order_status')->using($this->statusMap)->dot($this->statusColor);
|
||||
$grid->column('pay_way')->display(function ($v) {
|
||||
return $v?->mallText();
|
||||
})->circleDot(PayWay::colors());
|
||||
$grid->column('pay_at');
|
||||
$grid->column('created_at');
|
||||
|
||||
$grid->showViewButton();
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('sn')->width(3);
|
||||
|
|
@ -52,4 +59,88 @@ class OrderController extends AdminController
|
|||
});
|
||||
return $grid;
|
||||
}
|
||||
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = Show::make($id, Order::with(['user', 'inviter']));
|
||||
$show->field('id');
|
||||
$show->field('sn');
|
||||
$show->field('user.phone');
|
||||
$show->field('inviter.phone');
|
||||
$show->field('total_amount')->as(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
});
|
||||
$show->field('sales_value');
|
||||
$show->field('order_status')->as(function ($v) {
|
||||
return $this->order_status;
|
||||
})->using($this->statusMap)->dot($this->statusColor);
|
||||
$show->field('pay_way')->as(function ($v) {
|
||||
return $this->pay_way?->mallText();
|
||||
})->circleDot(PayWay::colors());
|
||||
$show->field('pay_at');
|
||||
$show->field('created_at');
|
||||
|
||||
$show->panel()->tools(function ($tools) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
});
|
||||
|
||||
$row = new Row();
|
||||
$row->column(5, $show);
|
||||
$tab = Tab::make()->withCard();
|
||||
$tab->add('商品', Card::make($this->gridProduct($id)));
|
||||
$tab->add('提货记录', Card::make($this->gridPackage($id)));
|
||||
|
||||
$row->column(7, $tab);
|
||||
return $row;
|
||||
}
|
||||
|
||||
protected function gridProduct($id)
|
||||
{
|
||||
$grid = Grid::make(OrderProduct::with([]));
|
||||
$grid->model()->where('order_id', $id);
|
||||
|
||||
$grid->column('name');
|
||||
$grid->column('sell_price', '销售价格')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('vip_price', '会员价格')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('quantity');
|
||||
$grid->column('sales_value');
|
||||
$grid->column('remain_quantity');
|
||||
$grid->column('product_total_amount')->display(function () {
|
||||
return bcdiv($this->total_amount, 100, 2);
|
||||
})->prepend('¥');
|
||||
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
$grid->disableRefreshButton();
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
protected function gridPackage($id)
|
||||
{
|
||||
$grid = Grid::make(OrderPackage::with(['inviter', 'orderProducts']));
|
||||
|
||||
$grid->model()->where('order_id', $id)->orderBy('created_at', 'desc');
|
||||
|
||||
$grid->column('products', '商品')->display(function () {
|
||||
$html = '';
|
||||
foreach($this->orderProducts as $item) {
|
||||
$html .= '<div><span class="label bg-primary">'.$item->name.'</span><span class="label bg-danger">'.$item->pivot->quantity.'</span></div>';
|
||||
}
|
||||
return $html;
|
||||
});
|
||||
$grid->column('created_at', '提货时间');
|
||||
$grid->column('inviter.phone', '员工');
|
||||
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
$grid->disableRefreshButton();
|
||||
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class OrderPackageService
|
|||
* @param array $params {shipping_company, shipping_number, packages => {order_product_id, quantity}}
|
||||
* @param OrderPackage $package
|
||||
*
|
||||
* @return void
|
||||
* @return OrderPackage $package
|
||||
*/
|
||||
public function createPackage(Order $order, array $params, ?OrderPackage $package = null)
|
||||
{
|
||||
|
|
@ -118,6 +118,8 @@ class OrderPackageService
|
|||
'shipping_state'=>Order::SHIPPING_STATE_PROCESSING,
|
||||
]);
|
||||
}
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ Route::group([
|
|||
$router->resource('store/list', 'Store\StoreController');
|
||||
$router->resource('store/product', 'Store\ProductController');
|
||||
$router->resource('store/stock', 'Store\StockController');
|
||||
$router->resource('store/order', 'Store\OrderController');
|
||||
$router->resource('store/order', 'Store\OrderController')->only(['index', 'show']);
|
||||
$router->resource('store/user', 'Store\UserController');
|
||||
// $router->resource('store/{store_id}/admin', 'Store\AdministratorController');
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class OrderPackage extends Model
|
|||
*/
|
||||
public function orderProducts()
|
||||
{
|
||||
return $this->belongsToMany(OrderProduct::class, 'order_package_products', 'order_package_id', 'order_product_id');
|
||||
return $this->belongsToMany(OrderProduct::class, 'order_package_products', 'order_package_id', 'order_product_id')->withPivot(['quantity']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1170,49 +1170,54 @@ class OrderService
|
|||
]);
|
||||
}
|
||||
|
||||
$products = $order->products()->get();
|
||||
|
||||
foreach ($products->load(['sku', 'spu']) as $product) {
|
||||
if ($product->sku === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果商品不是赠品,则直接增加商品库存
|
||||
if (! $product->isGift()) {
|
||||
$product->spu?->increment('sales', -$product->quantity);
|
||||
$product->sku?->update([
|
||||
'stock' => DB::Raw("stock + {$product->quantity}"),
|
||||
'sales' => DB::Raw("sales - {$product->quantity}"),
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
|
||||
//原赠品
|
||||
if ($product->gift_for_sku_id) {
|
||||
$gift = ProductGift::where('sku_id', $product->gift_for_sku_id)
|
||||
->where('gift_sku_id', $product->sku_id)
|
||||
->first();
|
||||
|
||||
if ($gift === null) {
|
||||
// 门店订单
|
||||
if ($order->store_id) {
|
||||
// 返还店铺库存
|
||||
} else {
|
||||
$products = $order->products()->get();
|
||||
|
||||
foreach ($products->load(['sku', 'spu']) as $product) {
|
||||
if ($product->sku === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($gift->isLimit()) {
|
||||
$gift->update([
|
||||
'remaining' => DB::raw("remaining+{$product->quantity}"),
|
||||
'sent' => DB::raw("sent-{$product->quantity}"),
|
||||
|
||||
// 如果商品不是赠品,则直接增加商品库存
|
||||
if (! $product->isGift()) {
|
||||
$product->spu?->increment('sales', -$product->quantity);
|
||||
$product->sku?->update([
|
||||
'stock' => DB::Raw("stock + {$product->quantity}"),
|
||||
'sales' => DB::Raw("sales - {$product->quantity}"),
|
||||
]);
|
||||
} else {
|
||||
$gift->decrement('sent', $product->quantity);
|
||||
continue;
|
||||
}
|
||||
|
||||
//原赠品
|
||||
if ($product->gift_for_sku_id) {
|
||||
$gift = ProductGift::where('sku_id', $product->gift_for_sku_id)
|
||||
->where('gift_sku_id', $product->sku_id)
|
||||
->first();
|
||||
|
||||
if ($gift === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($gift->isLimit()) {
|
||||
$gift->update([
|
||||
'remaining' => DB::raw("remaining+{$product->quantity}"),
|
||||
'sent' => DB::raw("sent-{$product->quantity}"),
|
||||
]);
|
||||
} else {
|
||||
$gift->decrement('sent', $product->quantity);
|
||||
}
|
||||
continue;
|
||||
} else {//新赠品, 则直接增加商品库存
|
||||
$product->spu?->increment('sales', -$product->quantity);
|
||||
$product->sku?->update([
|
||||
'stock' => DB::Raw("stock + {$product->quantity}"),
|
||||
'sales' => DB::Raw("sales - {$product->quantity}"),
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
} else {//新赠品, 则直接增加商品库存
|
||||
$product->spu?->increment('sales', -$product->quantity);
|
||||
$product->sku?->update([
|
||||
'stock' => DB::Raw("stock + {$product->quantity}"),
|
||||
'sales' => DB::Raw("sales - {$product->quantity}"),
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class VipService
|
|||
$money = $userVip->price;
|
||||
$debug = config('app.debug');
|
||||
if ($debug) {
|
||||
$money = 1;
|
||||
$money = 0.01;
|
||||
}
|
||||
$user = $userVip->user;
|
||||
// 微信小程序支付
|
||||
|
|
|
|||
Loading…
Reference in New Issue