WithdrawCorrectionFive.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Order;
  4. use App\Models\Amount;
  5. use App\Models\Store;
  6. use App\Models\User;
  7. use App\Models\DwbsUser;
  8. use App\Handlers\SignHandler;
  9. use Illuminate\Console\Command;
  10. use Illuminate\Support\Facades\Log;
  11. use Illuminate\Support\Facades\DB;
  12. class WithdrawCorrectionFive extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'withdraw_correction_five';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '提现修正';
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. parent::__construct();
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. Log::info('提现修正5任务正在运行 ing');
  43. $date=date("Y-m-d",strtotime('-5 days'));
  44. $handle=new SignHandler();
  45. $refunds=Amount::where('type',3)->where('status',1)->whereDate('created_at',$date)->orderBy('id')->get();
  46. foreach($refunds as $key=>$val){
  47. $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('id',$val->store_id)->value('sub_mchid');
  48. $withdraw_id=$val->transaction_id;
  49. $out_request_no=$val->order_no;
  50. $url='https://api.mch.weixin.qq.com/v3/ecommerce/fund/withdraw/'.$withdraw_id.'?sub_mchid='.$sub_mchid;//查询地址
  51. // $url='https://api.mch.weixin.qq.com/v3/ecommerce/fund/withdraw/out-request-no/'.$out_request_no.'?sub_mchid='.$sub_mchid;
  52. $merchant_id=config('wechat.payment.default.mch_id');//商户号
  53. $serial_no=config('wechat.payment.default.serial_no');//不是平台证书序列号
  54. $mch_private_key=$handle->getPublicKey();//读取商户api证书公钥 getPublicKey()获取方法 见下文
  55. $timestamp=time();//时间戳
  56. $nonce=$handle->nonce_str();//随机字符串
  57. $body="";
  58. $sign=$handle->sign($url,'GET',$timestamp,$nonce,$body,$mch_private_key,$merchant_id,$serial_no);//签名
  59. $header=[
  60. 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign,
  61. 'Accept:application/json',
  62. 'User-Agent:' . $merchant_id,
  63. 'Content-Type:application/json',
  64. 'Wechatpay-Serial:' . $handle->getzhengshu()//获取平台证书序列号
  65. ];
  66. $result=$handle->curl($url,'',$header,'GET');
  67. $result=json_decode($result,true);
  68. // log::info('ssss---ssss---ssss---ssss');
  69. if($val->status_code<>$result['status']){
  70. Log::info('提现5状态有误:'.$val->store_id.'---'.$val->order_no.'---'.$result['status']);
  71. Store::withTrashed()->where('is_failure',0)->where('id',$val->store_id)->decrement('withdrawal',$val->money);
  72. if($result['status']=='FAIL' ||$result['status']=='REFUND' ||$result['status']=='CLOSE'){
  73. $reason=$result['reason'];
  74. }else{
  75. $reason=null;
  76. }
  77. Amount::where('transaction_id',$withdraw_id)
  78. ->update([
  79. 'status'=>0,
  80. 'status_code'=>$result['status'],
  81. 'reason'=>$reason
  82. ]);
  83. }
  84. }
  85. }
  86. }