AutoCallOut.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Module\TransferOld;
  3. use App\Jobs\TransferOrderOutCallback;
  4. use App\Module\Outside\Http;
  5. use App\Module\TransferOld\Enums\TStatus;
  6. use App\Module\TransferOld\Enums\TType;
  7. use App\Module\TransferOld\Model\TransferOrder;
  8. use Carbon\Carbon;
  9. use Dcore\Exception\LogicException;
  10. use Dcore\Helper\Logger;
  11. use Fund\Account;
  12. use Fund\Fund;
  13. use Illuminate\Support\Facades\DB;
  14. class AutoCallOut
  15. {
  16. /**
  17. * 出包 的 处理
  18. *
  19. * @return void
  20. */
  21. static public function out_call()
  22. {
  23. $models = TransferOrder::query()
  24. ->where([
  25. 'status' => TStatus::CREATED,
  26. 'type' => TType::Out
  27. ])
  28. ->where('created_at', '>', Carbon::now()->subMinutes(2))
  29. ->orderBy('id', 'desc')->limit(10)->get();
  30. foreach ($models as $model) {
  31. TransferOrderOutCallback::dispatch($model->id)->delay(5);
  32. }
  33. }
  34. static public function out_call_all()
  35. {
  36. $models = TransferOrder::query()
  37. ->where([
  38. 'status' => TStatus::CREATED,
  39. 'type' => TType::Out
  40. ])
  41. ->orderBy('id', 'desc')->get();
  42. foreach ($models as $model) {
  43. TransferOrderOutCallback::dispatch($model->id)->delay(5);
  44. }
  45. }
  46. /**
  47. * 出包 的 处理
  48. * @param TransferOrder $model
  49. * @return void
  50. * @throws \Exception
  51. */
  52. static public function out_call1(TransferOrder $model)
  53. {
  54. if($model->type === TType::Out){
  55. if ($model->status === TStatus::CREATED) {
  56. self::out_call2($model);
  57. }
  58. }
  59. }
  60. /**
  61. * 出包 的处理
  62. *
  63. * @param TransferOrder $order
  64. * @return void
  65. */
  66. static private function out_call2(TransferOrder $order)
  67. {
  68. // dump($order);
  69. $user_id = $order->user_id;
  70. $trapp_id = $order->trapp_id;
  71. $app = App::get($trapp_id);
  72. // 出包,进行下单
  73. $app = App::get($trapp_id);
  74. $http = Http::getById($app->out_id);
  75. $data = [
  76. 'wallet_id' => $order->id,
  77. 'wallet_user_id' => $order->user_id,
  78. 'amount' => (int)$order->oamount,
  79. ];
  80. // index.php?s=/api/linkup.order/recharge
  81. $res = $http->postJson($app->order_out_create, $data);
  82. // dd($res,$data);
  83. if ($res['code'] != 0) {
  84. Logger::error('out_call2',$res);
  85. throw new \Exception('回调失败'.($res['message']??''));
  86. }
  87. $order->out_order_id = $res['data']['business_id'];
  88. $order->ouser_id = $res['data']['business_user_id'];
  89. Logger::info('out_call2',$res);
  90. $order->status = TStatus::CALL;
  91. if (!$order->save()) {
  92. throw new \Exception('保存失败');
  93. }
  94. return true;
  95. }
  96. }