PaymentDirector.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/8/26
  8. * Time: 16:52
  9. */
  10. namespace app\common\payment;
  11. use app\common\models\PayType;
  12. use app\common\payment\types\BasePaymentTypes;
  13. class PaymentDirector
  14. {
  15. public $paymentTypes;
  16. public function setPaymentTypes(BasePaymentTypes $basePaymentTypes)
  17. {
  18. $this->paymentTypes = $basePaymentTypes;
  19. app()->singleton(BasePaymentTypes::class,function () {
  20. return $this->paymentTypes;
  21. });
  22. return $this;
  23. }
  24. public function getPaymentButton()
  25. {
  26. $paymentMethodList = collect(app()->tagged('paymentMethod'));
  27. $paymentMethodList = $paymentMethodList->filter(function ($method) {
  28. $method->setTypes($this->paymentTypes);
  29. $method->setPayType();
  30. return $method->getCode() && $method->canUse();
  31. });
  32. $buttonList = $paymentMethodList->map(function ($payment) {
  33. return [
  34. 'code' => $payment->getCode(),
  35. 'name' => $payment->getName(),
  36. 'value' => $payment->getId(),
  37. 'need_password' => $payment->needPassword(),
  38. 'weight' => $payment->getWeight(),
  39. ];
  40. });
  41. return $buttonList->sortByDesc('weight')->values();
  42. }
  43. }