Modules_Api_Controllers_OrderController.proxy.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * 订单回调处理.
  4. * @author zhangjunbao <junbaoz1314@gmail.com>
  5. * @date 2020-01-29 10:13:09
  6. */
  7. declare (strict_types=1);
  8. namespace Modules\Api\Controllers;
  9. use App\Model\VipOrderModel;
  10. use App\Repositories\Service\PaymentService;
  11. use App\Repositories\Service\QueueService;
  12. use Carbon\Carbon;
  13. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  14. use Psr\SimpleCache\CacheInterface;
  15. class OrderController extends BaseController
  16. {
  17. use \Hyperf\Di\Aop\ProxyTrait;
  18. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  19. function __construct()
  20. {
  21. if (method_exists(parent::class, '__construct')) {
  22. parent::__construct(...func_get_args());
  23. }
  24. $this->__handlePropertyHandler(__CLASS__);
  25. }
  26. /**
  27. * 订单回调处理
  28. * @param $type
  29. * @param $orderId
  30. * @param $gateway
  31. */
  32. public function notify($type, $orderId)
  33. {
  34. make(QueueService::class)->addPayNotifyJob(['method' => $this->request->getMethod(), 'order_id' => $orderId, 'order_type' => $type, 'order_gateway' => 1, 'data' => $this->request->all(), 'date' => Carbon::now()->toDateTimeString()]);
  35. $orderId = intval($orderId);
  36. $result = make(PaymentService::class)->notify($orderId, $type);
  37. return $result;
  38. }
  39. /**
  40. * 用户上传-支持成功凭证
  41. */
  42. public function proof(ValidatorFactoryInterface $validatorFactory)
  43. {
  44. $user_id = $this->getUserId();
  45. $inputData = $this->getJsonData();
  46. $rules = ['order_sn' => 'required|string', 'file_path' => 'required|string'];
  47. $validator = $validatorFactory->make($inputData, $rules);
  48. if ($validator->fails()) {
  49. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  50. return json_fail($validator->errors()->first());
  51. }
  52. $order_sn = $inputData['order_sn'];
  53. $file_path = $inputData['file_path'];
  54. $where = ['order_sn' => $order_sn];
  55. $select = '*';
  56. $r = VipOrderModel::query()->selectRaw($select)->where($where)->first();
  57. if (!$r) {
  58. return json_fail('购买记录不存在');
  59. }
  60. if ($r['user_code'] != $user_id) {
  61. return json_fail('此记录不是你的,无权操作');
  62. }
  63. if ($r['payproof_imgs']) {
  64. return json_fail('你已上传凭证了,请勿重复操作');
  65. }
  66. $data = array('payproof_imgs' => $file_path, 'is_user_proof' => 1);
  67. $re = VipOrderModel::query()->where($where)->update($data);
  68. if (!$re) {
  69. return json_fail('上传凭证失败');
  70. }
  71. return json_success('', '上传成功');
  72. }
  73. /**
  74. * 清除支付列表缓存
  75. *
  76. * @return string|void
  77. * @throws \Psr\SimpleCache\InvalidArgumentException
  78. */
  79. public function delPayListsCache()
  80. {
  81. $inputData = request()->all();
  82. if ($inputData['key'] != env('PAY_CENTER_KEY')) {
  83. return json_fail('nook');
  84. }
  85. make(CacheInterface::class)->delete('paymentType');
  86. return json_success('ok');
  87. }
  88. }