updateUserFinance.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\UserFinanceModel;
  4. use App\Models\UserOrderModel;
  5. use Illuminate\Console\Command;
  6. class updateUserFinance extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'updateUserFianance';
  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. //获取没有用户ID的流水记录
  37. $datas = UserFinanceModel::query()
  38. ->whereNull("user_id")
  39. ->get();
  40. foreach ($datas as $data) {
  41. $order = UserOrderModel::query()
  42. ->where("order_number",$data["order_number"])
  43. ->first();
  44. UserFinanceModel::query()
  45. ->where("id",$data["id"])
  46. ->update(
  47. [
  48. "user_id"=>$order["user_id"]
  49. ]
  50. );
  51. }
  52. }
  53. }