链街Dcat后台
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.

89 lines
3.0 KiB

  1. <?php
  2. namespace App\Admin\Forms\v3;
  3. use Dcat\Admin\Widgets\Form;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Illuminate\Support\Facades\Redis;
  6. use App\Libs\Redis\RedisKey;
  7. class GoodsActivityLimitForm extends Form
  8. {
  9. /**
  10. * Handle the form request.
  11. *
  12. * @param array $input
  13. *
  14. * @return Response
  15. */
  16. public function handle(array $input)
  17. {
  18. // 获取外部传递参数
  19. $data = [
  20. 'flash_sale' => $input['flash_sale'] ?? 0,
  21. 'group_buy' => $input['group_buy'] ?? 0,
  22. 'new_product' => $input['new_product'] ?? 0,
  23. ];
  24. $setData = [
  25. 'buy_num_limit' => 0,
  26. 'banner' => '',
  27. 'show_type' => 'list',
  28. 'index_num_limit' => 6,
  29. 'index_image' => '',
  30. 'index_url' => '',
  31. ];
  32. $setting = Redis::hgetall(RedisKey::ACTIVITY_TYPE_SETTING);
  33. $settingData = [
  34. 'flash_sale' => isset($setting['flash_sale']) ? json_decode($setting['flash_sale'],true) : $setData,
  35. 'group_buy' => isset($setting['group_buy']) ? json_decode($setting['group_buy'],true) : $setData,
  36. 'new_product' => isset($setting['new_product']) ? json_decode($setting['new_product'],true) : $setData,
  37. ];
  38. $settingData['flash_sale']['buy_num_limit'] = $data['flash_sale'];
  39. $settingData['group_buy']['buy_num_limit'] = $data['group_buy'];
  40. $settingData['new_product']['buy_num_limit'] = $data['new_product'];
  41. $activitySetting = [
  42. 'flash_sale' => json_encode($settingData['flash_sale']),
  43. 'group_buy' => json_encode($settingData['group_buy']),
  44. 'new_product' => json_encode($settingData['new_product']),
  45. ];
  46. $res2 = Redis::hmset(RedisKey::ACTIVITY_TYPE_SETTING , $activitySetting);
  47. $res = Redis::hmset(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , $data);
  48. if($res){
  49. return $this->success('修改成功','/goods_activity');
  50. }else{
  51. return $this->error('修改失败');
  52. }
  53. }
  54. /**
  55. * Build a form here.
  56. */
  57. public function form()
  58. {
  59. $data = Redis::hgetall(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS);
  60. $flashSale = isset($data['flash_sale'])?$data['flash_sale']:0;
  61. $groupBuy= isset($data['group_buy'])?$data['group_buy']:0;
  62. $newProduct= isset($data['new_product'])?$data['new_product']:0;
  63. $this->display(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , '设置')->value('同一活动类型的商品,单笔订单可购买商品种数');
  64. $this->number('flash_sale','秒杀')->attribute('min', 0)->default(1)->value($flashSale);
  65. $this->number('group_buy','团购')->attribute('min', 0)->default(1)->value($groupBuy);
  66. $this->number('new_product','新品')->attribute('min', 0)->default(1)->value($newProduct);
  67. }
  68. /**
  69. * The data of the form.
  70. *
  71. * @return array
  72. */
  73. public function default()
  74. {
  75. return [];
  76. }
  77. }