|
|
|
@ -14,12 +14,17 @@ class GoodsActivitySettingForm extends Form |
|
|
|
1 => '列表轮播', |
|
|
|
2 => '大图片', |
|
|
|
]; |
|
|
|
protected $typeOptionsValue = [ |
|
|
|
1 => 'list', |
|
|
|
2 => 'image', |
|
|
|
]; |
|
|
|
protected $indexOptions = [ |
|
|
|
1 => '秒杀', |
|
|
|
2 => '团购', |
|
|
|
3 => '新品' |
|
|
|
]; |
|
|
|
protected $indexOptionsValue = [ |
|
|
|
0 => 'default', |
|
|
|
1 => 'flash_sale', |
|
|
|
2 => 'group_buy', |
|
|
|
3 => 'new_product' |
|
|
|
@ -34,16 +39,16 @@ class GoodsActivitySettingForm extends Form |
|
|
|
public function handle(array $input) |
|
|
|
{ |
|
|
|
$activitySetting = [ |
|
|
|
'index_activity_type' => $input['index_activity_type'] ?? 1 |
|
|
|
'index_activity_type' => $this->indexOptionsValue[$input['index_activity_type']] ?? $this->indexOptionsValue[0] |
|
|
|
]; |
|
|
|
|
|
|
|
switch($activitySetting['index_activity_type']){ |
|
|
|
case 1: |
|
|
|
case 'flash_sale': |
|
|
|
$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, |
|
|
|
'show_type' => $this->typeOptionsValue[$input['show_type_1']] ?? $this->typeOptionsValue[1], |
|
|
|
'index_num_limit' => $input['index_num_1'] ?? 6, |
|
|
|
'index_image' => $input['index_image_1'] ?? '', |
|
|
|
'index_url' => $input['index_url_1'] ?? '', |
|
|
|
]; |
|
|
|
@ -51,19 +56,27 @@ class GoodsActivitySettingForm extends Form |
|
|
|
'flash_sale' => $setting['buy_num_limit'], |
|
|
|
]; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 'group_buy': |
|
|
|
$setting = [ |
|
|
|
'buy_num_limit' => $input['buy_num_limit_2'] ?? 0, |
|
|
|
'banner' => $input['banner_2'] ?? '' |
|
|
|
'banner' => $input['banner_2'] ?? '', |
|
|
|
'show_type' => $this->typeOptionsValue[$input['show_type_2']] ?? $this->typeOptionsValue[1], |
|
|
|
'index_num_limit' => $input['index_num_2'] ?? 6, |
|
|
|
'index_image' => $input['index_image_2'] ?? '', |
|
|
|
'index_url' => $input['index_url_2'] ?? '', |
|
|
|
]; |
|
|
|
$data = [ |
|
|
|
'group_buy' => $setting['buy_num_limit'], |
|
|
|
]; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 'new_product': |
|
|
|
$setting = [ |
|
|
|
'buy_num_limit' => $input['buy_num_limit_3'] ?? 0, |
|
|
|
'banner' => $input['banner_3'] ?? '' |
|
|
|
'banner' => $input['banner_3'] ?? '', |
|
|
|
'show_type' => $this->typeOptionsValue[$input['show_type_3']] ?? $this->typeOptionsValue[1], |
|
|
|
'index_num_limit' => $input['index_num_3'] ?? 6, |
|
|
|
'index_image' => $input['index_image_3'] ?? '', |
|
|
|
'index_url' => $input['index_url_3'] ?? '', |
|
|
|
]; |
|
|
|
$data = [ |
|
|
|
'new_product' => $setting['buy_num_limit'], |
|
|
|
@ -74,7 +87,7 @@ class GoodsActivitySettingForm extends Form |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
$activitySetting[$this->indexOptionsValue[$activitySetting['index_activity_type']]] = json_encode($setting); |
|
|
|
$activitySetting[$activitySetting['index_activity_type']] = json_encode($setting); |
|
|
|
|
|
|
|
$res1 = Redis::hmset(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , $data); |
|
|
|
|
|
|
|
@ -95,23 +108,27 @@ class GoodsActivitySettingForm extends Form |
|
|
|
$data = Redis::hgetall(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS); |
|
|
|
$setting = Redis::hgetall(RedisKey::ACTIVITY_TYPE_SETTING); |
|
|
|
|
|
|
|
$indexOptionsKey = array_flip($this->indexOptionsValue); |
|
|
|
$typeOptionsKey = array_flip($this->typeOptionsValue); |
|
|
|
|
|
|
|
$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, |
|
|
|
'index_activity_type' => $indexOptionsKey[$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){ |
|
|
|
->when([1],function(Form $form) use($limitData,$settingData,$typeOptionsKey){ |
|
|
|
$buyNumLimit = $limitData[1] ?? 0; |
|
|
|
$sData = $settingData[1] ?? []; |
|
|
|
|
|
|
|
$showType = $sData['show_type'] ?? 'list'; |
|
|
|
$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){ |
|
|
|
@ -130,27 +147,58 @@ class GoodsActivitySettingForm extends Form |
|
|
|
$form->url('index_url_1','跳转链接')->value($sData['index_url'] ?? '')->width(4); |
|
|
|
}) |
|
|
|
->options($form->typeOptions) |
|
|
|
->value($sData['show_type'] ?? 1) |
|
|
|
->value($typeOptionsKey[$showType] ?? 1) |
|
|
|
->default(1); |
|
|
|
|
|
|
|
}) |
|
|
|
->when([2],function(Form $form) use($limitData,$settingData){ |
|
|
|
->when([2],function(Form $form) use($limitData,$settingData,$typeOptionsKey){ |
|
|
|
$buyNumLimit = $limitData[2] ?? 0; |
|
|
|
$sData = $settingData[2] ?? []; |
|
|
|
$showType = $sData['show_type'] ?? 'list'; |
|
|
|
$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); |
|
|
|
$form->radio('show_type_2','展示形式') |
|
|
|
->when([1],function(Form $form) use($sData){ |
|
|
|
$form->number('index_num_2','首页显示数量')->value($sData['index_num'] ?? 6)->min(1)->default(6)->width(6); |
|
|
|
}) |
|
|
|
->when([2],function(Form $form) use($sData){ |
|
|
|
$form->image('index_image_2','首页大图')->autoUpload()->saveFullUrl() |
|
|
|
->customFormat(function() use($sData){ |
|
|
|
return [$sData['index_image'] ?? '']; |
|
|
|
})->width(3); |
|
|
|
$form->url('index_url_2','跳转链接')->value($sData['index_url'] ?? '')->width(4); |
|
|
|
}) |
|
|
|
->options($form->typeOptions) |
|
|
|
->value($typeOptionsKey[$showType] ?? 1) |
|
|
|
->default(1); |
|
|
|
}) |
|
|
|
->when([3],function(Form $form) use($limitData,$settingData){ |
|
|
|
->when([3],function(Form $form) use($limitData,$settingData,$typeOptionsKey){ |
|
|
|
$buyNumLimit = $limitData[3] ?? 0; |
|
|
|
$sData = $settingData[3] ?? []; |
|
|
|
$showType = $sData['show_type'] ?? 'list'; |
|
|
|
$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); |
|
|
|
|
|
|
|
$form->radio('show_type_3','展示形式') |
|
|
|
->when([1],function(Form $form) use($sData){ |
|
|
|
$form->number('index_num_3','首页显示数量')->value($sData['index_num'] ?? 6)->min(1)->default(6)->width(6); |
|
|
|
}) |
|
|
|
->when([2],function(Form $form) use($sData){ |
|
|
|
$form->image('index_image_3','首页大图')->autoUpload()->saveFullUrl() |
|
|
|
->customFormat(function() use($sData){ |
|
|
|
return [$sData['index_image'] ?? '']; |
|
|
|
})->width(3); |
|
|
|
$form->url('index_url_3','跳转链接')->value($sData['index_url'] ?? '')->width(4); |
|
|
|
}) |
|
|
|
->options($form->typeOptions) |
|
|
|
->value($typeOptionsKey[$showType] ?? 1) |
|
|
|
->default(1); |
|
|
|
}) |
|
|
|
->options($this->indexOptions)->value($settingData['index_activity_type'] ?? 1)->default(1)->width(4); |
|
|
|
} |
|
|
|
|