* @version : H5IOS 1.0 */ namespace huosdk\h5ios\core\controller; use huo\controller\pay\PaySwitch; use huo\controller\pay\Sdk; use huo\controller\request\Channel; use huo\controller\request\Device; use huo\controller\request\Game as GameRq; use huo\controller\request\Mem; use huo\controller\request\Order as OrderRq; use huo\controller\request\Role; use huoIdentify\controller\Pay; use huolib\status\CommonStatus; use huosdk\h5ios\core\constant\GameConst; use huosdk\h5ios\core\constant\OrderConst; use huosdk\h5ios\core\constant\PaywayConst; use huosdk\h5ios\core\model\GameModel; use huosdk\h5ios\core\model\GamePriceModel; use huosdk\h5ios\core\model\PayAppleModel; use huosdk\h5ios\core\status\GameStatus; use huosdk\h5ios\core\status\OrderStatus; class Order extends Base { public function __construct() { parent::__construct(); } /** * 预下单 * * @param OrderRq $order * @param Role $role * @param Mem $mem * @param GameRq $game_rq * @param Channel $channel * @param Device $device * * @return array|bool|string */ public function preorder(OrderRq $order, Role $role, Mem $mem, GameRq $game_rq, Channel $channel, Device $device) { $_vb_id = $game_rq->getVbId(); $_vb_info = (new GameModel())->getInfoById($_vb_id); $_classify = get_val($_vb_info, 'classify', 0); if (GameConst::GAME_IOS_SWITCH_H5 != $_classify) { $_code = GameStatus::GAME_VB_NOT_EXIST; return $this->huoError($_code, GameStatus::getMsg($_code)); } $_game_product_id = $order->getProductId(); $_game_price_model = new GamePriceModel(); $_apple_product_id = $_game_price_model->getProductByAppChProduct($_vb_id, $_game_product_id); if (!empty($_apple_product_id)) { $order->setProductId($_apple_product_id); } $_price = $_game_price_model->getPriceByAppProduct($_vb_id, $order->getProductId()); $_product_price = $order->getProductPrice(); if (!empty($_price) && $_price != $_product_price) { $order->setProductPrice($_price); } $order->setPayway(PaywayConst::PAYWAY_APPLE); $_order = new Sdk(); /* 判断支付切换 */ $_pay_check = (new PaySwitch())->getPaySwitch( $order, $role, $mem, $game_rq, $channel, $device ); $_preorder_rs = $_order->preorder($order, $role, $mem, $game_rq, $channel, $device); if (OrderStatus::NO_ERROR != $_preorder_rs['code']) { return $this->huoReturn($_preorder_rs); } $_order_data = $_preorder_rs['data']; $_order_id = $_order_data['order_id']; $_pay_token = $order->genPayToken($_order_id); $_rdata['order_id'] = $_order_id; $_rdata['pay_token'] = $_pay_token; $_rdata['check'] = $_pay_check; $_rdata['pay_url'] = ''; $_rdata['product_id'] = $_apple_product_id; /* 支付限制校验 */ $_rdata['url'] = (new Pay())->checkLimit($mem->getMemId(), $game_rq->getHAppId(), $_order_data['amount']); /* 苹果下单 不切换 直接插入苹果订单表 */ if (OrderConst::PAY_SWITCH_NO == $_pay_check) { $_data['order_id'] = $_order_id; $_data['mem_id'] = $mem->getMemId(); $_data['mg_mem_id'] = $mem->getMgMemId(); $_data['apple_id'] = $game_rq->getAppleId(); $_data['product_id'] = $_apple_product_id; $_data['idfv'] = $device->getMac(); $_data['idfa'] = $device->getDeviceId(); (new PayAppleModel())->addData($_data); } $_code = CommonStatus::NO_ERROR; return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata); } }