GmController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * GmController.php UTF-8
  4. *
  5. *
  6. * @date : 2018/6/5 16:44
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\cfloat\controller;
  13. use api\common\controller\CFloatBaseController;
  14. use huo\controller\common\CommonFunc;
  15. use huo\controller\common\HuoSession;
  16. use huo\controller\wallet\Gamemoney;
  17. use huo\controller\wallet\GmCache;
  18. use huolib\constant\DeviceTypeConst;
  19. use huolib\constant\OrderConst;
  20. use huolib\constant\WalletConst;
  21. use huolib\pay\Pay;
  22. use huolib\status\CommonStatus;
  23. use huolib\status\OrderStatus;
  24. use huolib\tool\StrUtils;
  25. use huolib\utils\OrderUtils;
  26. use think\Exception;
  27. class GmController extends CFloatBaseController {
  28. public function _initialize() {
  29. parent::_initialize();
  30. $this->checkLogin();
  31. }
  32. /**
  33. * 游戏充值记录列表
  34. * http://doc.1tsdk.com/138?page_id=3437
  35. * 【域名】/cfloat/gamemoney/recharge_record
  36. */
  37. public function rechargeRecord() {
  38. $_mem_id = $this->mem_id;
  39. $_app_id = get_val($this->rq_data, 'app_id');
  40. $_page = get_val($this->rq_data, 'page', 0); /* 页码 默认为1 代表第一页 1 */
  41. $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
  42. $_status = get_val($this->rq_data, 'status', 0);
  43. $_map = [];
  44. $_order_status = array_keys(OrderConst::getPayStatusMsg(0,true));
  45. if (in_array($_status, $_order_status)) {
  46. $_map['status'] = $_status;
  47. }
  48. $_page = $_page.','.$_offset;
  49. $_where['type'] = WalletConst::WALLET_TYPE_CHARGE;
  50. $_rdata = (new Gamemoney())->getMemChargeList($_mem_id, $_app_id, $_map, $_page);
  51. return $this->returnData($_rdata);
  52. }
  53. /**
  54. * 游戏币充值
  55. * http://doc.1tsdk.com/138?page_id=3441
  56. * 【域名】/cfloat/gamemoney/recharge
  57. */
  58. public function recharge() {
  59. $_app_id = get_val($this->rq_data, 'app_id');
  60. $_gmc_class = GmCache::ins();
  61. $_gm_cnt = $_gmc_class->getRemainByMemGame($this->mem_id, $_app_id);
  62. $_gm_rmb_rate = CommonFunc::getGmRmbRate();
  63. $_pay_type = (new Gamemoney())->getPayWays(0);
  64. $_rdata = [
  65. 'code' => CommonStatus::NO_ERROR,
  66. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  67. 'data' => [
  68. 'gm_cnt' => StrUtils::formatNumber($_gm_cnt),
  69. 'gm_rate' => $_gm_rmb_rate,
  70. 'pay_type' => $_pay_type
  71. ],
  72. ];
  73. return $this->returnData($_rdata);
  74. }
  75. /**
  76. * 选择支付进行支付
  77. * http://doc.1tsdk.com/138?page_id=3442
  78. * 【域名】/cfloat/gamemoney/pay/post
  79. */
  80. public function payPost() {
  81. $_app_id = get_val($this->rq_data, 'app_id');
  82. $_payway = $this->request->param('payway/s', '');
  83. $_amount = $this->request->param('amount/f', 0);
  84. $_pw_check_rs = OrderUtils::checkPayway($_payway);
  85. if (OrderStatus::NO_ERROR != $_pw_check_rs) {
  86. $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);
  87. }
  88. $_amount_chk_rs = OrderUtils::checkAmount($_amount);
  89. if (OrderStatus::NO_ERROR != $_amount_chk_rs) {
  90. $this->error(OrderStatus::getMsg($_amount_chk_rs), [], $_amount_chk_rs);
  91. }
  92. $_type = WalletConst::WALLET_FROM_CHARGE;
  93. $_rdata = (new Gamemoney())->preorder($this->mem_id, $_app_id, $_amount, $_type, $_payway);
  94. if (CommonStatus::NO_ERROR != $_rdata['code']) {
  95. $this->returnData($_rdata);
  96. }
  97. $_order_id = $_rdata['data']['order_id'];
  98. try {
  99. $_pay_class = Pay::ins()->get($_payway);
  100. $_func = $this->getFunc($this->device_type);
  101. $_show_url = url('cfloat/'.$_payway.'/show', ['order_id' => $_order_id], false, APISITE);
  102. $_return_url = url(
  103. 'cfloat/'.$_payway.'/return', ['order_id' => $_order_id], false, APISITE
  104. );
  105. $_pay_class->setReturnUrl($_return_url);
  106. $_pay_class->setShowUrl($_show_url);
  107. $_pay_class->setOrderId($_order_id);
  108. $_product_name = config('GM_CURRENCY_NAME').'充值'.$_amount;
  109. $_pay_class->setProductName($_product_name);
  110. $_pay_class->setProductDesc($_product_name);
  111. $_pay_class->setRealAmount($_amount);
  112. $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_MEM_GM);
  113. $_pay_class->setIp($this->request->ip());
  114. $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId($_app_id));
  115. $_pay_rs = $_pay_class->$_func();
  116. if (empty($_pay_rs)) {
  117. $_code = OrderStatus::PAYWAY_PREORDER_ERROR;
  118. $this->error(OrderStatus::getMsg($_code), [], $_code);
  119. }
  120. $_code = OrderStatus::NO_ERROR;
  121. $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);
  122. } catch (Exception $e) {
  123. $_code = OrderStatus::PAYWAY_NOT_EXISTS;
  124. $this->error(OrderStatus::getMsg($_code), [], $_code);
  125. }
  126. }
  127. /**
  128. * 查询支付结果
  129. * http://doc.1tsdk.com/138?page_id=3443
  130. * 【域名】/cfloat/gamemoney/order/query
  131. */
  132. public function orderQuery() {
  133. $_order_id = $this->request->param('order-order_id/s', '');
  134. $_order = new Gamemoney();
  135. $_rdata = $_order->getStatus($_order_id);
  136. if (false == $_rdata) {
  137. $this->error(lang('ERROR'));
  138. }
  139. $_rdata['order_id'] = $_order_id;
  140. $this->success(lang('SUCCESS'), $_rdata);
  141. }
  142. /**
  143. * @param $device_type
  144. *
  145. * @return string clientPay mobilePay pcPay
  146. */
  147. private function getFunc($device_type) {
  148. switch ($device_type) {
  149. case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:
  150. $_type = 'clientPay';
  151. break;
  152. case DeviceTypeConst::DEVICE_TYPE_IOSSDK:
  153. $_type = 'clientPay';
  154. break;
  155. case DeviceTypeConst::DEVICE_TYPE_IOSAPP:
  156. $_type = 'clientPay';
  157. break;
  158. case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:
  159. $_type = 'clientPay';
  160. break;
  161. case DeviceTypeConst::DEVICE_TYPE_SAFARI:
  162. $_type = 'mobilePay';
  163. break;
  164. case DeviceTypeConst::DEVICE_TYPE_ANDSDK:
  165. $_type = 'clientPay';
  166. break;
  167. case DeviceTypeConst::DEVICE_TYPE_ANDAPP:
  168. $_type = 'clientPay';
  169. break;
  170. case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:
  171. $_type = 'clientPay';
  172. break;
  173. case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:
  174. $_type = 'mobilePay';
  175. break;
  176. case DeviceTypeConst::DEVICE_TYPE_WEIXIN:
  177. $_type = 'jsPay';
  178. break;
  179. case DeviceTypeConst::DEVICE_TYPE_PC:
  180. $_type = 'pcPay';
  181. break;
  182. case DeviceTypeConst::DEVICE_TYPE_WAP:
  183. $_type = 'mobilePay';
  184. break;
  185. default:
  186. $_type = 'mobilePay';
  187. }
  188. return $_type;
  189. }
  190. }