You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.7 KiB
78 lines
2.7 KiB
<?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(!empty($store->time1) && !empty($store->time2) && (!empty($store->time3) || !empty($store->time4))){
|
|
if($store->time3 && empty($store->time4)){
|
|
return $this->error('请选择时间段二的结束时间!');
|
|
}else if($store->time4 && empty($store->time3)){
|
|
return $this->error('请选择时间段二的开始时间!');
|
|
}else if(str_replace(':', '', $store->time3) <= str_replace(':', '', $store->time2)){
|
|
return $this->error('时间段二的开始时间 必须大于 时间段一的结束时间!');
|
|
}else if(str_replace(':', '', $store->time4) <= str_replace(':', '', $store->time3)){
|
|
return $this->error('时间段二的结束时间 必须大于 时间段二的开始时间!');
|
|
}
|
|
}
|
|
|
|
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')->value($time3);
|
|
$this->time('time4','时间段二结束')->format('HH:mm')->value($time4);
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
}
|