4 changed files with 143 additions and 8 deletions
-
32app/Admin/Actions/Grid/GoodsCopy.php
-
39app/Admin/Controllers/v3/GoodsController.php
-
19app/Admin/Controllers/v3/StoreController.php
-
61app/Admin/Forms/GoodsCopyForm.php
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
use Dcat\Admin\Form; |
||||
|
use App\Models\v3\Goods as GoodsModel; |
||||
|
use App\Admin\Forms\GoodsCopyForm; |
||||
|
|
||||
|
class GoodsCopy extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '复制'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body(GoodsCopyForm::make()->setKey($id)) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms; |
||||
|
|
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Symfony\Component\HttpFoundation\Response; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
use App\Models\v3\Goods as GoodsModel; |
||||
|
use App\Models\v3\GoodsBanners as GoodsBannerModel; |
||||
|
|
||||
|
class GoodsCopyForm extends Form |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$goodsId = $input['goods_id']; |
||||
|
$storeIds= $input['store_ids']; |
||||
|
// dd($storeIds);
|
||||
|
$goods = GoodsModel::find($goodsId); |
||||
|
$goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->get(); |
||||
|
foreach($storeIds as $key =>$value){ |
||||
|
$model = new GoodsModel(); |
||||
|
$model = $goods; |
||||
|
dd($model->toArray()); |
||||
|
$model->store_id = $value; |
||||
|
$model->name = $goods->name; |
||||
|
} |
||||
|
|
||||
|
return $this->success('修改成功', '/goods'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$this->text('goods_id')->value($id); |
||||
|
$stores = StoreModel::getStoreArray(); |
||||
|
$this->multipleSelect('store_ids','选择店铺')->required()->options($stores); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue