Order.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace addons\shop\controller;
  3. use think\Config;
  4. /**
  5. * 订单
  6. * Class Order
  7. * @package addons\shop\controller
  8. */
  9. class Order extends Base
  10. {
  11. protected $noNeedLogin = ['epay'];
  12. protected $noNeedRight = '*';
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. /**
  18. * 订单结算
  19. */
  20. public function checkout()
  21. {
  22. Config::set('shop.title', "订单结算");
  23. return $this->view->fetch('/checkout');
  24. }
  25. /**
  26. * @ DateTime 2021-06-01
  27. * @ 支付回调
  28. * @return void
  29. */
  30. public function epay()
  31. {
  32. $type = $this->request->param('type');
  33. $paytype = $this->request->param('paytype');
  34. if ($type == 'notify') {
  35. $pay = \addons\epay\library\Service::checkNotify($paytype);
  36. if (!$pay) {
  37. echo '签名错误';
  38. return;
  39. }
  40. $data = $pay->verify();
  41. try {
  42. $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  43. \addons\shop\model\Order::settle($data['out_trade_no'], $payamount, $paytype == 'alipay' ? $data['trade_no'] : $data['transaction_id']);
  44. } catch (\Exception $e) {
  45. \think\Log::write($e->getMessage(), 'epay');
  46. }
  47. echo $pay->success();
  48. } elseif ($type == 'return') {
  49. $order_sn = $this->request->param('order_sn');
  50. $this->redirect("index/shop.order/detail", ['orderid' => $order_sn]);
  51. }
  52. return;
  53. }
  54. }