KuaishowPush.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Helper\Kuaishou;
  4. use App\Helper\UniPlatform\Kuaishou\KuaishouAPI;
  5. use App\Models\Pay;
  6. use App\Models\PayConfig;
  7. use Carbon\Carbon;
  8. use Illuminate\Console\Command;
  9. use SebastianBergmann\CodeCoverage\Report\PHP;
  10. class KuaishowPush extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'kuaishow:push';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '推送快手订单';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return int
  37. */
  38. public function handle()
  39. {
  40. $app = $this->getKuishouFactory();
  41. $orders = Pay::with(['user.info'])->whereHas('user.info', function ($query){
  42. $query->where('platform', 2);
  43. })->where('status', 1)
  44. ->where('is_settle', 0)
  45. ->get();
  46. /* @var Pay $order*/
  47. foreach ($orders as $order){
  48. try {
  49. echo '推送订单号-->',$order->pay_id;
  50. $res = $app->pushOrder($order->user->open_id,$order->pay_id, $order->created_at);
  51. echo "\t推送结果-->\033[32m",json_encode($res,JSON_UNESCAPED_UNICODE),"\033[0m",PHP_EOL;
  52. }catch (\Exception $exception){
  53. echo "\t推送结果异常-->\033[31m",$exception->getMessage(),"\033[0m",PHP_EOL;
  54. }
  55. }
  56. }
  57. protected function getKuishouFactory(): Kuaishou
  58. {
  59. $setting = PayConfig::first();
  60. return (new Kuaishou(app(KuaishouAPI::class)))->factory([
  61. 'app_id' => $setting->kuaishou_app_id,
  62. 'app_secret' => $setting->kuaishou_app_secret,
  63. ]);
  64. }
  65. }