Cashierpay.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. use app\model\member\MemberAccount as MemberAccountModel;
  18. /**
  19. * 收银支付
  20. * Class Pay
  21. * @package app\shop\controller
  22. */
  23. class Cashierpay extends BaseStoreApi
  24. {
  25. /**
  26. * 计算
  27. * @return false|string
  28. */
  29. public function payCalculate()
  30. {
  31. $out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
  32. $promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
  33. $data = array (
  34. 'pay_type' => $this->params[ 'pay_type' ] ?? '',
  35. 'site_id' => $this->site_id,//站点id
  36. 'out_trade_no' => $out_trade_no,
  37. 'store_id' => $this->store_id ?? 0,
  38. 'promotion' => $promotion,
  39. 'member_id' => $this->params[ 'member_id' ],
  40. 'cash' => $this->params[ 'cash' ] ?? 0
  41. );
  42. $cashier_order_calculate_model = new CashierOrderCalculate();
  43. $result = $cashier_order_calculate_model->calculate($data);
  44. $result['data']['adjust_money'] = 123;
  45. // $this->joinyuelog($result['data']['member_account']['member_id'],$result['data']['order_money'],$result['data']['store_id']);
  46. $result['data']['balance'] = "12.00";
  47. $result['data']['balance_money'] = "12.00";
  48. $result['data']['total_money'] = "123.00";
  49. $result['data']['total_balance'] = "123.00";
  50. $result['data']['pay_money'] = "1213.00";
  51. //记录缓存(操作记录保存)
  52. $cashier_order_pay_model = new CashierOrderPay();
  53. $cashier_order_pay_model->setCache($out_trade_no, [ 'promotion' => $promotion, 'member_id' => $this->params[ 'member_id' ] ?? 0 ]);
  54. return $this->response($result);
  55. }
  56. /**
  57. * 订单支付
  58. */
  59. public function confirm()
  60. {
  61. $out_trade_no = $this->params[ 'out_trade_no' ] ?? '';
  62. $promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
  63. $cashier_order_pay_model = new CashierOrderPay();
  64. $data = array (
  65. 'pay_type' => $this->params[ 'pay_type' ] ?? '',
  66. 'site_id' => $this->site_id,//站点id
  67. 'out_trade_no' => $out_trade_no,
  68. 'store_id' => $this->store_id ?? 0,
  69. 'promotion' => $promotion,
  70. 'member_id' => $this->params[ 'member_id' ],
  71. 'cash' => $this->params[ 'cash' ] ?? 0
  72. );
  73. $result = $cashier_order_pay_model->confirm($data);
  74. //创建余额支付记录
  75. return $this->response($result);
  76. }
  77. public function joinyuelog($member_id,$adjust_num,$store_id){
  78. $remark = input('remark', '商家调整');
  79. $this->addLog("会员余额调整id:" . $member_id . "金额" . $adjust_num);
  80. $member_account_model = new MemberAccountModel();
  81. return $member_account_model->addMemberAccountnew($this->site_id, $member_id, 'balance', $adjust_num, 'adjust', 0, $remark ? $remark : '商家调整',0,$store_id);
  82. }
  83. /**
  84. * 支付信息
  85. * @return false|string
  86. */
  87. public function info()
  88. {
  89. $out_trade_no = $this->params[ 'out_trade_no' ];
  90. $pay = new PayModel();
  91. $info = $pay->getPayInfo($out_trade_no);
  92. return $this->response($info);
  93. }
  94. /**
  95. * 生成支付二维码
  96. */
  97. public function payQrcode()
  98. {
  99. $out_trade_no = $this->params[ 'out_trade_no' ];
  100. $cashier_order_pay_model = new CashierOrderPay();
  101. $data = array (
  102. 'site_id' => $this->site_id,//站点id
  103. 'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
  104. 'store_id' => $this->store_id ?? 0,
  105. );
  106. $result = $cashier_order_pay_model->createPay($data);
  107. if ($result[ 'code' ] < 0) {
  108. return $this->response($result);
  109. }
  110. $data = [];
  111. $pay = new PayModel();
  112. foreach (event('PayType', []) as $item) {
  113. $result = $pay->pay($item[ 'pay_type' ], $out_trade_no, 'cashier', 0);
  114. if ($result && $result[ 'code' ] == 0) {
  115. array_push($data, [
  116. 'pay_type' => $item[ 'pay_type' ],
  117. 'pay_type_name' => $item[ 'pay_type_name' ],
  118. 'qrcode' => $result[ 'data' ][ 'qrcode' ],
  119. 'logo' => img($item[ 'logo' ])
  120. ]);
  121. }
  122. }
  123. return $this->response($this->success($data));
  124. }
  125. /**
  126. * 创建支付单据
  127. * @return false|string
  128. */
  129. public function createPay()
  130. {
  131. $cashier_order_pay_model = new CashierOrderPay();
  132. $data = array (
  133. 'site_id' => $this->site_id,//站点id
  134. 'out_trade_no' => $this->params[ 'out_trade_no' ] ?? '',
  135. 'store_id' => $this->store_id ?? 0,
  136. );
  137. $result = $cashier_order_pay_model->createPay($data);
  138. return $this->response($result);
  139. }
  140. /**
  141. * 会员付款码支付 (已废弃)
  142. */
  143. public function paymentCodePay()
  144. {
  145. $out_trade_no = $this->params[ 'out_trade_no' ];
  146. $auth_code = $this->params[ 'auth_code' ];
  147. return $this->response($this->error());
  148. }
  149. }