CheckCommission.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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', 1)) {
  42. Order::where('commission_status', 0)
  43. ->where('invite_user_id', '!=', NULL)
  44. ->whereIn('status', [3, 4])
  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('invite_user_id', '!=', NULL)
  55. ->get();
  56. foreach ($order as $item) {
  57. $inviter = User::find($item->invite_user_id);
  58. if (!$inviter) continue;
  59. $inviter->commission_balance = $inviter->commission_balance + $item->commission_balance;
  60. if ($inviter->save()) {
  61. $item->commission_status = 2;
  62. $item->save();
  63. }
  64. }
  65. }
  66. }