diff --git a/app/Admin/Controllers/Activity/RuleController.php b/app/Admin/Controllers/Activity/RuleController.php index 89459b4..82771d5 100644 --- a/app/Admin/Controllers/Activity/RuleController.php +++ b/app/Admin/Controllers/Activity/RuleController.php @@ -54,25 +54,27 @@ class RuleController extends AdminController $form->switch('status', '状态')->default(1); $form->saving(function (Form $form) { - $code = $form->code; + if ($form->code) { + $code = $form->code; - $ticket = explode('-', $code); - if (!is_array($ticket) || count($ticket) != 3) { - $error = new MessageBag([ - 'title' => '错误', - 'message' => '规则编号格式错误', - ]); + $ticket = explode('-', $code); + if (!is_array($ticket) || count($ticket) != 3) { + $error = new MessageBag([ + 'title' => '错误', + 'message' => '规则编号格式错误', + ]); - return back()->withInput()->with(compact('error')); + return back()->withInput()->with(compact('error')); + } + + $full = $ticket[1]; //full100 + $price = $ticket[2]; + preg_match('/\d+/', $full, $match); + + $form->full = $match[0]; + $form->take = $price; } - $full = $ticket[1]; //full100 - $price = $ticket[2]; - preg_match('/\d+/', $full, $match); - - $form->full = $match[0]; - $form->take = $price; - }); return $form; diff --git a/app/Listeners/ConponCallbackListener.php b/app/Listeners/ConponCallbackListener.php index 75ac784..2a4e08c 100644 --- a/app/Listeners/ConponCallbackListener.php +++ b/app/Listeners/ConponCallbackListener.php @@ -1,67 +1,68 @@ -acticity_coupon; - - $user = $acticity_coupon->outlet->parent; - if ($user->callback) { - $client = new Client(); - - $response = $client->request('post', $user->callback, [ - 'timeout' => 30, - 'query' => [ - 'code' => $acticity_coupon->code, - 'status' => $acticity_coupon->status, - ], - ]); - - $data = [ - 'code' => $acticity_coupon->code, - 'type' => $acticity_coupon->status == 2 ? 'Verification' : 'Destroy', - 'url' => $user->callback, - ]; - - $error = false; - - if ($response->getStatusCode() == 200) { - $body = $response->getBody(); - $result = json_decode($body->getContents(), true); - - $data['status'] = $result['code'] ?? ''; - $data['source'] = $result; - $data['remark'] = $result['message'] ?? ''; - - } else { - $data['status'] = 0; - $data['source'] = ''; - $data['remark'] = '接口错误'; - $error = true; - } - ActivityCouponLog::create($data); - - if ($error) { - throw new RuntimeException($data['remark']); - } - } - - } - -} +acticity_coupon; + + $user = $acticity_coupon->outlet->parent; + if ($user->callback) { + $client = new Client(); + + $response = $client->request('post', $user->callback, [ + 'timeout' => 30, + 'query' => [ + 'code' => $acticity_coupon->code, + 'status' => $acticity_coupon->status, + ], + ]); + + $data = [ + 'code' => $acticity_coupon->code, + 'type' => $acticity_coupon->status == 2 ? 'Verification' : 'Destroy', + 'url' => $user->callback, + ]; + + $error = false; + + if ($response->getStatusCode() == 200) { + $body = $response->getBody(); + $result = json_decode($body->getContents(), true); + + $data['status'] = $result['code'] ?? ''; + $data['source'] = $result; + $data['remark'] = $result['message'] ?? ''; + + } else { + $data['status'] = 0; + $data['source'] = ''; + $data['remark'] = '接口错误'; + $error = true; + } + ActivityCouponLog::create($data); + + if ($error) { + throw new RuntimeException($data['remark']); + } + } + + } + +}