53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Model\Seller\Seller;
|
|
use App\Model\Seller\Shop;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
|
|
class ShopAgentForm extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
|
|
public function handle(array $input)
|
|
{
|
|
if (empty($input)){
|
|
return $this->response()->alert()->error("设置失败1");
|
|
}else{
|
|
$agent_seller_id = (int)data_get($input,'agent_seller_id',0);
|
|
|
|
$agentSeller = Seller::find($agent_seller_id);
|
|
if (!$agentSeller) {
|
|
return $this->response()->alert()->error("该代理不存在");
|
|
}
|
|
|
|
$shop = Shop::where('id',$input['id'])->first();
|
|
if (empty($shop)){
|
|
return $this->response()->alert()->error("店铺不存在");
|
|
}
|
|
$shop->agent_seller_id = $agentSeller->id;
|
|
$shop->agent_shop_id = $agentSeller->shop_id;
|
|
$shop->save();
|
|
return $this->response()->success("设置成功")->refresh();
|
|
}
|
|
}
|
|
|
|
public function form()
|
|
{
|
|
$shop_id = $this->payload['id'];
|
|
$shops = Shop::where('id',$shop_id)->first();
|
|
$this->display('shop_sn','店铺编号')->with(function ($item)use($shops){
|
|
return $shops['shop_sn'];
|
|
});
|
|
$this->display('shop_name','店铺名称')->with(function ($item)use($shops){
|
|
return $shops['name'];
|
|
});
|
|
$this->select('agent_seller_id','平台代理')->options(Seller::pluck('name','id'))->help('请谨慎选择正确的平台代理');
|
|
$this->hidden('id')->value($shop_id);
|
|
}
|
|
|
|
}
|