链街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.

72 lines
1.9 KiB

  1. <?php
  2. namespace App\Admin\Forms;
  3. use App\Models\v3\GoodsBanners;
  4. use Dcat\Admin\Widgets\Form;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use App\Models\v3\GoodsNew as GoodsModel;
  7. use App\Models\v3\GoodsNewBanners as GoodsBannerModel;
  8. use Illuminate\Support\Facades\DB;
  9. class GoodsNewImageForm extends Form
  10. {
  11. /**
  12. * Handle the form request.
  13. *
  14. * @param array $input
  15. *
  16. * @return Response
  17. */
  18. public function handle(array $input)
  19. {
  20. // 获取外部传递参数
  21. $goodsId = $input['goods_id'];
  22. $coverImg= $input['cover_img'];
  23. $bannerImg= $input['img_banner'];
  24. if($goodsId > 0 && !empty($coverImg)){
  25. $data = ['cover_img' => $coverImg];
  26. GoodsModel::where('id',$goodsId)->update($data);
  27. }
  28. if($goodsId > 0 && !empty($bannerImg)){
  29. $banner = GoodsBannerModel::where('goods_id',$goodsId)->first();
  30. if(empty($banner)){
  31. $banner = new GoodsBanners();
  32. $banner->goods_id = $goodsId;
  33. $banner->type = 1;
  34. $banner->created_at = time();
  35. }
  36. $banner->path = $bannerImg;
  37. $banner->updated_at = time();
  38. $banner->save();
  39. }
  40. return $this->success('修改成功', '/goods_new');
  41. }
  42. /**
  43. * Build a form here.
  44. */
  45. public function form()
  46. {
  47. $id = $this->getKey();
  48. $goods = GoodsModel::select('name')->find($id);
  49. $goodName = empty($goods->name)?'':$goods->name;
  50. $this->hidden('goods_id')->value($id);
  51. $this->image('cover_img','封面图')->url('ops/files')->help('商品名称:'.$goodName);
  52. $this->image('img_banner','轮播图')->url('ops/files');
  53. }
  54. /**
  55. * The data of the form.
  56. *
  57. * @return array
  58. */
  59. public function default()
  60. {
  61. return [];
  62. }
  63. }