5 changed files with 295 additions and 20 deletions
-
8app/Admin/Controllers/v3/GoodsActivityController.php
-
89app/Admin/Forms/v3/GoodsActivityLimitForm.php
-
214app/Admin/Forms/v3/GoodsActivitySettingForm.php
-
2app/Admin/routes.php
-
2app/Libs/Redis/RedisKey.php
@ -0,0 +1,89 @@ |
|||
<?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 GoodsActivityLimitForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$data = [ |
|||
'flash_sale' => $input['flash_sale'] ?? 0, |
|||
'group_buy' => $input['group_buy'] ?? 0, |
|||
'new_product' => $input['new_product'] ?? 0, |
|||
]; |
|||
$setData = [ |
|||
'buy_num_limit' => 0, |
|||
'banner' => '', |
|||
'show_type' => 'list', |
|||
'index_num_limit' => 6, |
|||
'index_image' => '', |
|||
'index_url' => '', |
|||
]; |
|||
$setting = Redis::hgetall(RedisKey::ACTIVITY_TYPE_SETTING); |
|||
$settingData = [ |
|||
'flash_sale' => isset($setting['flash_sale']) ? json_decode($setting['flash_sale'],true) : $setData, |
|||
'group_buy' => isset($setting['group_buy']) ? json_decode($setting['group_buy'],true) : $setData, |
|||
'new_product' => isset($setting['new_product']) ? json_decode($setting['new_product'],true) : $setData, |
|||
]; |
|||
|
|||
$settingData['flash_sale']['buy_num_limit'] = $data['flash_sale']; |
|||
$settingData['group_buy']['buy_num_limit'] = $data['group_buy']; |
|||
$settingData['new_product']['buy_num_limit'] = $data['new_product']; |
|||
|
|||
$activitySetting = [ |
|||
'flash_sale' => json_encode($settingData['flash_sale']), |
|||
'group_buy' => json_encode($settingData['group_buy']), |
|||
'new_product' => json_encode($settingData['new_product']), |
|||
]; |
|||
$res2 = Redis::hmset(RedisKey::ACTIVITY_TYPE_SETTING , $activitySetting); |
|||
|
|||
$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(RedisKey::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 []; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue