where([ 'status' => TStatus::CREATED, 'type' => TType::In ])->get(); foreach ($models as $model) { TransferOrderInCall::dispatch($model->id)->delay(2); } } static public function in_call1(TransferOrder $model) { $run = false; DB::beginTransaction(); try { $model = TransferOrder::query()->lockForUpdate()->find($model->id); // dump($model->status); if ($model->status === TStatus::CREATED) { $run = self::in_call2($model); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); dump($e); Logger::exception('', $e); } if ($run) { TransferOrderInCallback::dispatch($model->id)->delay(1); } } /** * 入包的处理 * * @param TransferOrder $order * @return void */ static private function in_call2(TransferOrder $order) { // dump($order); $user_id = $order->user_id; $out_id = $order->out_id; $trapp_id = $order->trapp_id; $app = App::get($trapp_id); $fundE = \Fund\Enums\Fund::from($app->fund_id); $fund = new Fund($app->fund_in_uid, $app->fund_id); $res = $fund->trade($user_id, $fundE, $order->amount, 'Transfer', $order->id, '划转 - 转入'); if (is_string($res)) { throw new \Exception($res); } $order->status = TStatus::CALL; if (!$order->save()) { throw new \Exception('保存失败'); } return true; } static public function in_callback() { $models = TransferOrder::query() ->where([ 'status' => TStatus::CALL, 'type' => TType::In ]) ->where('created_at', '>', Carbon::now()->subMinutes(2)) ->limit(10) ->orderBy('id', 'desc') ->get(); foreach ($models as $model) { TransferOrderInCallback::dispatch($model->id)->delay(5); } } static public function in_callback_all() { $models = TransferOrder::query() ->where([ 'status' => TStatus::CALL, 'type' => TType::In ]) ->orderBy('id', 'desc') ->get(); foreach ($models as $model) { TransferOrderInCallback::dispatch($model->id)->delay(5); } } /** * 入包,回调处理 * * @param $model * @return void */ static public function in_callback1(TransferOrder $model) { if ($model->type === TType::In) { // dump($model->status); if ($model->status === TStatus::CALL) { self::in_callback2($model); } } } /** * 回调处理 * * @param TransferOrder $order * @return true */ static private function in_callback2(TransferOrder $order) { // dump($order); // $user_id = $order->user_id; $out_id = $order->out_id; $trapp_id = $order->trapp_id; $app = App::get($trapp_id); $http = Http::getById($app->out_id); $res = $http->postJson($app->order_callback, [ 'business_id' => $order->out_order_id, 'wallet_id' => $order->id, 'status' => $order->status->value(), ]); if ($res['code'] != 0) { throw new \Exception('回调失败'); } // dd($res); $order->status = TStatus::CALLBACK; if (!$order->save()) { throw new \Exception('保存失败'); } return true; } }