PaymentQueryTask.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/21
  6. * Time: 下午2:12
  7. */
  8. namespace App\Console\Commands;
  9. use App\Libs\Pay\SandPay;
  10. use App\Libs\PayHelper;
  11. use App\Modules\Finance\Models\WithdrawCash;
  12. use App\Modules\Finance\Services\AdvancedPaymentService;
  13. use App\Modules\Finance\Services\BatchPaymentService;
  14. use App\Modules\Finance\Services\LiquidatedStatService;
  15. use App\Modules\Finance\Services\PaymentService;
  16. use App\Modules\Finance\Services\WithdrawCashService;
  17. use Illuminate\Console\Command;
  18. use Illuminate\Support\Facades\DB;
  19. use Illuminate\Support\Facades\Log;
  20. class PaymentQueryTask extends Command
  21. {
  22. /**
  23. * 执行命令 php artisan payment_query_task
  24. *
  25. * The name and signature of the console command.
  26. *
  27. * @var string
  28. */
  29. protected $signature = 'payment_query_task';
  30. /**
  31. * The console command description.
  32. *
  33. * @var string
  34. */
  35. protected $description = '支付通道打款结果查询';
  36. /**
  37. * Execute the console command.
  38. *
  39. * @return mixed
  40. */
  41. public function handle()
  42. {
  43. print_r("======支付通道打款结果查询 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
  44. Log::info("======支付通道打款结果查询 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
  45. $this->BatchPaymentQuery();
  46. Log::info("======支付通道余额结果查询 【任务执行结束】=====[" . date("y-m-d H:i:s" . "\n"));
  47. print_r("======支付通道余额结果查询 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  48. }
  49. private function BatchPaymentQuery()
  50. {
  51. $pay_service = new SandPay;
  52. $payment_service = new AdvancedPaymentService;
  53. $payments = $payment_service->findPayingBatchPayments();
  54. foreach ($payments as $pay) {
  55. $result = $pay_service->queryOrder([
  56. 'order_no' => $pay->trade_no,
  57. 'pay_time' => $pay->pay_time,
  58. ], $pay->is_company == 0);
  59. if ($result['result'] == 'success' && $result['content']->respCode == '0000' && $result['content']->resultFlag == 0) {
  60. print_r(($pay->id) . '---执行---start---' . "\n");
  61. $sand_serial = property_exists($result['content'],'sandSerial') ? $result['content']->sandSerial : '0000';
  62. $payment_service->updateBatchPaymentStatus($pay, AdvancedPaymentService::auto_success, 0, $result, $sand_serial);
  63. print_r(($pay->id) . '---执行---end---' . "\n");
  64. } else if ($result['result'] == 'failure') {
  65. $payment_service->updateBatchPaymentStatus($pay, AdvancedPaymentService::auto_failure, 0, $result);
  66. } else {
  67. $pay->pay_merchant_source_msg = json_encode($result);
  68. $pay->pay_merchant_source_result = '正在处理中';
  69. $pay->save();
  70. }
  71. }
  72. }
  73. }