PtbPay.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * PtbPay.php UTF-8
  4. * 平台币支付
  5. *
  6. * @date : 2018/5/18 21:19
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\pay;
  13. use huo\controller\common\Base;
  14. use huo\controller\common\CommonFunc;
  15. use huo\controller\member\MemCache;
  16. use huolib\constant\CommonConst;
  17. use huolib\constant\OrderConst;
  18. use huolib\constant\PaywayConst;
  19. use huolib\status\MemberStatus;
  20. use huolib\status\OrderStatus;
  21. use huolib\status\SettleStatus;
  22. use huolib\tool\StrUtils;
  23. class PtbPay extends Base {
  24. /**
  25. * 平台币SDK支付
  26. *
  27. * @param string $order_id 订单ID
  28. *
  29. * @return array
  30. */
  31. public function ptbSdkPay($order_id) {
  32. $_soc_class = SdkOrderCache::ins();
  33. $_order_data = $_soc_class->getInfoByOrderId($order_id);
  34. $_order_data['payway'] = PaywayConst::PAYWAY_PTBPAY;
  35. $_soc_class->saveOrderCache($order_id, $_order_data);
  36. if ($_order_data == false) {
  37. $_code = OrderStatus::ORDER_NOT_EXISTS;
  38. return $this->huoError($_code, OrderStatus::getMsg($_code));
  39. }
  40. /* 实际支付金额为0 */
  41. $_order_data['real_amount'] = 0;
  42. /* 平台币支付所有金额 */
  43. $_order_data['ptb_amount'] = $_order_data['amount'];
  44. $_soc_class->updateOrder($order_id, $_order_data);
  45. /* Modified by wuyonghong BEGIN 2018/3/26 ISSUES:5314 LTV */
  46. /* 充值时计算LTV */
  47. $_ltv_class = new \ltv\Ltv();
  48. $_mem_data = (new \huo\model\member\MemberModel())->getInfoById(
  49. $_order_data['mem_id']
  50. );//field($_field)->where($_map)->find();
  51. $_ltv_class->charge(
  52. $_mem_data['app_id'],
  53. $_mem_data['agent_id'],
  54. $_order_data['app_id'],
  55. $_order_data['amount'],
  56. $_order_data['update_time'],
  57. $_mem_data['create_time']
  58. );
  59. /* END 2018/3/26 ISSUES:5314 */
  60. $_rs = (new Notify())->doAfterPayNotify($order_id);
  61. $_cp_status = OrderConst::CP_STATUS_SUC;
  62. if (OrderStatus::NOTIFY_FAIL == $_rs['code']) {
  63. $_cp_status = OrderConst::CP_STATUS_NOT;
  64. } else {
  65. if (SettleStatus::NO_ERROR != $_rs['code']) {
  66. return $this->huoReturn($_rs);
  67. }
  68. }
  69. $_rdata = $this->clientAjax($_order_data['payway'], $order_id, 2, 2, $_cp_status);
  70. $_code = OrderStatus::NO_ERROR;
  71. return $this->huoSuccess($_code, OrderStatus::getMsg($_code), $_rdata);
  72. }
  73. /**
  74. * 扣除平台币
  75. *
  76. * @param string $order_id 订单ID
  77. *
  78. * @return array
  79. */
  80. public function PtbOrder($order_id) {
  81. $_soc_class = SdkOrderCache::ins();
  82. $_order_data = $_soc_class->getInfoByOrderId($order_id);
  83. if (false == $_order_data) {
  84. $_code = OrderStatus::ORDER_NOT_EXISTS;
  85. return $this->huoError($_code, OrderStatus::getMsg($_code));
  86. }
  87. $_me_data = MemCache::ins()->getMeInfoById($_order_data['mem_id']);
  88. if (empty($_me_data)) {
  89. $_code = MemberStatus::UID_NOT_EXISTS;
  90. return $this->huoError($_code, MemberStatus::getMsg($_code));
  91. }
  92. /* 订单金额与平台币金额比对 */
  93. $_ptb_cnt = $_me_data['ptb_cnt'];
  94. $_ptb_rate = CommonFunc::getPtbRmbRate();
  95. $_mem_ptb_amount = StrUtils::formatNumber($_ptb_cnt / $_ptb_rate, 2);
  96. if ($_mem_ptb_amount > CommonConst::CONST_ZERO_COMPARE && $_mem_ptb_amount < $_order_data['amount']) {
  97. /* 平台币金额少于订单金额 还需其他支付 */
  98. $_order_data['ptb_amount'] = $_mem_ptb_amount;
  99. $_order_data['real_amount'] = StrUtils::formatNumber($_order_data['amount'] - $_order_data['ptb_amount']);
  100. $_soc_class->updateOrder($order_id, $_order_data);
  101. $_code = OrderStatus::NO_ERROR;
  102. } elseif ($_mem_ptb_amount >= $_order_data['amount']) {
  103. /* 平台币金额大于订单金额 */
  104. $_order_data['ptb_amount'] = $_order_data['amount'];
  105. $_order_data['real_amount'] = StrUtils::formatNumber($_order_data['amount'] - $_order_data['ptb_amount']);
  106. $_soc_class->updateOrder($order_id, $_order_data);
  107. $_code = OrderStatus::NO_ERROR;
  108. } else {
  109. /* 不处理扣除平台币 */
  110. $_code = OrderStatus::NO_ERROR;
  111. }
  112. return $this->huoSuccess($_code, OrderStatus::getMsg($_code));
  113. }
  114. /**
  115. * 游戏客户端的标准返回
  116. *
  117. * @param $payway
  118. * @param $order_id
  119. * @param int $status
  120. * @param int $is_native
  121. * @param int $cp_status
  122. *
  123. * @return mixed
  124. */
  125. public function clientAjax($payway, $order_id, $status = 1, $is_native = 2, $cp_status = 2) {
  126. $_rdata['pay_type'] = $payway;
  127. $_rdata['order_id'] = $order_id;
  128. $_rdata['real_amount'] = 0;
  129. $_rdata['token'] = $order_id;
  130. $_rdata['is_native'] = $is_native;
  131. $_rdata['status'] = $status;
  132. $_rdata['cp_status'] = $cp_status;
  133. return $_rdata;
  134. }
  135. }