8 changed files with 154 additions and 19 deletions
-
40app/Admin/Actions/Grid/v3/StoreChangeMarket.php
-
8app/Admin/Controllers/v3/GoodsActivityController.php
-
8app/Admin/Controllers/v3/GoodsController.php
-
18app/Admin/Controllers/v3/StoreController.php
-
3app/Admin/Forms/v3/GoodsActivityCopyForm.php
-
5app/Admin/Forms/v3/GoodsCopyForm.php
-
15app/Admin/Forms/v3/GoodsImageForm.php
-
76app/Admin/Forms/v3/StoreChangeMarketForm.php
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Dcat\Admin\Widgets\Modal; |
|||
use App\Admin\Forms\v3\StoreChangeMarketForm; |
|||
|
|||
class StoreChangeMarket extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = ' 换市场 '; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(StoreChangeMarketForm::make()->setKey($id)->payload([ |
|||
'id'=>$this->row->id, |
|||
'name'=>$this->row->name, |
|||
'market_id'=>$this->row->market_id |
|||
])) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms\v3; |
|||
|
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\Store as StoreModel; |
|||
use App\Models\v3\Market as MarketModel; |
|||
use App\Models\v3\Goods as GoodsModel; |
|||
use Dcat\Admin\Contracts\LazyRenderable; |
|||
use Dcat\Admin\Traits\LazyWidget; |
|||
|
|||
class StoreChangeMarketForm extends Form implements LazyRenderable |
|||
{ |
|||
use LazyWidget; |
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$id = $input['id']; |
|||
$marketId = $input['market_id']; |
|||
|
|||
$store = StoreModel::find($id); |
|||
if(empty($store)){ |
|||
return $this->error('店铺不存在!'); |
|||
} |
|||
|
|||
$goods = GoodsModel::select('id')->where('store_id',$id)->first(); |
|||
if($goods){ |
|||
return $this->error('店铺存在商品,不可更换市场!'); |
|||
} |
|||
if(!empty($marketId)){ |
|||
$store->market_id = $marketId; |
|||
} |
|||
if($store->save()){ |
|||
return $this->success('修改成功!'); |
|||
} |
|||
|
|||
return $this->error('未做任何修改或者修改失败!'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$id = $this->payload['id'] ?? 0; |
|||
$name = $this->payload['name'] ?? ''; |
|||
$marketId = $this->payload['market_id'] ?? 0; |
|||
|
|||
$marketList = MarketModel::getMarketArray(); |
|||
unset($marketList[$marketId]); |
|||
|
|||
$this->hidden('id')->value($id); |
|||
$this->display('name','店铺')->value($name); |
|||
|
|||
$this->select('market_id','所属市场')->options($marketList)->required(); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue