控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Order.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 订单管理
  13. // +----------------------------------------------------------------------
  14. namespace app\cms\controller;
  15. use think\Exception;
  16. class Order extends Cmsbase
  17. {
  18. protected $noNeedLogin = ['epay'];
  19. protected $noNeedRight = [];
  20. //创建订单并发起支付请求
  21. public function submit()
  22. {
  23. if (!$this->auth->isLogin()) {
  24. $this->error('请先登录!', url('member/index/login'));
  25. }
  26. $catid = $this->request->param('catid/d');
  27. $id = $this->request->param('id/d');
  28. $pay_type = $this->request->param('pay_type');
  29. try {
  30. $res = \app\cms\model\Order::submitOrder($catid, $id, $pay_type ? $pay_type : 'wechat');
  31. } catch (Exception $e) {
  32. $this->error($e->getMessage());
  33. }
  34. if ($res) {
  35. $this->success('支付成功');
  36. }
  37. }
  38. //企业支付通知和回调
  39. public function epay()
  40. {
  41. $type = $this->request->param('type');
  42. $pay_type = $this->request->param('pay_type');
  43. if ($type == 'notify') {
  44. $pay = \addons\pay\library\Service::checkNotify($pay_type);
  45. if (!$pay) {
  46. echo '签名错误';
  47. return;
  48. }
  49. try {
  50. $data = $pay->verify();
  51. $payamount = $pay_type == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  52. \app\cms\model\Order::settle($data['out_trade_no'], $payamount);
  53. } catch (Exception $e) {
  54. //写入日志
  55. // $e->getMessage();
  56. }
  57. return $pay->success()->send();
  58. } else {
  59. $pay = \addons\pay\library\Service::checkReturn($pay_type);
  60. if (!$pay) {
  61. $this->error('签名错误');
  62. }
  63. if ($pay === true) {
  64. //微信支付
  65. $data = ['out_trade_no' => $this->request->param('trade_sn')];
  66. } else {
  67. $data = $pay->verify();
  68. }
  69. $order = \app\cms\model\Order::getByTradeSn($data['out_trade_no']);
  70. if (!$order) {
  71. $this->error('订单不存在!');
  72. }
  73. //你可以在这里定义你的提示信息,但切记不可在此编写逻辑
  74. $this->success("恭喜你!支付成功!", buildContentUrl($order['catid'], $order['contentid'], '', true, true));
  75. }
  76. return;
  77. }
  78. }