123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- /**
- * GmController.php UTF-8
- *
- *
- * @date : 2018/6/5 16:44
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace api\cfloat\controller;
- use api\common\controller\CFloatBaseController;
- use huo\controller\common\CommonFunc;
- use huo\controller\common\HuoSession;
- use huo\controller\wallet\Gamemoney;
- use huo\controller\wallet\GmCache;
- use huolib\constant\DeviceTypeConst;
- use huolib\constant\OrderConst;
- use huolib\constant\WalletConst;
- use huolib\pay\Pay;
- use huolib\status\CommonStatus;
- use huolib\status\OrderStatus;
- use huolib\tool\StrUtils;
- use huolib\utils\OrderUtils;
- use think\Exception;
- class GmController extends CFloatBaseController {
- public function _initialize() {
- parent::_initialize();
- $this->checkLogin();
- }
- /**
- * 游戏充值记录列表
- * http://doc.1tsdk.com/138?page_id=3437
- * 【域名】/cfloat/gamemoney/recharge_record
- */
- public function rechargeRecord() {
- $_mem_id = $this->mem_id;
- $_app_id = get_val($this->rq_data, 'app_id');
- $_page = get_val($this->rq_data, 'page', 0); /* 页码 默认为1 代表第一页 1 */
- $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
- $_status = get_val($this->rq_data, 'status', 0);
- $_map = [];
- $_order_status = array_keys(OrderConst::getPayStatusMsg(0,true));
- if (in_array($_status, $_order_status)) {
- $_map['status'] = $_status;
- }
- $_page = $_page.','.$_offset;
- $_where['type'] = WalletConst::WALLET_TYPE_CHARGE;
- $_rdata = (new Gamemoney())->getMemChargeList($_mem_id, $_app_id, $_map, $_page);
- return $this->returnData($_rdata);
- }
- /**
- * 游戏币充值
- * http://doc.1tsdk.com/138?page_id=3441
- * 【域名】/cfloat/gamemoney/recharge
- */
- public function recharge() {
- $_app_id = get_val($this->rq_data, 'app_id');
- $_gmc_class = GmCache::ins();
- $_gm_cnt = $_gmc_class->getRemainByMemGame($this->mem_id, $_app_id);
- $_gm_rmb_rate = CommonFunc::getGmRmbRate();
- $_pay_type = (new Gamemoney())->getPayWays(0);
- $_rdata = [
- 'code' => CommonStatus::NO_ERROR,
- 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
- 'data' => [
- 'gm_cnt' => StrUtils::formatNumber($_gm_cnt),
- 'gm_rate' => $_gm_rmb_rate,
- 'pay_type' => $_pay_type
- ],
- ];
- return $this->returnData($_rdata);
- }
- /**
- * 选择支付进行支付
- * http://doc.1tsdk.com/138?page_id=3442
- * 【域名】/cfloat/gamemoney/pay/post
- */
- public function payPost() {
- $_app_id = get_val($this->rq_data, 'app_id');
- $_payway = $this->request->param('payway/s', '');
- $_amount = $this->request->param('amount/f', 0);
- $_pw_check_rs = OrderUtils::checkPayway($_payway);
- if (OrderStatus::NO_ERROR != $_pw_check_rs) {
- $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);
- }
- $_amount_chk_rs = OrderUtils::checkAmount($_amount);
- if (OrderStatus::NO_ERROR != $_amount_chk_rs) {
- $this->error(OrderStatus::getMsg($_amount_chk_rs), [], $_amount_chk_rs);
- }
- $_type = WalletConst::WALLET_FROM_CHARGE;
- $_rdata = (new Gamemoney())->preorder($this->mem_id, $_app_id, $_amount, $_type, $_payway);
- if (CommonStatus::NO_ERROR != $_rdata['code']) {
- $this->returnData($_rdata);
- }
- $_order_id = $_rdata['data']['order_id'];
- try {
- $_pay_class = Pay::ins()->get($_payway);
- $_func = $this->getFunc($this->device_type);
- $_show_url = url('cfloat/'.$_payway.'/show', ['order_id' => $_order_id], false, APISITE);
- $_return_url = url(
- 'cfloat/'.$_payway.'/return', ['order_id' => $_order_id], false, APISITE
- );
- $_pay_class->setReturnUrl($_return_url);
- $_pay_class->setShowUrl($_show_url);
- $_pay_class->setOrderId($_order_id);
- $_product_name = config('GM_CURRENCY_NAME').'充值'.$_amount;
- $_pay_class->setProductName($_product_name);
- $_pay_class->setProductDesc($_product_name);
- $_pay_class->setRealAmount($_amount);
- $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_MEM_GM);
- $_pay_class->setIp($this->request->ip());
- $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId($_app_id));
- $_pay_rs = $_pay_class->$_func();
- if (empty($_pay_rs)) {
- $_code = OrderStatus::PAYWAY_PREORDER_ERROR;
- $this->error(OrderStatus::getMsg($_code), [], $_code);
- }
- $_code = OrderStatus::NO_ERROR;
- $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);
- } catch (Exception $e) {
- $_code = OrderStatus::PAYWAY_NOT_EXISTS;
- $this->error(OrderStatus::getMsg($_code), [], $_code);
- }
- }
- /**
- * 查询支付结果
- * http://doc.1tsdk.com/138?page_id=3443
- * 【域名】/cfloat/gamemoney/order/query
- */
- public function orderQuery() {
- $_order_id = $this->request->param('order-order_id/s', '');
- $_order = new Gamemoney();
- $_rdata = $_order->getStatus($_order_id);
- if (false == $_rdata) {
- $this->error(lang('ERROR'));
- }
- $_rdata['order_id'] = $_order_id;
- $this->success(lang('SUCCESS'), $_rdata);
- }
- /**
- * @param $device_type
- *
- * @return string clientPay mobilePay pcPay
- */
- private function getFunc($device_type) {
- switch ($device_type) {
- case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_IOSSDK:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_IOSAPP:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_SAFARI:
- $_type = 'mobilePay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_ANDSDK:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_ANDAPP:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:
- $_type = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:
- $_type = 'mobilePay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_WEIXIN:
- $_type = 'jsPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_PC:
- $_type = 'pcPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_WAP:
- $_type = 'mobilePay';
- break;
- default:
- $_type = 'mobilePay';
- }
- return $_type;
- }
- }
|