OrderController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  18. * 订单回调处理
  19. * @param $type
  20. * @param $orderId
  21. * @param $gateway
  22. */
  23. public function notify($type, $orderId)
  24. {
  25. make(QueueService::class)->addPayNotifyJob(
  26. [
  27. 'method' => $this->request->getMethod(),
  28. 'order_id' => $orderId,
  29. 'order_type' => $type,
  30. 'order_gateway' => 1,
  31. 'data' => $this->request->all(),
  32. 'date' => Carbon::now()->toDateTimeString(),
  33. ]
  34. );
  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 = [
  47. 'order_sn' => 'required|string',
  48. 'file_path' => 'required|string', //客户端先请求"上传(视频/图片)"接口 拿到上传成功后的路径值,原样传过来
  49. ];
  50. $validator = $validatorFactory->make($inputData, $rules);
  51. if ($validator->fails()) {
  52. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  53. return json_fail($validator->errors()->first());
  54. }
  55. $order_sn = $inputData['order_sn'];
  56. $file_path = $inputData['file_path'];
  57. $where = ['order_sn'=>$order_sn];
  58. $select = '*';
  59. $r = VipOrderModel::query()
  60. ->selectRaw($select)
  61. ->where($where)
  62. ->first();
  63. if (!$r) {
  64. return json_fail('购买记录不存在');
  65. }
  66. if ($r['user_code'] != $user_id) {
  67. return json_fail('此记录不是你的,无权操作');
  68. }
  69. if ($r['payproof_imgs']) {
  70. return json_fail('你已上传凭证了,请勿重复操作');
  71. }
  72. $data = array(
  73. 'payproof_imgs' => $file_path,
  74. 'is_user_proof' => 1,
  75. );
  76. $re = VipOrderModel::query()
  77. ->where($where)
  78. ->update($data);
  79. if (!$re) {
  80. return json_fail('上传凭证失败');
  81. }
  82. return json_success('', '上传成功');
  83. }
  84. /**
  85. * 清除支付列表缓存
  86. *
  87. * @return string|void
  88. * @throws \Psr\SimpleCache\InvalidArgumentException
  89. */
  90. public function delPayListsCache()
  91. {
  92. $inputData = request()->all();
  93. if ($inputData['key'] != env('PAY_CENTER_KEY')) {
  94. return json_fail('nook');
  95. }
  96. make(CacheInterface::class)->delete('paymentType');
  97. return json_success('ok');
  98. }
  99. }