链街Dcat后台
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

  1. <?php
  2. namespace App\Admin\Forms\v3;
  3. use Dcat\Admin\Widgets\Form;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Models\v3\Store as StoreModel;
  6. class StoreSetTimeForm extends Form
  7. {
  8. /**
  9. * Handle the form request.
  10. *
  11. * @param array $input
  12. *
  13. * @return Response
  14. */
  15. public function handle(array $input)
  16. {
  17. // 获取外部传递参数
  18. $storeId = $input['store_id'];
  19. $store = StoreModel::find($storeId);
  20. $store->time1 = $input['time1'];
  21. $store->time2 = $input['time2'];
  22. $store->time3 = $input['time3'];
  23. $store->time4 = $input['time4'];
  24. if(!empty($store->time1) && !empty($store->time2) && (!empty($store->time3) || !empty($store->time4))){
  25. if($store->time3 && empty($store->time4)){
  26. return $this->error('请选择时间段二的结束时间!');
  27. }else if($store->time4 && empty($store->time3)){
  28. return $this->error('请选择时间段二的开始时间!');
  29. }else if(str_replace(':', '', $store->time3) <= str_replace(':', '', $store->time2)){
  30. return $this->error('时间段二的开始时间 必须大于 时间段一的结束时间!');
  31. }else if(str_replace(':', '', $store->time4) <= str_replace(':', '', $store->time3)){
  32. return $this->error('时间段二的结束时间 必须大于 时间段二的开始时间!');
  33. }
  34. }
  35. if($store->save()){
  36. return $this->success('修改成功', '/store');
  37. }
  38. return $this->error('修改失败');
  39. }
  40. /**
  41. * Build a form here.
  42. */
  43. public function form()
  44. {
  45. $id = $this->getKey();
  46. $store = StoreModel::select('name','time1','time2','time3','time4')->find($id);
  47. $this->hidden('store_id')->value($id);
  48. $name = empty($store->name)?'':$store->name;
  49. $time1 = empty($store->time1)?'':$store->time1;
  50. $time2 = empty($store->time2)?'':$store->time2;
  51. $time3 = empty($store->time3)?'':$store->time3;
  52. $time4 = empty($store->time4)?'':$store->time4;
  53. $this->display('name','店铺名称')->value($name);
  54. $this->time('time1','时间段一开始')->format('HH:mm')->value($time1);
  55. $this->time('time2','时间段一结束')->format('HH:mm')->rules('after:time1',['after'=>'选择的时间必须比时间段一开始时间晚'])->value($time2);
  56. $this->time('time3','时间段二开始')->format('HH:mm')->value($time3);
  57. $this->time('time4','时间段二结束')->format('HH:mm')->value($time4);
  58. }
  59. /**
  60. * The data of the form.
  61. *
  62. * @return array
  63. */
  64. public function default()
  65. {
  66. return [];
  67. }
  68. }