0 && !empty($coverImg)){ $lastLen = strrpos($coverImg,','); if($lastLen != false){ $coverImg = substr($coverImg,$lastLen+1); } if(strlen($coverImg) > 200){ return $this->error('上传图片名称过长'); } $data = ['cover_img' => $coverImg]; $res1 = GoodsModel::where('id',$goodsId)->update($data); } if($goodsId > 0 && !empty($bannerImg)){ $banner = GoodsBannerModel::where('goods_id',$goodsId)->delete(); foreach($bannerImg as $value){ $banner = new GoodsBanners(); $banner->goods_id = $goodsId; $banner->type = 1; $banner->created_at = time(); $banner->updated_at = time(); $banner->path = $value; $res2 = $banner->save(); } } if((isset($res1) && $res1) || (isset($res2) && $res2)){ return $this->success('修改成功','/goods?'.$this->getSearch($this->search)); } return $this->error('未做任何修改'); } /** * Build a form here. */ public function form() { $id = $this->payload['id'] ?? 0; $goodName = $this->payload['name'] ?? ''; $coverImg = $this->payload['cover_img'] ?? ''; $this->search = $this->payload['search'] ?? ''; $this->hidden('goods_id')->value($id); $this->display('name','商品名称')->value($goodName); $this->image('cover_img','封面图')->uniqueName()->retainable()->customFormat(function() use($coverImg){ return [$coverImg]; })->autoUpload(); $this->multipleImage('img_banner','轮播图')->uniqueName()->customFormat(function() use($id){ if(!$id){ return ; } $banners = GoodsBanners::where('goods_id',$id)->pluck('path')->toArray(); return empty($banners) ? [] : $banners; })->autoUpload(); $this->disableResetButton(); } /** * The data of the form. * * @return array */ public function default() { return []; } public function getSearch($data) { $return = ''; if(is_array($data) && count($data) > 0){ unset($data['_pjax']); foreach($data as $key => $value){ $return .= $key.'='.$value.'&'; } } return $return; } }