Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Order.php UTF-8
  4. * 订单处理
  5. *
  6. * @date : 2020/9/15 10:27
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : H5IOS 1.0
  11. */
  12. namespace huosdk\h5ios\core\controller;
  13. use huo\controller\pay\PaySwitch;
  14. use huo\controller\pay\Sdk;
  15. use huo\controller\request\Channel;
  16. use huo\controller\request\Device;
  17. use huo\controller\request\Game as GameRq;
  18. use huo\controller\request\Mem;
  19. use huo\controller\request\Order as OrderRq;
  20. use huo\controller\request\Role;
  21. use huoIdentify\controller\Pay;
  22. use huolib\status\CommonStatus;
  23. use huosdk\h5ios\core\constant\GameConst;
  24. use huosdk\h5ios\core\constant\OrderConst;
  25. use huosdk\h5ios\core\constant\PaywayConst;
  26. use huosdk\h5ios\core\model\GameModel;
  27. use huosdk\h5ios\core\model\GamePriceModel;
  28. use huosdk\h5ios\core\model\PayAppleModel;
  29. use huosdk\h5ios\core\status\GameStatus;
  30. use huosdk\h5ios\core\status\OrderStatus;
  31. class Order extends Base {
  32. public function __construct() {
  33. parent::__construct();
  34. }
  35. /**
  36. * 预下单
  37. *
  38. * @param OrderRq $order
  39. * @param Role $role
  40. * @param Mem $mem
  41. * @param GameRq $game_rq
  42. * @param Channel $channel
  43. * @param Device $device
  44. *
  45. * @return array|bool|string
  46. */
  47. public function preorder(OrderRq $order, Role $role, Mem $mem, GameRq $game_rq, Channel $channel, Device $device) {
  48. $_vb_id = $game_rq->getVbId();
  49. $_vb_info = (new GameModel())->getInfoById($_vb_id);
  50. $_classify = get_val($_vb_info, 'classify', 0);
  51. if (GameConst::GAME_IOS_SWITCH_H5 != $_classify) {
  52. $_code = GameStatus::GAME_VB_NOT_EXIST;
  53. return $this->huoError($_code, GameStatus::getMsg($_code));
  54. }
  55. $_game_product_id = $order->getProductId();
  56. $_game_price_model = new GamePriceModel();
  57. $_apple_product_id = $_game_price_model->getProductByAppChProduct($_vb_id, $_game_product_id);
  58. if (!empty($_apple_product_id)) {
  59. $order->setProductId($_apple_product_id);
  60. }
  61. $_price = $_game_price_model->getPriceByAppProduct($_vb_id, $order->getProductId());
  62. $_product_price = $order->getProductPrice();
  63. if (!empty($_price) && $_price != $_product_price) {
  64. $order->setProductPrice($_price);
  65. }
  66. $order->setPayway(PaywayConst::PAYWAY_APPLE);
  67. $_order = new Sdk();
  68. /* 判断支付切换 */
  69. $_pay_check = (new PaySwitch())->getPaySwitch(
  70. $order, $role, $mem, $game_rq, $channel, $device
  71. );
  72. $_preorder_rs = $_order->preorder($order, $role, $mem, $game_rq, $channel, $device);
  73. if (OrderStatus::NO_ERROR != $_preorder_rs['code']) {
  74. return $this->huoReturn($_preorder_rs);
  75. }
  76. $_order_data = $_preorder_rs['data'];
  77. $_order_id = $_order_data['order_id'];
  78. $_pay_token = $order->genPayToken($_order_id);
  79. $_rdata['order_id'] = $_order_id;
  80. $_rdata['pay_token'] = $_pay_token;
  81. $_rdata['check'] = $_pay_check;
  82. $_rdata['pay_url'] = '';
  83. $_rdata['product_id'] = $_apple_product_id;
  84. /* 支付限制校验 */
  85. $_rdata['url'] = (new Pay())->checkLimit($mem->getMemId(), $game_rq->getHAppId(), $_order_data['amount']);
  86. /* 苹果下单 不切换 直接插入苹果订单表 */
  87. if (OrderConst::PAY_SWITCH_NO == $_pay_check) {
  88. $_data['order_id'] = $_order_id;
  89. $_data['mem_id'] = $mem->getMemId();
  90. $_data['mg_mem_id'] = $mem->getMgMemId();
  91. $_data['apple_id'] = $game_rq->getAppleId();
  92. $_data['product_id'] = $_apple_product_id;
  93. $_data['idfv'] = $device->getMac();
  94. $_data['idfa'] = $device->getDeviceId();
  95. (new PayAppleModel())->addData($_data);
  96. }
  97. $_code = CommonStatus::NO_ERROR;
  98. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  99. }
  100. }