Compare commits
No commits in common. "e3b3dc221f297162127bbc91a463ef76a4b3e0a4" and "7e0c93cda13bb471e76aa05c2b2278e73386eabf" have entirely different histories.
e3b3dc221f
...
7e0c93cda1
Binary file not shown.
|
|
@ -3,9 +3,6 @@
|
||||||
namespace Peidikeji\Goods\Action;
|
namespace Peidikeji\Goods\Action;
|
||||||
|
|
||||||
use Dcat\Admin\Grid\BatchAction;
|
use Dcat\Admin\Grid\BatchAction;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Peidikeji\Goods\Exceptions\GoodsException;
|
|
||||||
use Peidikeji\Goods\GoodsService;
|
|
||||||
use Peidikeji\Goods\Models\Goods;
|
use Peidikeji\Goods\Models\Goods;
|
||||||
|
|
||||||
class BatchGoodsDown extends BatchAction
|
class BatchGoodsDown extends BatchAction
|
||||||
|
|
@ -15,18 +12,9 @@ class BatchGoodsDown extends BatchAction
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ids = $this->getKey();
|
$ids = $this->getKey();
|
||||||
try {
|
Goods::whereIn('id', $ids)->update(['on_sale' => 0]);
|
||||||
DB::beginTransaction();
|
|
||||||
$service = GoodsService::make();
|
|
||||||
foreach(Goods::whereIn('id', $ids)->get() as $item) {
|
|
||||||
$service->downSale($item);
|
|
||||||
}
|
|
||||||
DB::commit();
|
|
||||||
return $this->response()->success('操作成功')->refresh();
|
return $this->response()->success('操作成功')->refresh();
|
||||||
} catch (GoodsException $e) {
|
|
||||||
DB::rollBack();
|
|
||||||
return $this->response()->error($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirm()
|
public function confirm()
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
namespace Peidikeji\Goods\Action;
|
namespace Peidikeji\Goods\Action;
|
||||||
|
|
||||||
use Dcat\Admin\Grid\BatchAction;
|
use Dcat\Admin\Grid\BatchAction;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Peidikeji\Goods\Exceptions\GoodsException;
|
|
||||||
use Peidikeji\Goods\GoodsService;
|
|
||||||
use Peidikeji\Goods\Models\Goods;
|
use Peidikeji\Goods\Models\Goods;
|
||||||
|
|
||||||
class BatchGoodsUp extends BatchAction
|
class BatchGoodsUp extends BatchAction
|
||||||
|
|
@ -15,18 +12,9 @@ class BatchGoodsUp extends BatchAction
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$ids = $this->getKey();
|
$ids = $this->getKey();
|
||||||
try {
|
Goods::whereIn('id', $ids)->update(['on_sale' => 1]);
|
||||||
DB::beginTransaction();
|
|
||||||
$service = GoodsService::make();
|
|
||||||
foreach(Goods::whereIn('id', $ids)->get() as $item) {
|
|
||||||
$service->upSale($item);
|
|
||||||
}
|
|
||||||
DB::commit();
|
|
||||||
return $this->response()->success('操作成功')->refresh();
|
return $this->response()->success('操作成功')->refresh();
|
||||||
} catch (GoodsException $e) {
|
|
||||||
DB::rollBack();
|
|
||||||
return $this->response()->error($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirm()
|
public function confirm()
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
namespace Peidikeji\Goods\Action;
|
namespace Peidikeji\Goods\Action;
|
||||||
|
|
||||||
use Dcat\Admin\Grid\RowAction;
|
use Dcat\Admin\Grid\RowAction;
|
||||||
use Peidikeji\Goods\Exceptions\GoodsException;
|
|
||||||
use Peidikeji\Goods\GoodsService;
|
|
||||||
use Peidikeji\Goods\Models\Goods;
|
use Peidikeji\Goods\Models\Goods;
|
||||||
|
|
||||||
class RowGoodsSale extends RowAction
|
class RowGoodsSale extends RowAction
|
||||||
|
|
@ -17,18 +15,9 @@ class RowGoodsSale extends RowAction
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$info = Goods::findOrFail($this->getKey());
|
$info = Goods::findOrFail($this->getKey());
|
||||||
$service = GoodsService::make();
|
Goods::where('id', $this->getKey())->update(['on_sale' => ! $info->on_sale]);
|
||||||
try {
|
|
||||||
if ($info->on_sale) {
|
|
||||||
$service->downSale($info);
|
|
||||||
} else {
|
|
||||||
$service->upSale($info);
|
|
||||||
}
|
|
||||||
return $this->response()->success('操作成功')->refresh();
|
|
||||||
} catch(GoodsException $e) {
|
|
||||||
return $this->response()->error($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return $this->response()->success('操作成功')->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirm()
|
public function confirm()
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Peidikeji\Goods\Exceptions;
|
|
||||||
|
|
||||||
use Dcat\Admin\Traits\JsonResponse;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class GoodsException extends Exception
|
|
||||||
{
|
|
||||||
use JsonResponse;
|
|
||||||
|
|
||||||
protected $code = 400;
|
|
||||||
|
|
||||||
public function report()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function render($request)
|
|
||||||
{
|
|
||||||
return $this->error($this->message, $this->code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,15 +4,14 @@ namespace Peidikeji\Goods;
|
||||||
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Peidikeji\Goods\Exceptions\GoodsException;
|
|
||||||
use Peidikeji\Goods\Models\Goods;
|
use Peidikeji\Goods\Models\Goods;
|
||||||
use Peidikeji\Goods\Models\GoodsSku;
|
use Peidikeji\Goods\Models\GoodsSku;
|
||||||
|
|
||||||
class GoodsService
|
class GoodsService
|
||||||
{
|
{
|
||||||
public static function make()
|
public static function make(...$params)
|
||||||
{
|
{
|
||||||
return new static();
|
return new static(...$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateSn()
|
public function generateSn()
|
||||||
|
|
@ -73,29 +72,4 @@ class GoodsService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品上架销售
|
|
||||||
*
|
|
||||||
* @param Goods $goods 商品
|
|
||||||
* @throws GoodsException
|
|
||||||
*/
|
|
||||||
public function upSale(Goods $goods)
|
|
||||||
{
|
|
||||||
if ($goods->spec && $goods->skus()->count() === 0) {
|
|
||||||
throw new GoodsException($goods->name . ' 必需生成货品');
|
|
||||||
}
|
|
||||||
|
|
||||||
$goods->update(['on_sale' => 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品下架
|
|
||||||
*
|
|
||||||
* @param Goods $goods 商品
|
|
||||||
*/
|
|
||||||
public function downSale(Goods $goods)
|
|
||||||
{
|
|
||||||
$goods->update(['on_sale' => 0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ class GoodsController extends AdminController
|
||||||
});
|
});
|
||||||
$grid->column('price');
|
$grid->column('price');
|
||||||
$grid->column('stock')
|
$grid->column('stock')
|
||||||
->if(fn () => !!$this->spec)
|
->if(fn () => $this->skus->count() > 0)
|
||||||
->display(fn () => $this->skus->sum('stock'))
|
->display(fn () => $this->skus->sum('stock'))
|
||||||
->else()
|
->else()
|
||||||
->editable();
|
->editable();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue