RefundCommand.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Console\Pay;
  3. use App\Cache\UserCache;
  4. use App\Libs\Utils;
  5. use App\Models\Channel\Channel;
  6. use App\Models\Pay\PayMerchant;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Redis;
  10. use Ycpay\Byte;
  11. use App\Servicess\WithdrawCashService;
  12. use App\Services\Order\OrderService;
  13. use Ycpay\Factory as PayFactory;
  14. /**
  15. * 退款脚本
  16. */
  17. class RefundCommand extends Command
  18. {
  19. /**
  20. * @var string
  21. */
  22. protected $signature = 'order_refund {--trade_no=}';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '订单退款';
  29. /**
  30. * handle
  31. */
  32. public function handle()
  33. {
  34. // 传参
  35. $trade_no = $this->option('trade_no');
  36. \Log::info('order_refund_start:'.$trade_no);
  37. $order = OrderService::getByTradeNo($trade_no);
  38. \Log::info('$order:'.json_encode($order));
  39. $distribution_channel_id = $order->distribution_channel_id;
  40. // $channel = Channel::find($distribution_channel_id);
  41. // \Log::info('$channel:'.$distribution_channel_id.' param:'.json_encode($channel));
  42. $pay_merchant = PayMerchant::find($order->pay_merchant_id);
  43. if(empty($pay_merchant)){
  44. \Log::info('create_order_pay_merchant_null:'.$order->pay_merchant_id);
  45. return $this->error('50013:参数异常');
  46. }
  47. $pay_config_info = $pay_merchant->config_info;
  48. $pay_config_infos = json_decode($pay_config_info,true);
  49. \Log::info('create_order_pay_merchant:'.json_encode($pay_merchant));
  50. \Log::info('$pay_config_infos:');\Log::info($pay_config_infos);
  51. $byte = new Byte();
  52. $config = [
  53. 'app_id'=>isset($pay_config_infos['appid'])?$pay_config_infos['appid']:'',
  54. 'secret'=>isset($pay_config_infos['secret'])?$pay_config_infos['secret']:'',
  55. 'notify_url'=>isset($pay_config_infos['notify_url'])?$pay_config_infos['notify_url']:'',
  56. 'refund_notify_url'=>isset($pay_config_infos['refund_notify_url'])?$pay_config_infos['refund_notify_url']:'',
  57. 'token'=>isset($pay_config_infos['token'])?$pay_config_infos['token']:'',
  58. 'salt'=>isset($pay_config_infos['salt'])?$pay_config_infos['salt']:'',
  59. 'store_uid'=>isset($pay_config_infos['store_uid'])?$pay_config_infos['store_uid']:'',// 收款商户号,1个主体下面有多个商户号
  60. 'merchant_id'=>$order->pay_merchant_id,
  61. 'title'=>isset($pay_config_infos['title'])?$pay_config_infos['title']:'',
  62. 'desc'=>isset($pay_config_infos['desc'])?$pay_config_infos['desc']:'',
  63. ];
  64. \Log::info('$config:'.json_encode($config));
  65. $pay_client = PayFactory::getInstance('Byte');
  66. $order_param = [
  67. 'out_order_no'=>$trade_no,
  68. 'out_refund_no'=>generateOrderSn('refund-'),
  69. 'reason'=>'退款',
  70. 'refund_amount'=>$order->price * 100,
  71. 'cp_extra'=>'',
  72. 'notify_url'=>$config['refund_notify_url'],
  73. ];
  74. \Log::info('$order_param:');
  75. \Log::info(json_encode($order_param));
  76. $order_refund_res = $pay_client->init($config)->applyOrderRefund($order_param);
  77. if(isset($order_refund_res->err_no) && $order_refund_res->err_no == 0 &&$order_refund_res->err_tips == 'success'){
  78. }
  79. \Log::info('order_refund_res:'.json_encode($order_refund_res));
  80. }
  81. }