CheckCommission.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $this->autoCheck();
  37. $this->autoPayCommission();
  38. }
  39. public function autoCheck()
  40. {
  41. if ((int)config('v2board.commission_auto_check_enable')) {
  42. Order::where('commission_status', 0)
  43. ->where('status', 3)
  44. ->where('commission_balance', '>', 0)
  45. ->where('updated_at', '>=', strtotime('+3 day', time()))
  46. ->update([
  47. 'commission_status' => 1
  48. ]);
  49. }
  50. }
  51. public function autoPayCommission()
  52. {
  53. $order = Order::where('commission_status', 1)
  54. ->where('status', 3)
  55. ->get();
  56. foreach ($order as $item) {
  57. if ($item->invite_user_id) {
  58. $inviter = User::find($item->invite_user_id);
  59. if (!$inviter) continue;
  60. $inviter->commission_balance = $inviter->commission_balance + $item->commission_balance;
  61. if ($inviter->save()) {
  62. $item->commission_status = 2;
  63. $item->save();
  64. }
  65. }
  66. }
  67. }
  68. }