CheckCommission.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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('status', 3)
  44. ->where('updated_at', '<=', strtotime('-3 day', time()))
  45. ->update([
  46. 'commission_status' => 1
  47. ]);
  48. }
  49. }
  50. public function autoPayCommission()
  51. {
  52. $order = Order::where('commission_status', 1)
  53. ->where('status', 3)
  54. ->get();
  55. foreach ($order as $item) {
  56. if ($item->invite_user_id) {
  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. }
  67. }