38 lines
909 B
PHP
38 lines
909 B
PHP
<?php
|
|
|
|
namespace Peidikeji\Goods\Action;
|
|
|
|
use Dcat\Admin\Grid\BatchAction;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Peidikeji\Goods\Exceptions\GoodsException;
|
|
use Peidikeji\Goods\GoodsService;
|
|
use Peidikeji\Goods\Models\Goods;
|
|
|
|
class BatchGoodsUp extends BatchAction
|
|
{
|
|
protected $title = '上架';
|
|
|
|
public function handle()
|
|
{
|
|
$ids = $this->getKey();
|
|
try {
|
|
DB::beginTransaction();
|
|
$service = GoodsService::make();
|
|
foreach(Goods::whereIn('id', $ids)->get() as $item) {
|
|
$service->upSale($item);
|
|
}
|
|
DB::commit();
|
|
return $this->response()->success('操作成功')->refresh();
|
|
} catch (GoodsException $e) {
|
|
DB::rollBack();
|
|
return $this->response()->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function confirm()
|
|
{
|
|
return ['是否确定?'];
|
|
}
|
|
}
|
|
|