admin store_prodcut_stock_batch
parent
36ad423033
commit
3448852885
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Admin\Actions\Store;
|
||||
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use App\Models\Admin\Administrator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Store\{ProductSku, StockBatch};
|
||||
|
||||
class RowAddStock extends RowAction
|
||||
|
|
@ -20,9 +20,10 @@ class RowAddStock extends RowAction
|
|||
}
|
||||
$admin = $model->adminUser;
|
||||
$type = $admin->getMorphClass();
|
||||
foreach($model->productSkus()->get() as $item) {
|
||||
$amount = $item->pivot?->amount;
|
||||
if ($amount) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
foreach($model->productSkus()->get() as $item) {
|
||||
$amount = $item->pivot?->amount;
|
||||
$product = ProductSku::firstOrCreate([
|
||||
'store_id' => $model->store_id,
|
||||
'product_sku_id' => $item->id
|
||||
|
|
@ -33,9 +34,9 @@ class RowAddStock extends RowAction
|
|||
]);
|
||||
$balance = $product->amount + $amount;
|
||||
if ($balance < 0) {
|
||||
continue;
|
||||
throw new \Exception($item->name . ' 商品库存不足');
|
||||
}
|
||||
array_push($list, [
|
||||
$list[] = [
|
||||
'operator_type' => $type,
|
||||
'operator_id' => $admin->id,
|
||||
'operator_name' => $admin->name,
|
||||
|
|
@ -45,15 +46,19 @@ class RowAddStock extends RowAction
|
|||
'store_id' => $model->store_id,
|
||||
'tag_id' => $model->tag_id,
|
||||
'remarks' => '批次号: ' . $model->sn,
|
||||
]);
|
||||
|
||||
];
|
||||
|
||||
$product->update(['amount' => $balance]);
|
||||
}
|
||||
}
|
||||
|
||||
$model->logs()->createMany($list);
|
||||
|
||||
$model->update(['status' => 1]);
|
||||
$model->logs()->createMany($list);
|
||||
|
||||
$model->update(['status' => 1]);
|
||||
DB::commit();
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
return $this->response()->error($exception->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class ProductSkuController extends AdminController
|
|||
{
|
||||
$name = $request->input('q');
|
||||
|
||||
$query = ProductSkuModel::query();
|
||||
$query = ProductSkuModel::select(['id', 'name as text']);
|
||||
|
||||
if ($name) {
|
||||
$query->where('name', 'like', "%$name%");
|
||||
|
|
@ -180,9 +180,7 @@ class ProductSkuController extends AdminController
|
|||
$list = $query->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $list->map(function ($item) {
|
||||
return ['id' => $item->id, 'text' => $item->name . '-----库存('.$item->stock.')'];
|
||||
})
|
||||
'data' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue