8 changed files with 185 additions and 188 deletions
-
74app/Admin/Actions/Grid/v3/GoodsActivitySetting.php
-
35app/Admin/Controllers/v3/GoodsActivityController.php
-
2app/Admin/Controllers/v3/GoodsController.php
-
108app/Admin/Forms/GoodsNewCopyForm.php
-
73app/Admin/Forms/GoodsNewImageForm.php
-
68app/Admin/Forms/v3/GoodsActivitySettingForm.php
-
1app/Admin/routes.php
-
12app/Libs/Redis/RedisKey.php
@ -0,0 +1,74 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class GoodsActivitySetting extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '活动设置'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
return $this->response() |
|||
->success('跳转到设置页面' ) |
|||
->redirect('/activity_setting'); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('category/tie');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -1,108 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms; |
|||
|
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\StoreNew as StoreModel; |
|||
use App\Models\v3\GoodsNew as GoodsModel; |
|||
use App\Models\v3\GoodsNewBanners as GoodsBannerModel; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class GoodsNewCopyForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$goodsId = $input['goods_id']; |
|||
$storeIds= $input['store_ids']; |
|||
|
|||
$goods = GoodsModel::find($goodsId); |
|||
$goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->get(); |
|||
$markets = StoreModel::whereIn('id',$storeIds)->pluck('market_id','id'); |
|||
foreach($storeIds as $key =>$value){ |
|||
$storeId = $value; |
|||
$model = new GoodsModel(); |
|||
|
|||
$model->store_id = $storeId; |
|||
$model->market_id = $markets[$storeId]; |
|||
$model->category_id = $goods->category_id; |
|||
|
|||
$model->name = $goods->name; |
|||
$model->cover_img = $goods->cover_img; |
|||
$model->goods_unit = $goods->goods_unit; |
|||
|
|||
$model->tags = $goods->tags; |
|||
$model->spec = $goods->spec; |
|||
$model->details_imgs = $goods->details_imgs; |
|||
$model->content = $goods->content; |
|||
$model->details = $goods->details; |
|||
|
|||
$model->price = $goods->price; |
|||
$model->original_price = $goods->original_price; |
|||
$model->vip_price = $goods->vip_price; |
|||
|
|||
$model->start_num = $goods->start_num; |
|||
$model->restrict_num = $goods->restrict_num; |
|||
$model->is_infinite = $goods->is_infinite; |
|||
$model->inventory = $goods->inventory; |
|||
|
|||
$model->on_sale = $goods->on_sale; |
|||
$model->sort = $goods->sort; |
|||
$model->remark = $goods->remark; |
|||
|
|||
if($model->save() && !empty($goodsBanners)){ |
|||
$goodsId = $model->getKey(); |
|||
$banners = []; |
|||
foreach($goodsBanners as $kb => $vb){ |
|||
$banners[] = [ |
|||
'goods_id' => $goodsId, |
|||
'type' => $vb->type, |
|||
'path' => $vb->path, |
|||
'sort' => $vb->sort, |
|||
'created_at' => time(), |
|||
'updated_at' => time(), |
|||
]; |
|||
GoodsBannerModel::insert($banners); |
|||
} |
|||
}else{ |
|||
return $this->error('修改失败'); |
|||
}; |
|||
} |
|||
|
|||
return $this->error('修改成功'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$id = $this->getKey(); |
|||
$goods = GoodsModel::select('name')->find($id); |
|||
$this->hidden('goods_id')->value($id); |
|||
$name = empty($goods->name)?'':$goods->name; |
|||
$this->display('name')->value($name); |
|||
$stores = StoreModel::getStoreArray(); |
|||
$this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms; |
|||
|
|||
use App\Models\v3\GoodsBanners; |
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\GoodsNew as GoodsModel; |
|||
use App\Models\v3\GoodsNewBanners as GoodsBannerModel; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class GoodsNewImageForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$goodsId = $input['goods_id']; |
|||
$coverImg= $input['cover_img']; |
|||
$bannerImg= $input['img_banner']; |
|||
|
|||
if($goodsId > 0 && !empty($coverImg)){ |
|||
$data = ['cover_img' => $coverImg]; |
|||
GoodsModel::where('id',$goodsId)->update($data); |
|||
} |
|||
if($goodsId > 0 && !empty($bannerImg)){ |
|||
$banner = GoodsBannerModel::where('goods_id',$goodsId)->first(); |
|||
if(empty($banner)){ |
|||
$banner = new GoodsBanners(); |
|||
$banner->goods_id = $goodsId; |
|||
$banner->type = 1; |
|||
$banner->created_at = time(); |
|||
} |
|||
$banner->path = $bannerImg; |
|||
$banner->updated_at = time(); |
|||
$banner->save(); |
|||
} |
|||
|
|||
return $this->error('修改成功'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$id = $this->getKey(); |
|||
$goods = GoodsModel::select('name')->find($id); |
|||
$goodName = empty($goods->name)?'':$goods->name; |
|||
$this->hidden('goods_id')->value($id); |
|||
$this->display('name','商品名称')->value($goodName); |
|||
$this->image('cover_img','封面图')->url('ops/files'); |
|||
$this->image('img_banner','轮播图')->url('ops/files'); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms\v3; |
|||
|
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use Illuminate\Support\Facades\Redis; |
|||
use App\Libs\Redis\RedisKey; |
|||
|
|||
class GoodsActivitySettingForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$flashSale = $input['flash_sale']; |
|||
$groupBuy= $input['group_buy']; |
|||
$newProduct= $input['new_product']; |
|||
|
|||
$data = [ |
|||
'flash_sale' => $flashSale, |
|||
'group_buy' => $groupBuy, |
|||
'new_product' => $newProduct, |
|||
]; |
|||
|
|||
$res = Redis::hmset(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , $data); |
|||
if($res){ |
|||
return $this->success('修改成功','/goods_activity'); |
|||
}else{ |
|||
return $this->error('修改失败'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$data = Redis::hgetall('activity_type_limit_nums'); |
|||
|
|||
$flashSale = isset($data['flash_sale'])?$data['flash_sale']:0; |
|||
$groupBuy= isset($data['group_buy'])?$data['group_buy']:0; |
|||
$newProduct= isset($data['new_product'])?$data['new_product']:0; |
|||
|
|||
$this->display(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , '设置')->value('同一活动类型的商品,单笔订单可购买商品种数'); |
|||
$this->number('flash_sale','秒杀')->attribute('min', 0)->default(1)->value($flashSale); |
|||
$this->number('group_buy','团购')->attribute('min', 0)->default(1)->value($groupBuy); |
|||
$this->number('new_product','新品')->attribute('min', 0)->default(1)->value($newProduct); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
<?php |
|||
namespace App\Libs\Redis; |
|||
|
|||
/** |
|||
* @Constants |
|||
*/ |
|||
class RedisKey |
|||
{ |
|||
|
|||
const ACTIVITY_TYPE_LIMIT_NUMS = 'activity_type_limit_nums'; |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue