123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- /**
- * OrderOut.php UTF-8
- *
- *
- * @date : 2018/8/10 17:27
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\controller\order;
- use huo\controller\common\Base;
- use huo\controller\game\GamePaySwitchCache;
- use huo\controller\pay\SdkOrderCache;
- use huo\controller\queue\OrderQrQueue;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use huolib\constant\MpConfConst;
- use huolib\status\OrderStatus;
- use huomp\controller\game\GameMini;
- use huomp\controller\share\QrCodeOut;
- use huoMpQr\QrCode;
- use think\Cache;
- use think\Log;
- class OrderOut extends Base {
- /**
- * 预下单米大师支付数据
- *
- * @param string $order_id 订单ID
- * @param bool $is_sand 是否沙盒
- *
- * @return array
- */
- public function getMpayData($order_id, $is_sand = false) {
- $_order_data = SdkOrderCache::ins()->getInfoByOrderId($order_id);
- if (empty($_order_data)) {
- $_code = OrderStatus::ORDER_ID_ERROR;
- return $this->huoError($_code, OrderStatus::getMsg($_code));
- }
- $_env = MpConfConst::MP_MPPAY_NORMAL; //默认是正式环境
- if (true == $is_sand) {
- $_env = MpConfConst::MP_MPPAY_TEST; //沙箱走测试环境
- }
- $_mpay_conf = (new GameMini())->getMpayConf($_order_data['app_id'], $is_sand);
- $_rdata['mode'] = 'game';
- $_rdata['env'] = $_env;
- $_rdata['offer_id'] = $_mpay_conf['offer_id'];
- $_rdata['currency'] = 'CNY';
- $_rdata['platform'] = 'android';
- $_rdata['buy_quantity'] = $_order_data['real_amount'] * $_mpay_conf['mini_rate'];
- $_rdata['zone_id'] = '1';
- $_code = OrderStatus::NO_ERROR;
- $_order_data['product_cnt'] = $_rdata['buy_quantity'];
- $_rs = SdkOrderCache::ins()->updateOrder($order_id, $_order_data);
- if (false == $_rs) {
- $_code = OrderStatus::UNKNOWN_ERROR;
- }
- return $this->huoSuccess($_code, OrderStatus::getMsg($_code), $_rdata);
- }
- /**
- * 获取切换配置
- *
- * @param int $app_id 游戏ID
- *
- * @return bool|array
- */
- public function getSwitchAppPath($app_id) {
- $_switch_data = GamePaySwitchCache::ins()->getInfoByAppId($app_id);
- if (empty($_switch_data)) {
- // Log::write(
- // 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&app_id='.$app_id
- // .'&error=switch_data is null', Log::ERROR
- // );
- return false;
- }
- $_rdata['path'] = $_switch_data['pages'];
- $_rdata['switch_app_id'] = $_switch_data['switch_app_id'];
- return $_rdata;
- }
- /**
- * 获取玩家游戏支付二维码
- *
- * @param $mem_id
- * @param $app_id
- *
- * @return bool
- */
- public function genMemAppQrCodeQueue($mem_id, $app_id) {
- $_switch_data = $this->getSwitchAppPath($app_id);
- if (empty($_switch_data)) {
- return false;
- }
- $_path = $_switch_data['path'];
- $_switch_app_id = $_switch_data['switch_app_id'];
- $_key = CacheConst::CACHE_MEM_APP_ORDER_PREFIX.md5(json_encode(array($mem_id, $app_id, $_switch_app_id)));
- $_image = Cache::get($_key);
- if (!empty($_image)) {
- /* 入队列 */
- return true;
- }
- $_order_id = $mem_id.'&'.$app_id;
- $_rdata = (new QrCodeOut())->getOrderQrCode(
- $_order_id, $_switch_app_id, $_path
- );
- $_image = !empty($_rdata['data']['image']) ? $_rdata['data']['image'] : '';
- if (empty($_image)) {
- Log::write(
- 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&mem_id='.$mem_id.'&app_id='.$app_id
- .'&rdata='.json_encode($_rdata).'获取二维码错误', Log::ERROR
- );
- return false;
- }
- Cache::set($_key, $_image, CommonConst::CONST_MONTH_SECONDS);
- return true;
- }
- /**
- * 获取订单支付二维码
- *
- * @param string $order_id 订单ID
- *
- * @return bool
- */
- public function genOrderQrQueue($order_id) {
- $_order_data = SdkOrderCache::ins()->getInfoByOrderId($order_id);
- if (empty($_order_data)) {
- return false;
- }
- $_app_id = $_order_data['app_id'];
- $_switch_data = $this->getSwitchAppPath($_app_id);
- if (empty($_switch_data)) {
- return false;
- }
- $_path = $_switch_data['path'];
- $_switch_app_id = $_switch_data['switch_app_id'];
- $_key = CacheConst::CACHE_MEM_APP_ORDER_PREFIX.$order_id;
- $_image = Cache::get($_key);
- if (!empty($_image)) {
- return true;
- }
- $_rdata = (new QrCodeOut())->getOrderQrCode(
- $order_id, $_switch_app_id, $_path
- );
- $_image = !empty($_rdata['data']['image']) ? $_rdata['data']['image'] : '';
- if (empty($_image)) {
- Log::write(
- 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&order_id='.$order_id
- .'&rdata='.json_encode($_rdata).'获取二维码错误', Log::ERROR
- );
- return false;
- }
- Cache::set($_key, $_image, CommonConst::CONST_DAY_SECONDS);
- return true;
- }
- /**
- * 获取玩家游戏支付二维码
- *
- * @param int $mem_id 玩家ID
- * @param int $app_id 游戏ID
- * @param bool $must_get
- *
- * @return bool
- */
- public function getMemAppQrCode($mem_id, $app_id, $must_get = false) {
- $_switch_data = $this->getSwitchAppPath($app_id);
- if (empty($_switch_data)) {
- return false;
- }
- $_switch_app_id = $_switch_data['switch_app_id'];
- $_key = CacheConst::CACHE_MEM_APP_ORDER_PREFIX.md5(json_encode(array($mem_id, $app_id, $_switch_app_id)));
- $_image = Cache::get($_key);
- $_param['mem_id'] = $mem_id;
- $_param['app_id'] = $app_id;
- if (empty($_image) && false == $must_get) {
- /* 入队列 */
- (new OrderQrQueue($_param))->pushQueue();
- return '';
- } elseif (empty($_image) && true == $must_get) {
- $_rs = $this->genMemAppQrCodeQueue($mem_id, $app_id);
- if (false == $_rs) {
- Log::write(
- 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&mem_id='.$mem_id.'&app_id='.$app_id
- .'获取支付二维码错误', Log::ERROR
- );
- }
- $_image = Cache::get($_key);
- }
- return cmf_get_image_url($_image);
- }
- }
|