Cashierpay.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\cashier\storeapi\controller;
  13. use addon\cashier\model\order\CashierOrderCalculate;
  14. use addon\cashier\model\order\CashierOrderPay;
  15. use app\model\system\Pay as PayModel;
  16. use app\storeapi\controller\BaseStoreApi;
  17. /**
  18. * 收银支付
  19. * Class Pay
  20. * @package app\shop\controller
  21. */
  22. class Cashierpay extends BaseStoreApi
  23. {
  24. /**
  25. * 计算
  26. * @return false|string
  27. */
  28. public function payCalculate()
  29. {
  30. $out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
  31. $promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
  32. $data = array (
  33. 'pay_type' => $this->params[ 'pay_type' ] ?? '',
  34. 'site_id' => $this->site_id,//站点id
  35. 'out_trade_no' => $out_trade_no,
  36. 'store_id' => $this->store_id ?? 0,
  37. 'promotion' => $promotion,
  38. 'member_id' => $this->params[ 'member_id' ],
  39. 'cash' => $this->params[ 'cash' ] ?? 0
  40. );
  41. $cashier_order_calculate_model = new CashierOrderCalculate();
  42. $result = $cashier_order_calculate_model->calculate($data);
  43. //记录缓存(操作记录保存)
  44. $cashier_order_pay_model = new CashierOrderPay();
  45. $cashier_order_pay_model->setCache($out_trade_no, [ 'promotion' => $promotion, 'member_id' => $this->params[ 'member_id' ] ?? 0 ]);
  46. return $this->response($result);
  47. }
  48. /**
  49. * 订单支付
  50. */
  51. public function confirm()
  52. {
  53. $out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
  54. $promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
  55. $cashier_order_pay_model = new CashierOrderPay();
  56. $data = array (
  57. 'pay_type' => $this->params[ 'pay_type' ] ?? '',
  58. 'site_id' => $this->site_id,//站点id
  59. 'out_trade_no' => $out_trade_no,
  60. 'store_id' => $this->store_id ?? 0,
  61. 'promotion' => $promotion,
  62. 'member_id' => $this->params[ 'member_id' ],
  63. 'cash' => $this->params[ 'cash' ] ?? 0
  64. );
  65. $result = $cashier_order_pay_model->confirm($data);
  66. return $this->response($result);
  67. }
  68. /**
  69. * 支付信息
  70. * @return false|string
  71. */
  72. public function info()
  73. {
  74. $out_trade_no = $this->params[ 'out_trade_no' ];
  75. $pay = new PayModel();
  76. $info = $pay->getPayInfo($out_trade_no);
  77. return $this->response($info);
  78. }
  79. /**
  80. * 生成支付二维码
  81. */
  82. public function payQrcode()
  83. {
  84. $out_trade_no = $this->params[ 'out_trade_no' ];
  85. $cashier_order_pay_model = new CashierOrderPay();
  86. $data = array (
  87. 'site_id' => $this->site_id,//站点id
  88. 'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
  89. 'store_id' => $this->store_id ?? 0,
  90. );
  91. $result = $cashier_order_pay_model->createPay($data);
  92. if ($result[ 'code' ] < 0) {
  93. return $this->response($result);
  94. }
  95. if (!empty($result[ 'data' ])) $out_trade_no = $result[ 'data' ];
  96. $data = [];
  97. $pay = new PayModel();
  98. foreach (event('PayType', []) as $item) {
  99. $result = $pay->pay($item[ 'pay_type' ], $out_trade_no, 'cashier', 0);
  100. if ($result && $result[ 'code' ] >= 0) {
  101. array_push($data, [
  102. 'pay_type' => $item[ 'pay_type' ],
  103. 'pay_type_name' => $item[ 'pay_type_name' ],
  104. 'qrcode' => $result[ 'data' ][ 'qrcode' ],
  105. 'logo' => img($item[ 'logo' ]),
  106. 'out_trade_no' => $out_trade_no
  107. ]);
  108. }
  109. }
  110. return $this->response($this->success($data));
  111. }
  112. /**
  113. * 创建支付单据
  114. * @return false|string
  115. */
  116. public function createPay()
  117. {
  118. $cashier_order_pay_model = new CashierOrderPay();
  119. $data = array (
  120. 'site_id' => $this->site_id,//站点id
  121. 'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
  122. 'store_id' => $this->store_id ?? 0,
  123. );
  124. $result = $cashier_order_pay_model->createPay($data);
  125. return $this->response($result);
  126. }
  127. /**
  128. * 会员付款码支付 (已废弃)
  129. */
  130. public function paymentCodePay()
  131. {
  132. $out_trade_no = $this->params[ 'out_trade_no' ];
  133. $auth_code = $this->params[ 'auth_code' ];
  134. return $this->response($this->error());
  135. }
  136. }