stock
parent
e52f42d0b6
commit
a8deaf4b4d
|
|
@ -102,8 +102,6 @@ class ProductController extends AdminController
|
|||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
$count = $query->count();
|
||||
$sell_price = round($query->sum('product_skus.sell_price') / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$cost_price = round($query->sum('product_skus.cost_price') / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$stock = round($query->sum('store_product_skus.amount'), 2, PHP_ROUND_HALF_DOWN);
|
||||
$cost = round($query->sum(DB::raw('product_skus.cost_price * amount')) / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$sell = round($query->sum(DB::raw('product_skus.sell_price * amount')) / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
|
|
@ -113,8 +111,6 @@ class ProductController extends AdminController
|
|||
<tr>
|
||||
<td>统计</td>
|
||||
<td>总数: $count</td>
|
||||
<td>销售价: $sell_price</td>
|
||||
<td>成本价: $cost_price</td>
|
||||
<td>库存: $stock</td>
|
||||
<td>总销售: $sell</td>
|
||||
<td>总成本: $cost</td>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use Dcat\Admin\{Form, Grid, Admin, Show};
|
|||
use App\Models\Store\{Store, StockBatch, StockLog};
|
||||
use App\Models\{ProductSku};
|
||||
use Dcat\Admin\Widgets\Table;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Admin\Administrator;
|
||||
|
||||
class StockBatchController extends AdminController
|
||||
|
|
@ -25,13 +26,16 @@ class StockBatchController extends AdminController
|
|||
$grid->column('status')->using([0 => '未确认', 1 => '已确认'])->label([0 => 'danger', 1 => 'success']);
|
||||
$grid->column('product_sku_id')->display(fn() => '共'.$this->productSkus->count().'件')->modal(function ($modal) {
|
||||
$modal->title('商品记录');
|
||||
$data = $this->productSkus->map(fn($item) => [
|
||||
$item->name,
|
||||
round($item->sell_price / 100, 2, PHP_ROUND_HALF_DOWN),
|
||||
round($item->cost_price / 100, 2, PHP_ROUND_HALF_DOWN),
|
||||
$item->pivot?->amount
|
||||
])->all();
|
||||
return Table::make(['名称', '售价', '成本价', '数量'], $data);
|
||||
$data = $this->productSkus->map(function($item) {
|
||||
$sell_price = round($item->sell_price / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$cost_price = round($item->cost_price / 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$amount = data_get($item->pivot, 'amount', 0);
|
||||
$profit_price = round($sell_price - $cost_price, 2, PHP_ROUND_HALF_DOWN);
|
||||
$sell = abs(round($sell_price * $amount, 2, PHP_ROUND_HALF_DOWN));
|
||||
$cost = abs(round($cost_price * $amount, 2, PHP_ROUND_HALF_DOWN));
|
||||
return [$item->name, $sell_price, $cost_price, $profit_price, $amount, $sell, $cost];
|
||||
})->all();
|
||||
return Table::make(['名称', '售价', '成本价', '毛利', '数量', '总销售', '总成本'], $data);
|
||||
});
|
||||
$grid->column('sell_price', '总销售价')->display(fn () => round($this->productSkus->sum(fn ($item) => abs(data_get($item->pivot, 'amount', 0)) * $item->sell_price) / 100, 2, PHP_ROUND_HALF_DOWN));
|
||||
$grid->column('cost_price', '总成本价')->display(fn () => round($this->productSkus->sum(fn ($item) => abs(data_get($item->pivot, 'amount', 0)) * $item->cost_price) / 100, 2, PHP_ROUND_HALF_DOWN));
|
||||
|
|
@ -40,10 +44,23 @@ class StockBatchController extends AdminController
|
|||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('sn')->width(3);
|
||||
$filter->equal('store_id')->select('api/store')->width(3);
|
||||
$filter->equal('tag_id', '类目')->select(StockLog::tags()->pluck('name', 'id'))->width(3);
|
||||
$filter->equal('admin_user_id')->select()->model(Administrator::class)->ajax('api/administrators?_paginate=1')->width(3);
|
||||
$filter->equal('status')->select([0 => '未确认', 1 => '已确认'])->width(3);
|
||||
$filter->whereBetween('created_at', function ($q) {
|
||||
$start = data_get($this->input, 'start');
|
||||
$start = $start ? Carbon::createFromFormat('Y-m-d', $start) : null;
|
||||
$end = data_get($this->input, 'end');
|
||||
$end = $end ? Carbon::createFromFormat('Y-m-d', $end) : null;
|
||||
if ($start) {
|
||||
$q->where('created_at', '>=', $start);
|
||||
}
|
||||
if ($end) {
|
||||
$q->where('created_at', '<=', $end);
|
||||
}
|
||||
})->date()->width(6);
|
||||
});
|
||||
|
||||
$user = Admin::user();
|
||||
|
|
|
|||
|
|
@ -33,15 +33,7 @@ class StockController extends AdminController
|
|||
return '<span class="text-'.($value > 0 ? 'success' : 'danger') .'">'.$value.'</span>';
|
||||
});
|
||||
$grid->column('balance');
|
||||
$grid->column('operator', '操作人')->display(function ($v) {
|
||||
if ($v instanceof Administrator) {
|
||||
return $v->name . '<span class="label bg-primary">管理员</span>';
|
||||
} else if ($v instanceof User) {
|
||||
return $v->phone . '<span class="label bg-info">员工</span>';
|
||||
}
|
||||
|
||||
return '未知身份';
|
||||
});
|
||||
$grid->column('operator_name', '操作人');
|
||||
$grid->column('remarks', '备注');
|
||||
$grid->column('created_at', '操作时间');
|
||||
|
||||
|
|
@ -55,15 +47,7 @@ class StockController extends AdminController
|
|||
$filter->equal('store_id')->select(Store::pluck('title', 'id'))->width(3);
|
||||
$filter->like('productSku.name', '商品')->width(3);
|
||||
$filter->equal('tag_id', '类目')->select(StockLog::tags()->pluck('name', 'id'))->width(3);
|
||||
$filter->where('operator', function ($q) {
|
||||
$input = $this->input;
|
||||
$condition = '%'.$input.'%';
|
||||
$q->whereHasMorph('operator', [Administrator::class, User::class], function ($q1, $type) use ($condition) {
|
||||
$column = $type === Administrator::class ? 'name' : 'phone';
|
||||
|
||||
$q1->where($column, 'like', $condition);
|
||||
});
|
||||
})->placeholder('管理员姓名/员工手机号')->width(3);
|
||||
$filter->like('operator_name', '操作人')->width(3);
|
||||
$filter->whereBetween('created_at', function ($q) {
|
||||
$start = data_get($this->input, 'start');
|
||||
$start = $start ? Carbon::createFromFormat('Y-m-d', $start) : null;
|
||||
|
|
@ -77,7 +61,7 @@ class StockController extends AdminController
|
|||
} elseif ($end) {
|
||||
$q->where('created_at', '<=', $end);
|
||||
}
|
||||
}, '操作时间')->date()->width(3);
|
||||
}, '操作时间')->date()->width(6);
|
||||
});
|
||||
return $grid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ class OrderResource extends JsonResource
|
|||
'expires_at' => $this->expires_at,
|
||||
|
||||
'packages' => OrderPackageResource::make($this->whenLoaded('lastPackage')),
|
||||
|
||||
'source_type' => $this->source_type,
|
||||
'source_id' => $this->source_id,
|
||||
'store_id' => $this->store_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Listeners;
|
|||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Models\Store\{Desk, ProductSku};
|
||||
use App\Models\Order;
|
||||
use App\Models\{Tag, Order};
|
||||
|
||||
/**
|
||||
* 自动完成订单
|
||||
|
|
@ -27,16 +27,21 @@ class OrderAutoComplete
|
|||
foreach($package->orderProducts as $item) {
|
||||
$sku = ProductSku::where('store_id', $store->id)->where('product_sku_id', $item->sku_id)->first();
|
||||
if ($sku) {
|
||||
$tag = Tag::firstOrCreate([
|
||||
'type' => Tag::TYPE_STORE_STOCK,
|
||||
'name' => '提货'
|
||||
]);
|
||||
$amount = $item->pivot->quantity;
|
||||
$balance = $sku->amount - $amount;
|
||||
$store->stockLogs()->create([
|
||||
'amount' => 0 - $amount,
|
||||
'product_sku_id' => $item->sku_id,
|
||||
'remarks' => '桌号订自动提货',
|
||||
'remarks' => '桌号订单自动提货',
|
||||
'balance' => $balance,
|
||||
'source_id' => $order->id,
|
||||
'source_type' => $order->getMorphClass(),
|
||||
'tag_id' => 3
|
||||
'tag_id' => $tag->id,
|
||||
'operator_name' => '积趣吧台',
|
||||
]);
|
||||
|
||||
$sku->update(['amount' => $balance]);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ class OrderPrint
|
|||
public function handle($event)
|
||||
{
|
||||
$order = $event->order;
|
||||
// 门店订单, 桌号信息
|
||||
if ($order->store_id && $order->source_type == Desk::class) {
|
||||
// 门店订单
|
||||
if ($order->store_id) {
|
||||
try {
|
||||
(new OrderService())->print($order);
|
||||
} catch (BizException $e) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class StockLog extends Model
|
|||
|
||||
protected $table = 'store_stock_logs';
|
||||
|
||||
protected $fillable = ['operator_type', 'operator_id', 'amount', 'product_sku_id', 'remarks', 'balance', 'source_id', 'source_type', 'store_id', 'tag_id'];
|
||||
protected $fillable = ['operator_type', 'operator_id', 'operator_name', 'amount', 'product_sku_id', 'remarks', 'balance', 'source_id', 'source_type', 'store_id', 'tag_id'];
|
||||
|
||||
public static function tags()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1368,16 +1368,17 @@ class OrderService
|
|||
*/
|
||||
public function print(Order $order)
|
||||
{
|
||||
if (!$order->store_id || $order->source_type !== Desk::class) {
|
||||
if (!$order->store_id) {
|
||||
throw new BizException('不是门店订单');
|
||||
}
|
||||
$store = $order->store;
|
||||
if (!$store) {
|
||||
throw new BizException('未找到门店');
|
||||
}
|
||||
$desk = $order->source;
|
||||
if (!$desk) {
|
||||
throw new BizException('未找到桌号');
|
||||
$desk = '';
|
||||
if ($order->source_type === Desk::class) {
|
||||
$desk = $order->source;
|
||||
$desk = data_get($order->source, 'name', '');
|
||||
}
|
||||
|
||||
$devices = $store->devices()->where('status', 1)->get();
|
||||
|
|
@ -1403,7 +1404,7 @@ class OrderService
|
|||
'name' => $store->title,
|
||||
'sn' => $order->sn,
|
||||
'time' => $order->created_at->format('Y-m-d H:i:s'),
|
||||
'desk' => $desk->name,
|
||||
'desk' => $desk,
|
||||
'products' => $products,
|
||||
'total' => round($order->total_amount / 100, 2, PHP_ROUND_HALF_DOWN),
|
||||
'remarks' => $order->note ?: '',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AddOperatorNameToStockLogs extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('store_stock_logs', function (Blueprint $table) {
|
||||
$table->string('operator_name');
|
||||
});
|
||||
DB::update("update `store_stock_logs` set `operator_name` = (select `name` from `admin_users` where `store_stock_logs`.`operator_id` = `admin_users`.`id`) where `store_stock_logs`.`operator_type` in ('App\Models\Admin\Administrator', 'admin_users');");
|
||||
DB::update("update `store_stock_logs` set `operator_name` = (select `phone` from `users` where `store_stock_logs`.`operator_id` = `users`.`id`) where `store_stock_logs`.`operator_type` in ('App\Models\User');");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('store_stock_logs', function (Blueprint $table) {
|
||||
$table->dropColumn(['operator_name']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue