| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/4/21
- * Time: 下午6:16
- */
- namespace app\backend\modules\refund\controllers;
- use app\common\components\BaseController;
- use app\common\events\order\AfterOrderRefundSuccessEvent;
- use app\common\exceptions\AppException;
- use app\common\exceptions\ShopException;
- use app\common\modules\refund\services\RefundService;
- use app\backend\modules\refund\services\RefundMessageService;
- use app\backend\modules\refund\models\RefundApply;
- class PayController extends BaseController
- {
- private $refundApply;
- public $transactionActions = [];
- public function preAction()
- {
- parent::preAction();
- $this->validate([
- 'refund_id' => 'required',
- ]);
- $this->refundApply = RefundApply::find(request()->input('refund_id'));
- if (!isset($this->refundApply)) {
- throw new AdminException('退款记录不存在');
- }
- }
- public function api()
- {
- $request = request()->input();
- try {
- $result = \Illuminate\Support\Facades\DB::transaction(function () use ($request) {
- $result = (new RefundService)->pay($request['refund_id']);
- if (!$result) {
- throw new AppException('操作失败');
- }
- return $result;
- });
- } catch (\Exception $e) {
- \Log::debug('<------售后退款失败------:'.$e->getMessage());
- throw new AppException($e->getMessage());
- }
- return $this->successJson('退款成功');
- }
- /**
- * {@inheritdoc}
- */
- public function index()
- {
- $request = request()->input();
- $this->validate([
- 'refund_id' => 'required'
- ]);
- $restrictAccess = \app\common\services\RequestTokenService::limitRepeat('agree_refund_'. $request['refund_id']);
- if (!$restrictAccess) {
- throw new ShopException('短时间内重复操作,请等待10秒后再操作');
- }
- try {
- /**
- * @var $this ->refundApply RefundApply
- */
- $result = \Illuminate\Support\Facades\DB::transaction(function () use ($request) {
- $result = (new RefundService)->pay($request['refund_id']);
- if (!$result) {
- throw new ShopException('操作失败');
- }
- return $result;
- });
- } catch (\Exception $e) {
- \Log::debug('<------售后退款失败------:'.$e->getMessage());
- throw new ShopException($e->getMessage());
- }
- if (is_string($result)) {
- redirect($result)->send();
- }
- if (is_array($result) && isset($result['action']) && isset($result['input'])) {
- echo $this->formPost($result);exit();
- }
- // RefundMessageService::passMessage($this->refundApply);//通知买家
- //
- // event(new AfterOrderRefundSuccessEvent($this->refundApply));
- // if (app('plugins')->isEnabled('instation-message')) {
- // event(new \Yunshop\InstationMessage\event\OrderRefundSuccessEvent($this->refundApply));
- // }
- return $this->message('操作成功');
- }
- /**
- * 表单POST请求
- * @param $trxCode
- * @param $data
- */
- public function formPost($data)
- {
- $echo = "<form style='display:none;' id='form1' name='form1' method='post' action='" . $data['action']."'>";
- foreach ($data['input'] as $k => $v) {
- $echo .= "<input name='{$k}' type='text' value='{$v}' />";
- }
- $echo .= "</form>";
- $echo .= "<script type='text/javascript'>function load_submit(){document.form1.submit()}load_submit();</script>";
- echo $echo;
- }
- }
|