KuaishowPush.php 1.8 KB

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