Gamemoney.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Gamemoney.php UTF-8
  4. *
  5. *
  6. * @date : 2018/6/5 15:40
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\wallet;
  13. use huo\controller\common\Base;
  14. use huo\controller\common\CommonFunc;
  15. use huo\controller\member\MemCache;
  16. use huo\controller\member\MemWallet;
  17. use huo\logic\finance\GmChargeLogic;
  18. use huo\logic\finance\GmOrderLogic;
  19. use huo\model\finance\GmChargeModel;
  20. use huolib\constant\WalletConst;
  21. use huolib\status\CommonStatus;
  22. use huolib\status\MemberStatus;
  23. use huolib\status\OrderStatus;
  24. use huolib\status\SettleStatus;
  25. use huolib\tool\StrUtils;
  26. class Gamemoney extends Base {
  27. protected function retSucMsg($code, $data = []) {
  28. $_msg = OrderStatus::getMsg($code);
  29. return $this->huoSuccess($code, $_msg, $data);
  30. }
  31. protected function retErrMsg($code) {
  32. $_err_msg = OrderStatus::getMsg($code);
  33. return $this->huoError($code, $_err_msg);
  34. }
  35. /**
  36. * 获取游戏币充值记录
  37. * @param $mem_id
  38. * @param $app_id
  39. * @param array $param
  40. * @param string $page
  41. * @param string $order
  42. *
  43. * @return array
  44. */
  45. public function getMemChargeList($mem_id, $app_id, $param = [], $page = '1,10', $order = '-create_time') {
  46. $_data = (new GmChargeLogic())->getMemList($mem_id, $app_id, $param, $page, $order);
  47. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  48. }
  49. /**
  50. * 获取游戏币消费记录
  51. * @param $mem_id
  52. * @param $app_id
  53. * @param array $param
  54. * @param string $page
  55. * @param string $order
  56. *
  57. * @return array
  58. */
  59. public function getMemConsumeList($mem_id, $app_id, $param = [], $page = '1,10', $order = '-create_time') {
  60. $_data = (new GmOrderLogic())->getMemList($mem_id, $app_id, $param, $page, $order);
  61. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  62. }
  63. /**
  64. * 充值游戏币 预下单
  65. *
  66. * @param $mem_id
  67. * @param $app_id
  68. * @param $amount
  69. *
  70. * @param $type
  71. * @param $payway
  72. *
  73. * @return array|bool|string
  74. */
  75. public function preorder($mem_id, $app_id, $amount, $type, $payway) {
  76. if (empty($mem_id)) {
  77. $_code = MemberStatus::LOGIN_IS_OUT;
  78. return $this->huoError($_code, MemberStatus::getMsg($_code));
  79. }
  80. if (empty($amount) || $amount < 1) {
  81. $_code = OrderStatus::ORDER_AMOUNT_MINIMUM_IS_1;
  82. return $this->huoError($_code, OrderStatus::getMsg($_code));
  83. }
  84. $_mc_class = MemCache::ins();
  85. $_mem_data = $_mc_class->getInfoById($mem_id);
  86. $_gmc_class = GmCache::ins();
  87. $_gmc_data = $_gmc_class->getInfoByMemGame($mem_id, $app_id);
  88. if (empty($_mem_data) || empty($_gmc_data)) {
  89. $_code = MemberStatus::UID_INVALID;
  90. return $this->huoError($_code, MemberStatus::getMsg($_code));
  91. }
  92. $_wr_class = new WalletRequest();
  93. $_order_id = StrUtils::genOrderId($_mem_data['agent_id'], $_mem_data['agent_id'], $mem_id, WalletConst::WALLET_ORDER_PREFIX_GC);
  94. $_wr_class->setOrderId($_order_id);
  95. $_wr_class->setRealAmount($amount);
  96. $_wr_class->setType($type);
  97. $_wr_class->setPayway($payway);
  98. $_wr_class->setMemId($mem_id);
  99. $_wr_class->setAppId($app_id);
  100. // TODO: wuyonghong 2018/4/27 折扣处理
  101. $_wr_class->setAmount($amount);
  102. $_gm_cnt = floor($amount * CommonFunc::getGmRmbRate());
  103. $_wr_class->setGmCnt($_gm_cnt);
  104. $_rs = (new MemWallet())->createGmcOrder($_wr_class);
  105. if (SettleStatus::NO_ERROR != $_rs) {
  106. return $this->huoError($_rs, SettleStatus::getMsg($_rs));
  107. }
  108. $_rdata['order_id'] = $_order_id;
  109. return $this->retSucMsg(OrderStatus::NO_ERROR, $_rdata);
  110. }
  111. /**
  112. * @param $order_id
  113. *
  114. * @return bool
  115. */
  116. public function getStatus($order_id = '') {
  117. if (empty($order_id)) {
  118. return false;
  119. }
  120. $_model = new GmChargeModel();
  121. $_rs = $_model->getStatus($order_id);
  122. if (false == $_rs) {
  123. return false;
  124. }
  125. return $_rs;
  126. }
  127. /**
  128. * @param string $app_id
  129. *
  130. * @return array
  131. */
  132. public function getPayWays($app_id) {
  133. // TODO: wuyonghong 2018/4/28 从数据库读取
  134. if (empty($app_id)) {
  135. /* 获取支付方式 */
  136. $_rdata[0]['payway'] = 'alipay';
  137. $_rdata[0]['name'] = '支付宝';
  138. $_rdata[0]['icon'] = '';
  139. $_rdata[0]['url'] = STATICSITE.'/h5sdk/images/arwec.png';
  140. $_rdata[1]['payway'] = 'wxpay';
  141. $_rdata[1]['name'] = '微信';
  142. $_rdata[1]['icon'] = STATICSITE.'/h5sdk/images/wergcder.png';
  143. $_rdata[1]['url'] = '支付宝';
  144. }
  145. /* 获取支付方式 */
  146. $_rdata[0]['payway'] = 'alipay';
  147. $_rdata[0]['name'] = '支付宝';
  148. $_rdata[0]['icon'] = STATICSITE.'/h5sdk/images/arwec.png';
  149. $_rdata[0]['url'] = '支付宝';
  150. $_rdata[1]['payway'] = 'wxpay';
  151. $_rdata[1]['name'] = '微信';
  152. $_rdata[1]['icon'] = STATICSITE.'/h5sdk/images/wergcder.png';
  153. $_rdata[1]['url'] = '微信';
  154. return $_rdata;
  155. }
  156. /**
  157. * 查询微信订单
  158. *
  159. * @param $order_id
  160. */
  161. public function queryWxOrder($order_id) {
  162. // TODO: wuyonghong 2018/5/7 查询订单完成情况
  163. }
  164. }