| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace App\Module\TransferOld;
- use App\Jobs\TransferOrderOutCallback;
- use App\Module\Outside\Http;
- use App\Module\TransferOld\Enums\TStatus;
- use App\Module\TransferOld\Enums\TType;
- use App\Module\TransferOld\Model\TransferOrder;
- use Carbon\Carbon;
- use Dcore\Exception\LogicException;
- use Dcore\Helper\Logger;
- use Fund\Account;
- use Fund\Fund;
- use Illuminate\Support\Facades\DB;
- class AutoCallOut
- {
- /**
- * 出包 的 处理
- *
- * @return void
- */
- static public function out_call()
- {
- $models = TransferOrder::query()
- ->where([
- 'status' => TStatus::CREATED,
- 'type' => TType::Out
- ])
- ->where('created_at', '>', Carbon::now()->subMinutes(2))
- ->orderBy('id', 'desc')->limit(10)->get();
- foreach ($models as $model) {
- TransferOrderOutCallback::dispatch($model->id)->delay(5);
- }
- }
- static public function out_call_all()
- {
- $models = TransferOrder::query()
- ->where([
- 'status' => TStatus::CREATED,
- 'type' => TType::Out
- ])
- ->orderBy('id', 'desc')->get();
- foreach ($models as $model) {
- TransferOrderOutCallback::dispatch($model->id)->delay(5);
- }
- }
- /**
- * 出包 的 处理
- * @param TransferOrder $model
- * @return void
- * @throws \Exception
- */
- static public function out_call1(TransferOrder $model)
- {
- if($model->type === TType::Out){
- if ($model->status === TStatus::CREATED) {
- self::out_call2($model);
- }
- }
- }
- /**
- * 出包 的处理
- *
- * @param TransferOrder $order
- * @return void
- */
- static private function out_call2(TransferOrder $order)
- {
- // dump($order);
- $user_id = $order->user_id;
- $trapp_id = $order->trapp_id;
- $app = App::get($trapp_id);
- // 出包,进行下单
- $app = App::get($trapp_id);
- $http = Http::getById($app->out_id);
- $data = [
- 'wallet_id' => $order->id,
- 'wallet_user_id' => $order->user_id,
- 'amount' => (int)$order->oamount,
- ];
- // index.php?s=/api/linkup.order/recharge
- $res = $http->postJson($app->order_out_create, $data);
- // dd($res,$data);
- if ($res['code'] != 0) {
- Logger::error('out_call2',$res);
- throw new \Exception('回调失败'.($res['message']??''));
- }
- $order->out_order_id = $res['data']['business_id'];
- $order->ouser_id = $res['data']['business_user_id'];
- Logger::info('out_call2',$res);
- $order->status = TStatus::CALL;
- if (!$order->save()) {
- throw new \Exception('保存失败');
- }
- return true;
- }
- }
|