链街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.

73 lines
1.6 KiB

  1. <?php
  2. namespace App\Admin\Forms;
  3. use Dcat\Admin\Widgets\Form;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Libs\SsdbClient;
  6. class CouponTieForm extends Form
  7. {
  8. /**
  9. *
  10. */
  11. protected $ssdb;
  12. /**
  13. * Handle the form request.
  14. *
  15. * @param array $input
  16. *
  17. * @return Response
  18. */
  19. public function handle(array $input)
  20. {
  21. $data = [
  22. 'activity' => $input['activity'],
  23. 'forward' => $input['forward'],
  24. 'repay' => $input['repay'],
  25. ];
  26. $coupon = $this->ssdb->client()->multi_hset('coupon_rebate_activity',$data);
  27. if($coupon === false){
  28. return $this->error('修改失败');
  29. }
  30. return $this->success('修改成功', '/couponTie');
  31. }
  32. /**
  33. * Build a form here.
  34. */
  35. public function form()
  36. {
  37. $this->ssdb = new SsdbClient();
  38. $coupon = $this->ssdb->client()->hgetall('coupon_rebate_activity');
  39. if(empty($coupon)){
  40. $coupon = [
  41. 'activity'=> 0,
  42. 'forward'=> '',
  43. 'repay' => ''
  44. ];
  45. }
  46. $this->text('activity')->required()->value($coupon['activity']);
  47. $this->text('forward')->required()->value($coupon['forward']);
  48. $this->text('repay')->required()->value($coupon['repay']);
  49. }
  50. /**
  51. * The data of the form.
  52. *
  53. * @return array
  54. */
  55. public function default()
  56. {
  57. return [
  58. 'activity' => '2',
  59. 'forward' => '',
  60. 'repay' => '',
  61. ];
  62. }
  63. }