* @version : Beibao 1.0 */ namespace huolib\withdraw; use huolib\status\OrderStatus; use think\Exception; use think\Log; class Withdraw { static $ins; private $payway_map = [ 'default' => 'Mobile', 'alipay' => 'Alipay', 'wxpay' => 'Wxpay', 'mobile' => 'Mobile', ]; public static function ins() { if (self::$ins == null) { self::$ins = new self(); } return self::$ins; } /** * @param string $payway * * @return mixed * @throws Exception */ public function get($payway = '') { if (empty($payway)) { return $this->register('default'); } $_pay_obj = $this->register($payway); if (!isset($_pay_obj)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&errmsg=registerError&payway=".$payway .'objName='.$this->payway_map[$payway], 'info' ); throw new Exception(OrderStatus::getMsg(OrderStatus::PAYWAY_INCORRECT), OrderStatus::PAYWAY_INCORRECT); } return $_pay_obj; } /** * @param string $payway * * @return mixed */ protected function register($payway = '') { $payway = strtolower($payway); $_class = '\\huolib\\withdraw\\driver\\'.$this->payway_map[$payway]; return new $_class(); } }