3 changed files with 103 additions and 0 deletions
-
36app/Admin/Actions/Grid/v3/StoreSetTime.php
-
2app/Admin/Controllers/v3/StoreController.php
-
65app/Admin/Forms/v3/StoreSetTimeForm.php
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Dcat\Admin\Widgets\Modal; |
|||
use App\Admin\Forms\v3\StoreSetTimeForm; |
|||
|
|||
class StoreSetTime extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '营业时间'; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(StoreSetTimeForm::make()->setKey($id)) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms\v3; |
|||
|
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\Store as StoreModel; |
|||
|
|||
class StoreSetTimeForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$storeId = $input['store_id']; |
|||
|
|||
$store = StoreModel::find($storeId); |
|||
$store->time1 = $input['time1']; |
|||
$store->time2 = $input['time2']; |
|||
$store->time3 = $input['time3']; |
|||
$store->time4 = $input['time4']; |
|||
if($store->save()){ |
|||
return $this->success('修改成功', '/store'); |
|||
} |
|||
return $this->error('修改失败'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$id = $this->getKey(); |
|||
$store = StoreModel::select('name','time1','time2','time3','time4')->find($id); |
|||
$this->hidden('store_id')->value($id); |
|||
$name = empty($store->name)?'':$store->name; |
|||
$time1 = empty($store->time1)?'':$store->time1; |
|||
$time2 = empty($store->time2)?'':$store->time2; |
|||
$time3 = empty($store->time3)?'':$store->time3; |
|||
$time4 = empty($store->time4)?'':$store->time4; |
|||
$this->display('name','店铺名称')->value($name); |
|||
$this->time('time1','时间段一开始')->format('HH:mm')->value($time1); |
|||
$this->time('time2','时间段一结束')->format('HH:mm')->rules('after:time1',['after'=>'选择的时间必须比时间段一开始时间晚'])->value($time2); |
|||
$this->time('time3','时间段二开始')->format('HH:mm')->rules('after:time2',['after'=>'选择的时间必须比时间段一结束时间晚'])->value($time3); |
|||
$this->time('time4','时间段二结束')->format('HH:mm')->rules('after:time3',['after'=>'选择的时间必须比时间段二开始时间晚'])->value($time4); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue