Withdraw.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Withdraw.php UTF-8
  4. * 提现基类
  5. *
  6. * @date : 2018/7/4 10:33
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : Beibao 1.0
  11. */
  12. namespace huolib\withdraw;
  13. use huolib\status\OrderStatus;
  14. use think\Exception;
  15. use think\Log;
  16. class Withdraw {
  17. static $ins;
  18. private $payway_map
  19. = [
  20. 'default' => 'Mobile',
  21. 'alipay' => 'Alipay',
  22. 'wxpay' => 'Wxpay',
  23. 'mobile' => 'Mobile',
  24. ];
  25. public static function ins() {
  26. if (self::$ins == null) {
  27. self::$ins = new self();
  28. }
  29. return self::$ins;
  30. }
  31. /**
  32. * @param string $payway
  33. *
  34. * @return mixed
  35. * @throws Exception
  36. */
  37. public function get($payway = '') {
  38. if (empty($payway)) {
  39. return $this->register('default');
  40. }
  41. $_pay_obj = $this->register($payway);
  42. if (!isset($_pay_obj)) {
  43. Log::write(
  44. "func=".__FUNCTION__."&class=".__CLASS__."&errmsg=registerError&payway=".$payway
  45. .'objName='.$this->payway_map[$payway], 'info'
  46. );
  47. throw new Exception(OrderStatus::getMsg(OrderStatus::PAYWAY_INCORRECT), OrderStatus::PAYWAY_INCORRECT);
  48. }
  49. return $_pay_obj;
  50. }
  51. /**
  52. * @param string $payway
  53. *
  54. * @return mixed
  55. */
  56. protected function register($payway = '') {
  57. $payway = strtolower($payway);
  58. $_class = '\\huolib\\withdraw\\driver\\'.$this->payway_map[$payway];
  59. return new $_class();
  60. }
  61. }