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

95 lines
2.8 KiB

  1. <?php
  2. namespace App\Admin\Forms\v3;
  3. use App\Models\v3\GoodsBanners;
  4. use Dcat\Admin\Widgets\Form;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use App\Models\v3\CouponReceiveType as ReceiveTypeModel;
  7. use App\Models\v3\CouponSetting as SettingModel;
  8. use App\Models\v3\Coupon as CouponModel;
  9. class CouponPublishForm extends Form
  10. {
  11. /**
  12. * Handle the form request.
  13. *
  14. * @param array $input
  15. *
  16. * @return Response
  17. */
  18. public function handle(array $input)
  19. {
  20. // 获取外部传递参数
  21. $id = $input['id'];
  22. $receiveType = $input['receive_type'];
  23. $coupon = CouponModel::find($id);
  24. if(!$coupon){
  25. return $this->error('优惠券不存在或已删除!');
  26. }
  27. switch($coupon->status){
  28. case 0:
  29. case 3:
  30. // 判断活动时间 还未判断
  31. $coupon->status = 1;
  32. if(!$coupon->save()){
  33. return $this->error('发布失败!');
  34. }
  35. // 删除领取方式
  36. $delRes = ReceiveTypeModel::where('coupon_id',$id)->delete();
  37. if($delRes === false){
  38. return $this->error('发布失败!');
  39. }
  40. // 添加领取方式
  41. $receiveModel = new ReceiveTypeModel();
  42. $receiveModel->coupon_id = $id;
  43. $receiveModel->receive_type = $receiveType;
  44. // 获取一次可领取数量
  45. $receiveNumber = SettingModel::getSettingInfo($receiveType,'value');
  46. $receiveModel->one_receive_number = empty($receiveNumber) ? 1 : $receiveNumber->value;
  47. if($receiveModel->save()){
  48. return $this->success('发布成功','/coupon');
  49. }
  50. break;
  51. case 1:
  52. return $this->error('优惠券已发布!');
  53. break;
  54. case 2:
  55. return $this->error('优惠券已领完!');
  56. break;
  57. case -1:
  58. return $this->error('优惠券已删除!');
  59. break;
  60. }
  61. return $this->error('发布失败!');
  62. }
  63. /**
  64. * Build a form here.
  65. */
  66. public function form()
  67. {
  68. $id = $this->getKey();
  69. $receiveTypeInfo = ReceiveTypeModel::getReceiveTypeInfo($id,'receive_type');
  70. $list = SettingModel::getSettingArray();
  71. $receiveType = empty($receiveTypeInfo->receive_type)? 0 :$receiveTypeInfo->receive_type;
  72. $this->hidden('id')->value($id);
  73. $this->select('receive_type','领取方式')->required()->options($list)->value($receiveType);
  74. }
  75. /**
  76. * The data of the form.
  77. *
  78. * @return array
  79. */
  80. public function default()
  81. {
  82. return [];
  83. }
  84. }