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