CheckCommission.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Order;
  5. use App\Models\User;
  6. class CheckCommission extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'check:commission';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '返佣服务';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $order = Order::where('commission_status', 0)
  37. ->where('status', 3)
  38. ->get();
  39. foreach ($order as $item) {
  40. if ($item->invite_user_id) {
  41. $inviter = User::find($item->invite_user_id);
  42. if (!$inviter) continue;
  43. $inviter->commission_balance = $inviter->commission_balance + $order->commission_balance;
  44. if ($inviter->save()) {
  45. $item->commission_status = 1;
  46. $item->save();
  47. }
  48. }
  49. }
  50. }
  51. }