Browse Source

店铺更换市场

master
liangyuyan 5 years ago
parent
commit
48534cd57a
  1. 40
      app/Admin/Actions/Grid/v3/StoreChangeMarket.php
  2. 18
      app/Admin/Controllers/v3/StoreController.php
  3. 76
      app/Admin/Forms/v3/StoreChangeMarketForm.php

40
app/Admin/Actions/Grid/v3/StoreChangeMarket.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 [
];
}
}

18
app/Admin/Controllers/v3/StoreController.php

@ -2,6 +2,7 @@
namespace App\Admin\Controllers\v3; namespace App\Admin\Controllers\v3;
use App\Admin\Actions\Grid\v3\StoreChangeMarket;
use App\Admin\Common\Auth; use App\Admin\Common\Auth;
use App\Admin\Repositories\v3\Store; use App\Admin\Repositories\v3\Store;
use App\Models\LanzuMmInfo; use App\Models\LanzuMmInfo;
@ -97,7 +98,13 @@ class StoreController extends AdminController
$grid->is_operation->switch(); $grid->is_operation->switch();
$grid->is_open->switch(); $grid->is_open->switch();
$grid->actions([new StoreSetTime()]);
$actions = [
new StoreSetTime()
];
if($this->storeChangeMarketCan()){
$actions[] = new StoreChangeMarket();
}
$grid->actions($actions);
// 搜索 // 搜索
$grid->filter(function (Grid\Filter $filter) use($marketList){ $grid->filter(function (Grid\Filter $filter) use($marketList){
$filter->equal('id'); $filter->equal('id');
@ -422,4 +429,13 @@ class StoreController extends AdminController
$user = Admin::user(); $user = Admin::user();
return $user->can('store_balance'); return $user->can('store_balance');
} }
/**
* @return bool
*/
protected function storeChangeMarketCan(): bool
{
$user = Admin::user();
return $user->can('store_change_market');
}
} }

76
app/Admin/Forms/v3/StoreChangeMarketForm.php

@ -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 [];
}
}
Loading…
Cancel
Save