Cashierpay.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\store\shopapi\controller;
  13. use addon\store\model\cashier\CashierOrderCalculate;
  14. use addon\store\model\cashier\CashierOrderCommon;
  15. use addon\store\model\cashier\CashierOrderPay;
  16. use app\model\system\Pay as PayModel;
  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. $data = event('Qrcode', [
  96. 'app_type' => 'h5',
  97. 'site_id' => $this->site_id,
  98. 'page' => '/pages/pay/cashier',
  99. 'qrcode_path' => 'upload/qrcode/cashier_pay',
  100. 'qrcode_name' => $out_trade_no,
  101. 'data' => [
  102. 'out_trade_no' => $out_trade_no
  103. ]
  104. ], true);
  105. return $this->response($data);
  106. }
  107. }