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.
168 lines
6.5 KiB
168 lines
6.5 KiB
<?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
|
|
{
|
|
|
|
protected $typeOptions = [
|
|
1 => '列表轮播',
|
|
2 => '大图片',
|
|
];
|
|
protected $indexOptions = [
|
|
1 => '秒杀',
|
|
2 => '团购',
|
|
3 => '新品'
|
|
];
|
|
protected $indexOptionsValue = [
|
|
1 => 'flash_sale',
|
|
2 => 'group_buy',
|
|
3 => 'new_product'
|
|
];
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$activitySetting = [
|
|
'index_activity_type' => $input['index_activity_type'] ?? 1
|
|
];
|
|
|
|
switch($activitySetting['index_activity_type']){
|
|
case 1:
|
|
$setting = [
|
|
'buy_num_limit' => $input['buy_num_limit_1'] ?? 0,
|
|
'banner' => $input['banner_1'] ?? '',
|
|
'show_type' => $input['show_type_1'] ?? 0,
|
|
'index_num' => $input['index_num_1'] ?? 6,
|
|
'index_image' => $input['index_image_1'] ?? '',
|
|
'index_url' => $input['index_url_1'] ?? '',
|
|
];
|
|
$data = [
|
|
'flash_sale' => $setting['buy_num_limit'],
|
|
];
|
|
break;
|
|
case 2:
|
|
$setting = [
|
|
'buy_num_limit' => $input['buy_num_limit_2'] ?? 0,
|
|
'banner' => $input['banner_2'] ?? ''
|
|
];
|
|
$data = [
|
|
'group_buy' => $setting['buy_num_limit'],
|
|
];
|
|
break;
|
|
case 3:
|
|
$setting = [
|
|
'buy_num_limit' => $input['buy_num_limit_3'] ?? 0,
|
|
'banner' => $input['banner_3'] ?? ''
|
|
];
|
|
$data = [
|
|
'new_product' => $setting['buy_num_limit'],
|
|
];
|
|
break;
|
|
default:
|
|
return $this->error('请选择正确的首页展示的活动类型!');
|
|
break;
|
|
}
|
|
|
|
$activitySetting[$this->indexOptionsValue[$activitySetting['index_activity_type']]] = json_encode($setting);
|
|
|
|
$res1 = Redis::hmset(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , $data);
|
|
|
|
$res2 = Redis::hmset(RedisKey::ACTIVITY_TYPE_SETTING , $activitySetting);
|
|
|
|
if($res1 && $res2){
|
|
return $this->success('修改成功','/goods_activity');
|
|
}else{
|
|
return $this->error('修改失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$data = Redis::hgetall(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS);
|
|
$setting = Redis::hgetall(RedisKey::ACTIVITY_TYPE_SETTING);
|
|
|
|
$limitData = [
|
|
1 => isset($data['flash_sale']) ? $data['flash_sale']:0,
|
|
2 => isset($data['group_buy']) ? $data['group_buy']:0,
|
|
3 => isset($data['new_product']) ? $data['new_product']:0,
|
|
];
|
|
$settingData = [
|
|
'index_activity_type' => $setting['index_activity_type'] ?? 1,
|
|
1 => isset($setting['flash_sale']) ? json_decode($setting['flash_sale'],true) : [],
|
|
2 => isset($setting['group_buy']) ? json_decode($setting['group_buy'],true) : [],
|
|
3 => isset($setting['new_product']) ? json_decode($setting['new_product'],true) : [],
|
|
];
|
|
|
|
$this->select('index_activity_type','首页展示的活动类型')
|
|
->when([1],function(Form $form) use($limitData,$settingData){
|
|
$buyNumLimit = $limitData[1] ?? 0;
|
|
$sData = $settingData[1] ?? [];
|
|
|
|
$form->number('buy_num_limit_1','购买数量限制')->attribute('min', 0)->default(1)->value($buyNumLimit)->width(6)->help('同一活动类型的商品,单笔订单可购买商品个数');
|
|
$form->image('banner_1','banner')->autoUpload()->saveFullUrl()
|
|
->customFormat(function() use($sData){
|
|
return [$sData['banner'] ?? ''];
|
|
})->width(3);
|
|
|
|
$form->radio('show_type_1','展示形式')
|
|
->when([1],function(Form $form) use($sData){
|
|
$form->number('index_num_1','首页显示数量')->value($sData['index_num'] ?? 6)->min(1)->default(6)->width(6);
|
|
})
|
|
->when([2],function(Form $form) use($sData){
|
|
$form->image('index_image_1','首页大图')->autoUpload()->saveFullUrl()
|
|
->customFormat(function() use($sData){
|
|
return [$sData['index_image'] ?? ''];
|
|
})->width(3);
|
|
$form->url('index_url_1','跳转链接')->value($sData['index_url'] ?? '')->width(4);
|
|
})
|
|
->options($form->typeOptions)
|
|
->value($sData['show_type'] ?? 1)
|
|
->default(1);
|
|
|
|
})
|
|
->when([2],function(Form $form) use($limitData,$settingData){
|
|
$buyNumLimit = $limitData[2] ?? 0;
|
|
$sData = $settingData[2] ?? [];
|
|
$form->number('buy_num_limit_2','购买数量限制')->attribute('min', 0)->default(1)->value($buyNumLimit)->width(6)->help('同一活动类型的商品,单笔订单可购买商品个数');
|
|
$form->image('banner_2','banner')->autoUpload()->saveFullUrl()
|
|
->customFormat(function() use($sData){
|
|
return [$sData['banner'] ?? ''];
|
|
})->width(3);
|
|
})
|
|
->when([3],function(Form $form) use($limitData,$settingData){
|
|
$buyNumLimit = $limitData[3] ?? 0;
|
|
$sData = $settingData[3] ?? [];
|
|
$form->number('buy_num_limit_3','购买数量限制')->attribute('min', 0)->default(1)->value($buyNumLimit)->width(6)->help('同一活动类型的商品,单笔订单可购买商品个数');
|
|
$form->image('banner_3','banner')->autoUpload()->saveFullUrl()
|
|
->customFormat(function() use($sData){
|
|
return [$sData['banner'] ?? ''];
|
|
})->width(3);
|
|
})
|
|
->options($this->indexOptions)->value($settingData['index_activity_type'] ?? 1)->default(1)->width(4);
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
}
|