Skip to content

Commit

Permalink
修改 前置、后置出来逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
liufei-ereach committed Jun 30, 2024
1 parent cb8f4be commit f606c59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Controller/BuyGoodsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected function data(ServerRequestInterface $request, Document $document) {
}

$validate = StoreExtend::getValidate($store->code);
if ($validate && !$validate->validate($actor, $store, $params, $this->translator, $this->settings, $this->events, $this->cache)) {
// $this->translator, $this->settings, $this->events, $this->cache
if ($validate && !$validate->validate($actor, $store, $params)) {
throw new ValidationException(['message' => $this->translator->trans('mattoid-store.forum.error.validate-fail')]);
}

Expand Down Expand Up @@ -117,7 +118,8 @@ protected function data(ServerRequestInterface $request, Document $document) {
$after = StoreExtend::getAfter($store->code);
if ($after) {
// 商品处理失败,通知购买失败事件进行回滚操作
if (!$after->after($actor, $store, $params, $this->translator, $this->settings, $this->events, $this->cache)) {
// $this->translator, $this->settings, $this->events, $this->cache
if (!$after->after($actor, $store, $params)) {
$this->events->dispatch(new StoreBuyFailEvent($user, $store, $cart, $params));
throw new ValidationException(['message' => $this->translator->trans('mattoid-store.forum.error.buy-goods-fail', ['title' => $store->title])]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Goods/After.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
abstract class After
{

abstract static function after(User $user, StoreModel $store, $params, Translator $translator = null, SettingsRepositoryInterface $settings = null, Dispatcher $events = null, CacheContract $cache = null);
abstract static function after(User $user, StoreModel $store, $params);
}
2 changes: 1 addition & 1 deletion src/Goods/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ abstract class Validate
* @param array $params 购买入参
* @return boolean 返回 true-验证成功 false-验证失败
*/
abstract static function validate(User $user, StoreModel $store, $params, Translator $translator = null, SettingsRepositoryInterface $settings = null, Dispatcher $events = null, CacheContract $cache = null);
abstract static function validate(User $user, StoreModel $store, $params);
}

0 comments on commit f606c59

Please sign in to comment.