PayController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace api\modules\v1\controllers\common;
  3. use Yii;
  4. use api\controllers\OnAuthController;
  5. use common\enums\PayTypeEnum;
  6. use common\helpers\Url;
  7. use common\forms\PayForm;
  8. use common\helpers\ResultHelper;
  9. use common\forms\OrderPayFrom;
  10. use common\forms\RechargePayFrom;
  11. /**
  12. * 公用支付生成
  13. *
  14. * Class PayController
  15. * @package api\modules\v1\controllers
  16. * @author jianyan74 <751393839@qq.com>
  17. */
  18. class PayController extends OnAuthController
  19. {
  20. /**
  21. * @var PayForm
  22. */
  23. public $modelClass = PayForm::class;
  24. /**
  25. * 生成支付参数
  26. *
  27. * @return array|bool|mixed|\yii\db\ActiveRecord
  28. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  29. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  30. * @throws \GuzzleHttp\Exception\GuzzleException
  31. * @throws \yii\base\InvalidConfigException
  32. * @throws \yii\web\UnprocessableEntityHttpException
  33. */
  34. public function actionCreate()
  35. {
  36. /* @var $payForm PayForm */
  37. $payForm = new $this->modelClass();
  38. $payForm->attributes = Yii::$app->request->post();
  39. $payForm->member_id = Yii::$app->user->identity->member_id;
  40. $payForm->code = Yii::$app->request->get('code');
  41. if (!$payForm->validate()) {
  42. return ResultHelper::json(422, $this->getError($payForm));
  43. }
  44. // 非余额支付
  45. if ($payForm->pay_type != PayTypeEnum::USER_MONEY) {
  46. // 执行方法
  47. $payForm->setHandlers([
  48. 'recharge' => RechargePayFrom::class,
  49. 'order' => OrderPayFrom::class,
  50. ]);
  51. // 回调方法
  52. $payForm->notify_url = Url::removeMerchantIdUrl('toApi', ['notify/' . PayTypeEnum::action($payForm->pay_type)]);
  53. // 生成配置
  54. return ResultHelper::json(200, '待支付', [
  55. 'payStatus' => false,
  56. 'config' => $payForm->getConfig(),
  57. ]);
  58. }
  59. }
  60. }
粤ICP备19079148号